Move root partition to home partition

If you have made these mistakes when installing your Linux Debian Server at home or work, this article might help you.

Mistakes:
* You split the drive into / (root portion) and /home portion. 3 years later and 1-2 Debian upgrades you run out of space on root. You need to move it off to home partition that has 400GB+.
* You have installed ext3 on your / (root partition) instead of xfs for your server. You are finding that mdadm and ext3 and long running servers are not playing so nicely when things go not as planned. Your home partition is xfs so now you would like to move it off to home to be on xfs.

Moving root partition to home. This process should not be taken lightly. You should not be doing this if you are not having any problems. You are doing it at your own risk and as a result you need to read up on what each of these commands might do to your system. You should not be replacing, deleting any data. You should not be deleting old root until a week later when you confirmed it all worked.

Prep Work:
When your computer boots and grub menu shows up press “e” to see what your grub is doing and write it down. Mine was doing below. When I search for some troubleshooting howto solutions the key why they didn’t work is because these modules were not loaded. insmod part_gpt and insmod ext2
in grub menu
insmod part_gpt
insmod ext2
set root='(hd0,gpt1)'
search --fs-uuid --set a80.....
linux /vmlinuz-3.2.9-4-amd64 root=/dev/mapper/my_lvmgroup_root

*Download Debian live cd
*My case, gpt partitions. sda only has my boot partiton. My sdb,sdc,sdd contain 4TB raid 5 with 3 lvm groups for root,swap,home.

*Use lucasmanual to mount the raid lvm from a live Debian Cd

*Mount source (root partition) and destination (home partition)
#root access
sudo -i
cd /mnt
mkdir src
mkdir dest
mount /dev/mapper/my_lvmgroup_root src
mount /dev/mapper/my_lvmgroup_home dest

*Now the key is that you will need to create a home folder inside your home partition and move all the files there.
cd /mnt/dest/
mkdir home

#now move the files you need. This will make current system accessible only through shell. You will need to access it via pressing for example Alt +F2 and using command line. So be prepared to have a backup tablet to troubleshoot.
#cp /mnt/dest/lucas /mnt/dest/home/lucas
#….keep going.

*Now lets sync root partition onto home. Many web pages says to exclude proc,sys,tmp,etc but I decided to copy it since it should work either way.
*I have added other excludes as I see fit

rsync -aAXv --exclude=/lost+found --exclude=/root/trash/* --exclude=/var/tmp/* /mnt/src/* /mnt/dest/

*If your boot partition is located elsewhere. (You can tell if its mounted to a different partition in /mnt/src/etc/fstab. you need to mount it in dest.

*Mount the uuid of the boot into the /mnt/dest/boot
mount UUID=abc...123 /mnt/dest/boot

*I made a copy of that just in case in
#cp -r /mnt/dest/boot /mnt/dest/boot_copy

*Next day when a copy is done. Its time to update grub and /etc/fstab

umount /mnt/src
*Lets create a root folder where we will mount old partition.
mkdir /mnt/dest/root_old

*Lets update /etc/fstab aka
vi /mnt/dest/etc/fstab
#And change your /home partition to /
#Change your old / to /root_old
#The last item on the line is the order for fsck. 0 = nocheck, 1 = check first, 2=secondary check. So update your new / to 1 so that fsck gets it checked as needed.

*First in order to update grub we need real dev,proc,sys from the currently running system. (not these are from the live cd not /mnt/src)

mount -o bind /proc /mnt/dest/proc
mount -o bind /dev /mnt/dest/dev
mount -o bind /sys /mnt/dest/sys

*Now we will chroot…this changes the “/” to point elsewhere in my shell temporally.
chroot /mnt/dest
update-grub

*You should see
Generating grib.cfg
Found background image....
Found linux image....
found initrd image....
....
Found Debian GnuLinux 7.8 on /dev/mapper...
#Note for some reason my always says it found it on my root lvm not home lvm..but these instructions did work

*Install grub on your first device where you have current grub. This was required for me because even do I did update-grub it would load into the old / (root partition).
grub-install /dev/sda

*When system reboots and grub menu shows up press e to see if it points to my_lvmgroup_home.
reboot

*Notes 1:
I guess one of the points for me was: on the old / there was a boot folder that had the old scripts pointing to lvmgroup_root….I renamed it to boot_notused….
I loaded the system, mounted everything src,dest,dev,sys,proc then
upgrade-grub
grub-install /dev/sda

* Note 2: when I loaded on lvmgroup_home as / I needed to not only do update-grub but also grub-install /dev/sda

*Note 3: When searching for help somebody said “delete old root partition” and it should work…WRONG…NEVER DELETE old partition. With Linux as long as you don’t delete or overwrite your data you will be always able to go back. So don’t listen to people who tell you to delete your data. There is no going back from that.

*Note 4: At some time in the future I wanted to redo my Raid5 with proper gpt starting not at 63 sector but at 2048 byte. I moved my old raid data to a temporary drive 2TB, (made sure the drive boots and runs fine) deleted and recreated my new raid5 on new partitions tables in each drive and copied data back to raid5. When I follow all the steps above the system said it couldn’t find the /dev/mapper/mygroup_home… When I chroot i did mount -a and then I needed to also do a update-initramfs -u to correct that.

source1
#Guide that I was sticking by

http://www.linuxquestions.org/questions/linux-general-1/move-root-filesystem-howto-931974/

source2
#1 had missing mounts for proc,dev,sys

http://askubuntu.com/questions/3402/how-to-move-boot-and-root-partitions-to-another-drive

source#3
but the mkinitcpio was not required…didn’t reasearch waht it is

https://wiki.archlinux.org/index.php/full_system_backup_with_rsync

source#4.
talks about grub and what it is

https://wiki.archlinux.org/index.php/GRUB

source#5
some other steps that are very similar

https://unix.stackexchange.com/questions/109464/how-can-i-fix-install-reinstall-grub

#source6
some other steps that are very similar

https://www.gnu.org/software/grub/manual/html_node/Installing-GRUB-using-grub_002dinstall.html

#source7
for note4 a little details on cylinder alignment sector 63 byte vs 2048 byte

http://dennisfleurbaaij.blogspot.com/2013/01/setting-up-linux-mdadm-raid-array-with.html

Comments:
– https://www.reddit.com/r/linux/comments/3qitkc/move_root_partition_to_home_partition/