Resize Root Filesystem

From wikipost

This procedure details how to copy the current filesystem to a new disk. This is a preferred scenario when:

  • the current root filesystem is becoming too small
  • you wish to shrink the existing root filesystem (think vm's)


Steps to achive the copy are:

  • create or attach a new disk
  • create a root (and swap partition) on the disk (fdisk /dev/...)
  • format the disk with EXT2
  • mount the disk to a directory on the live system
  • copy all files to the new disk
  • copy the special device files (?)
  • chroot into the new disk
  • install the bootloader to the MBR of the new disk


Copy command:

(cd / ; tar -cf - . --one-file-system) | (cd /mnt/ ; tar xvfpB -)


Find out the new disk's UUID:

ls -l /dev/disk/by-uuid/


  • Update the new UUID in /etc/fstab
  • Update the new UUID in /boot/grub/grub.cfg



Install bootloader:

There are (as far as I know of) three ways of installing GRUB onto the new disk.

1 * After copying all files, remove the old drive and boot off a live Linux CD (e.g. Knoppix) (the idea here is that hd0 is the new drive and issuing the grub-install command will simply install on hd0.

2 * Swap the drives (master becomes slave, slave becomes master) and in the BIOS designate to boot of the second disk. (again, grub will install on hd0 which is the new disk)

3 * with the new disk attached as /dev/sdb, instruct GRUB to install there but to refer to it as /dev/sda (or hd0 as we want). (my preference)



Method 1 and 2

http://www.linuxjournal.com/content/copy-your-linux-install-different-partition-or-drive


Method 3

(with the new disk (/dev/sdb) still mounted at /mnt/)

grub-install -d /mnt /dev/sdb
  • shutdown
  • take out old disk, and replace with the new disk as the primary boot disk
  • start the machine



GRUB v1 only:

When you're back in the O/S update the menu.lst to make sure the correct boot device (e.g. /dev/sda) is used.

grub-install /dev/sda
update-grub
  • reboot and all should be fine