Kali/Moving Root Partition
From charlesreid1
Sheesh.
First, I partition my / directory too small on my desktop box, and have to move the /usr directory to a new partition.
Then, I partition my / directory too small on my laptop, and have to move the /root directory to a new partition.
Okay, let's roll up our sleeves and fix this crap.
Contents
Boot into Live USB
First step is to boot into a live CD.
Use Kali or Pentoo as your live distro. Why the hell would you use anything else.
Map Out Partitions
Gparted
Fire up parted or gparted or fdisk or whatever your "favorite" disk manager is. Get a snapshot of what's where.
The partition we mount as / is on /dev/sda5 and the partition we want to mount as /root is on /dev/sda6. Assume /dev/sda6 is empty (not necessary though).
Copy, Don't Move
We'll start by copying files, not moving them, in case something goes awry.
Mount The Partitions
Mount the / partition:
$ mkdir /mnt/linux $ mount /dev/sda5 /mnt/linux
Mount the /root partition:
$ mkdir /mnt/myhome $ mount /dev/sda6 /mnt/myhome
Copy the Files
Now we copy (don't move) things from /mnt/linux/root
to /mnt/myhome/root
:
$ cp -r /mnt/linux/root /mnt/myhome/root
Edit Fstab
The last step is to change the installed OS's fstab file to mount the new partition to /root. First, get the UUID of the partition you want to mount as /root:
$ ls -l /dev/disk/by-uuid
Once you've got it, edit /mnt/linux/etc/fstab
and add a line:
UUID=82dfaa01-affa-444d-839a-a23b474a8014 /root ext4 defaults 0 2
Test
Move, Don't Delete
Now that we've finished the copy, and the files are successfully duplicated, we can move (don't delete!) the original:
$ mv /mnt/linux/{,_}root $ mkdir /mnt/linux/root
The second command makes sure that we leave behind a mount point for /root.
Reboot
Now we test things out by rebooting. Make sure /root mounts as expected.
Finishing
We finish by making our changes permanent. We can boot into a live distro again, or just do it from our installed distro.
Remove from Your Installed Distro
Remove the old files from the current installed distro:
$ rm -r /_root
Remove from Live Distro
Remove the old files from a live distro:
$ mkdir /mnt/linux $ mount /dev/sda5 /mnt/linux $ rm -r /mnt/linux/_root