KfWiki : FileSystemResize

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
HomePage » Linux » FileSystemResize


Linux partition resize without LVM

This example involves resizing a linux partition sitting on an HP smartarray volume. I have a 4x36G RAID0+1 volume, which I tend to double its size. On the volume, I have a root partition, followed by a swap partition:

Device Boot      Start         End      Blocks   Id  System
/dev/sda1           1       8723       x  83  Linux
/dev/sda2           8724       8854     x   82  Linux swap / Solaris


One should also do the following and save the output
dumpe2fs /dev/sda1 | grep -i "Block size"
du -k
du -mh


Step 1: swapping in bigger drives
Because the volume contains redundant drives, I can swap in 4 74G drives one at a time. Just wait till the rebuild completes before moving on to the next drive. On my test server with only the OS, each round of rebuild takes only 15min.

Step 2: Extending the volume
Check that all 4 drives are in, you should see 4 74G drives
hpacucli ctrl slot=0 pd all show


Check the logical drive is ready
hpacucli ctrl slot=0 pd all show


Then resize the logical drive. This an be done while your system is online
hpacucli ctrl slot=0 ld 1 modify size=max


Step 3: Reboot system into rescue mode
Using a Linux installation CD, reboot your server into rescue mode. There is no need to start networking or mount the existing OS partitions.

Step 4: fsck
Before doing anything, it is important to run fsck to make sure the filesystem is clean
fsck -n /dev/cciss/c0d0p1


Step 5: Remove journal on ext3 filesystem
Effectively making it a ext2 filesystem
tune2fs -O ^has_journal /dev/sda1


Step 6: Reset partition boundary
This is the scary part, but don't worry, you won't loose any data unless you set up a new partition that is smaller than the original one.
fdisk /dev/sda
delete the swap partition (2) with the "d" command
delete the linux partition (1) with the "d" command
recreate the linux partition with the "n" command. It should begin with 1, and ends with the total size - swap size.
recreate the swap partition using the remaining space
change swap partition type using the "t" command
mark linux partition active (bootable) with the "a" command
commit the changes with the "w" command
quit fdisk
sync;sync;sync;^d


The last command should reboot your system, which is required for the new partitions to take effect

Step 7: Resize ext2 filesystem
Run fs check and then resize2fs.
e2fsck -f /dev/sda1
resize2fs /dev/sda1


Using resize2fs without any argument will grow the filesystem to the maximum allowable size.

Step 8: Final steps
Do a fs check and add recreate the journal entries, effectively converting the ext2 fs back to ext3

fsck -n /dev/sda1
tune2fs -j /dev/sda1
sync;sync;sync;^d


The last command should reboot your system. When the system comes back up, you have a bigger root partition! Pay attention to the swap partition. As Redhat uses label to mount partitions, you will loose the swap partition. Edit /etc/fstab accordingly, do a mkswap followed by swapon /dev/sda2. You should be set!


Linux partition resize with LVM

I'm logging what I've done today for future reference. Originally, I have this partition table:
||hda1||hda2||hda3||hda4||
|| NTFS || /boot || swap || vg0(lv_root,lv_opt) ||
All four being primary partitions.

My goal is to extend /opt. But this is harder than I thought since gparted does not support resizing partitions inside LVM, and one can have a maximum of 4 primary partitions. So instead, I had to
  1. Shrink the NTFS partition using gparted
  2. Move /boot forward
  3. Drop the swap partition
  4. Create a physical volume in /dev/hda3, such that the new PV is the size of my swap partition + the free space from the NTFS partition
  5. Run vgextend vg0 /dev/hda3 to add /dev/hda3 to vg0
  6. Reboot
  7. Run lvcreate -L 1G -n lv_swap /dev/vg0 to re-create a swap partition in vg0
  8. Make necessary adjustments to /etc/fstab to enable the new swap
  9. Unmount /opt
  10. Run lvextend -L +6G /dev/vg0/lv_opt to extend my lv_opt partition

The following never got tested because I mounted /opt in ext4dev with the extents option. It seems afterwards, all tools built for ext2/3 cease to work. I ended up re-formatting lv_opt. IF the filesystem had been ext2/3, the followings should work. Apparently tools for ext4dev are not available at the time this is documented, not even fsck....
  1. Run tune2fs -O^has_journal /dev/vg0/lv_opt to convert the partition from ext3 to ext2, which is required for resize2fs
  2. Resize lv_opt using resize2fs/gparted/qtparted
  3. Run tune2fs -j /dev/vg0/lv_opt to convert it back to ext3

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2716 seconds