Move your Linux root around


The partition of my root Linux was getting really full, so I decided to move it to a bigger partition.
I didn’t had the time for a fresh install, so I decided to hack around 😉
It can be done with a system running. Mount the new partition, in /mnt/newPart for instance.

Copy the contents skipping the stuff that don’t matter:

rsync -aAXv /* /mnt/newPart/ –exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs,/var/lib/pacman/sync/*}

Check the partitions UUIDs with blkid, take note of the one corresponding to your new partition sdb1.

Modify the new fstab at /mnt/newPart/etc/fstab and change the root’s UUID to the new one.

Now update grub  (update-grub2) to find the new installation, but not everything is ready yet.
You need to update the /boot/grub/grub.cfg (chmod +w it first, otherwise is read-only), as seen here.
On my case the new installation is on /dev/sdb1 so for grub it will be hd1,1, that’s the keyword that I’ve search for in the file.
You’ll find a line starting as linux /boot/… root=UUID=xxxx… now you need to replace that xxxx…. with the UUID that you got for the new disk.
Save and reboot, but don’t forget to select to boot from the new partition.
If everything is OK, the final step is to re- install correctly grub (where are still using sda, no change in the BIOS disk order is needed):

grub-install /dev/sda

Continue to enjoy the same old Linux in your brand new hard-drive/partition 😉

I’ve tried this in Ubuntu 10.4, but I guess it should work with any Linux out there with grub2 and fstab that uses UUID.

Posted in Linux. 1 Comment »


One Response to “Move your Linux root around”

  1. BL diz:
    (Mozilla Firefox 35.0 Windows 7)
    Mozilla Firefox 35.0 Windows 7

    It worked also with Debian 7 between 2 different computers. I’ve booted the second one with System Rescue live CD to get access to grub and install it on the new PC.
    Linux #FTW!

Leave a Reply