Operating System - Linux
1748249 Members
3323 Online
108760 Solutions
New Discussion юеВ

Re: extend a ext3 partition

 
SOLVED
Go to solution
Sunny Jaisinghani
Trusted Contributor

extend a ext3 partition

Hello Gurus,

I have RHEL5 server on which i have to resize a ext3 partition.

fdisk -l /dev/sda

Disk /dev/sda: 147.1 GB, 147114180608 bytes
255 heads, 63 sectors/track, 17885 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 127 1020096 83 Linux
/dev/sda2 128 3314 25599577+ 83 Linux
/dev/sda3 3315 5864 20482875 83 Linux
/dev/sda4 5865 17885 96558682+ 5 Extended
/dev/sda5 5865 8414 20482843+ 83 Linux
/dev/sda6 8415 8733 2562336 82 Linux swap / Solaris

Model: MAXTOR ATLAS10K5_147SCA (scsi)
Disk /dev/sda: 147GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 32.3kB 1045MB 1045MB primary ext3 boot
2 1045MB 27.3GB 26.2GB primary ext3
3 27.3GB 48.2GB 21.0GB primary ext3
4 48.2GB 147GB 98.9GB extended
5 48.2GB 69.2GB 21.0GB logical ext3
6 69.2GB 71.8GB 2624MB logical linux-swap

From the above partition table i see i have enought unused space on the disk. I want to expand /dev/sda2 partition; however there is no unused space immediately after sda2.
How should i proceed in this scenario?

Will i have to move the start and end points of sda3,sda4....sda6 in order to expand sda2?

Thanks
Sunny
7 REPLIES 7
Sunny Jaisinghani
Trusted Contributor

Re: extend a ext3 partition

fdisk -l /dev/sda

Disk /dev/sda: 147.1 GB, 147114180608 bytes
255 heads, 63 sectors/track, 17885 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 127 1020096 83 Linux
/dev/sda2 128 3314 25599577+ 83 Linux
/dev/sda3 3315 5864 20482875 83 Linux
/dev/sda4 5865 17885 96558682+ 5 Extended
/dev/sda5 5865 8414 20482843+ 83 Linux
/dev/sda6 8415 8733 2562336 82 Linux swap / Solaris


Model: MAXTOR ATLAS10K5_147SCA (scsi)
Disk /dev/sda: 147GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 32.3kB 1045MB 1045MB primary ext3 boot
2 1045MB 27.3GB 26.2GB primary ext3
3 27.3GB 48.2GB 21.0GB primary ext3
4 48.2GB 147GB 98.9GB extended
5 48.2GB 69.2GB 21.0GB logical ext3
6 69.2GB 71.8GB 2624MB logical linux-swap
Matti_Kurkela
Honored Contributor
Solution

Re: extend a ext3 partition

> Will i have to move the start and end points of sda3,sda4....sda6 in order to expand sda2?

Yes, that would be required if you have to keep the other partitions the same.

But there may be another option:
1.) create a new partition 7 with the same size as partition 3
2.) copy the contents of partition 3 to partition 7
3.) unmount partition 3 and mount 7 in its place (editing /etc/fstab appropriately)
4.) verify everything works; if not, undo step 3 to roll back.
5.) you can now delete partition 3 and use its space to extend partition 2.

If you don't need all of it, you may also be able to extend partition 5 later, by moving the start of extended partition 4 towards the beginning of the disk.

The problem is that your free space is now split in two parts, which may be more difficult to manage.

You might also make a (partial) migration to LVM to avoid troubles like this in the future. A simple solution would be to migrate everything except /boot and root filesystems to LVM. Migrating an existing system to LVM-based root filesystem would be trickier; /boot must always be on a non-LVM partition on a regular x86 system, to allow the BIOS to understand it.
(If your /boot directory is within the root filesystem, you have two good reasons to keep it as a non-LVM partition.)

You currently have plenty of free disk space to do the migration; later it will be more difficult. It's more work now, but will allow for much easier administration later.

http://tldp.org/HOWTO/LVM-HOWTO/

In short: begin by creating a partition that occupies all your current free space, set its type to Linux LVM and use pvcreate to make it a LVM Physical Volume (PV). Create your Volume Group using that PV.

Now convert all the partitions you want:
1.) create a Logical Volume (LV) that matches the size of the partition you wish to convert
2.) Create a filesystem on the LV and mount it to a temporary location.
3.) Copy everything from the old partition to the new LV.
4.) Unmount the old partition and the temporarily-mounted LV; mount the LV to the mount point where the old partition used to be. Edit /etc/fstab.
5.) Test that it works.
6.) Change the type of the old partition to "Linux LVM", pvcreate it and use vgextend to add it to your Volume Group.

Repeat these steps 1-6 for all partitions you wish to convert to LVM.

For a swap partition, step 2 would be "mkswap", step 3 would be "run swapon for the new partition and swapoff for the old one" and step 4 just "edit /etc/fstab".

In your situation, if you don't migrate partition 2 to LVM, just delete partition 3 after migrating it to LVM and leave it as free space for extending partition 2.

If you later run out of disk space in the LVM, you can use the free space for another LVM PV... until then, that space will be your reserve for future extensions of partition 2.

MK
MK
Sunny Jaisinghani
Trusted Contributor

Re: extend a ext3 partition

Thanks Matti.
That was very informative
Sunny Jaisinghani
Trusted Contributor

Re: extend a ext3 partition

Matti,

As seen in the partition table, i have 3 primary partitions.
When i proceed to create a new Linux LVM partition what will it be... primary or extended?

Sunny
Matti_Kurkela
Honored Contributor

Re: extend a ext3 partition

Background:
In a PC partition table, there are only 4 primary partition slots. If one of them (and only one) is used as an extended partition, you can create logical partitions within the extended partition "container". With this, the total number of partitions can extend beyond 4.

The standard PC Master Boot Record in the first block of the disk can only boot from a primary partition: otherwise there is no functional difference between primary and logical partitions. The logical partitions must always be within an extended partition: an extended partition with no logical partitions in it is not useful.


In Linux, with a traditional x86 PC partition table, the primary partitions are always numbered 1-4: the numbers 5 and above are logical partitions. If another partition table format (like EFI GPT) is used, this rule no longer applies.

LVM does not care about the partition type: it can use both primary and logical partitions as LVM PVs. If you migrate to LVM, the LVM PVs sda5-sda7 will be logical partitions, and sda3 (if/when you choose to use it as a LVM PV will be a primary partition).

LVM can even use whole disks as PVs with no partition table at all: this may be useful on RAID sets larger than 2 TB, which cannot be handled with the traditional PC partition tables (the partition size field does not have enough bits to indicate more than 2 TB).

LVM logical volumes are not bootable with the common combination of firmware and boot loader (i.e. x86 BIOS and GRUB). It would be possible to create a BIOS-based bootloader that understands LVM, but so far nobody seems to have done this. In this sense, the LVM logical volumes are like logical partitions.

MK
MK
Steven E. Protter
Exalted Contributor

Re: extend a ext3 partition

Shalom,

If you'd used LVM

pvcreate
vgextend
lvextend
rsize2fs

All, hot, don't even have to umount the filesystem.

Not using LVM, you need to create a new parition and then use dd to copy the data from old to new.

I would not have the filesystem mounted while doing the dd copy.

Possible, but much less fun.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sunny Jaisinghani
Trusted Contributor

Re: extend a ext3 partition

Thanks Steven and Matti.

I migrated the concerned partition to LVM.

Thanks. Got back to LVM after 3 months. Feeling good :-)

Sunny