You usually don’t think about having the /home directory on a separate partition while doing an installation, so by default it would be created under your root (/) partition. It’s not a problem if you have assigned a large space to your root (/) partition, but sometimes due to heavy space usage by users of your SLED/SLES, your /home directory will grow like anything and you will require more space or move it to a separate partition if you want to increase the users quota size. Then you will have to move your /home directory in SLED/SLES from root (/) partition to a separate partition.
For example, you have an extra partition or extra formatted disk in your SLES/SLES machine. (If you don’t then attach a new one :)) In my case, I have a root (/) partition (/dev/sda1) of 10 GB and the /home directory is mounted under the root (/) partition. I have also an extra 10 GB formatted disk (/dev/sdb1)
My current status of disk usage:
NOVELLDESK:~ # df -kh / Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.6G 9.3G 240M 98% / NOVELLDESK:~ # df -kh /home Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.6G 9.3G 240M 98% / NOVELLDESK:~ #
You can see that most of the disk usage is eaten by the /home directory. Below are the steps to move the home directory safely to another partition.
STEP – 1
Inform all users of the system about your maintenance/down time (Which depends on the amount of disk space you are going to move to another partition)
Step – 2
Switch from your current runlevel to runlevel 1
NOVELLDESK:~ # init 1
You can also disable all users login by touching ‘nologin’ file in /etc directory. So we can move all of the /home directory’s contents without any interruption.
NOVELLDESK:~ # touch /etc/nologin
But to be safer, the first trick would be fine.
Step – 3
Mount the partition where you want to move your /home directory.
NOVELLDESK:~ # mount /dev/sdb1 /mnt
Step – 4
Copy all of the /home directory’s data to /mnt where we have mounted our partition.
NOVELLDESK:~ # cp -pr /home/* /mnt/
Here ‘-p’ will do the magic, it will preserve all permissions related to /home/* folders/files.
Step – 5
Move the /home directory to any other name so we can roll back if something goes wrong.
NOVELLDESK:~ # mv /home /home_bkp
Step – 6
Now unmount /dev/sdb1, make a new /home directory and mount that partition there.
NOVELLDESK:~ # umount /mnt NOVELLDESK:~ # mkdir /home NOVELLDESK:~ # mount /dev/sdb1 /home
Step – 7
Check the status of the mounted partition using the ‘mount’ command and also check the permissions of all the user’s directories on newly mount partitions.
Step – 8
Now do the /etc/fstab entry, so if you reboot/restart your SLED/SLES, your new partition (/dev/sdb1) will always mount on /home
NOVELLDESK:~ # echo "/dev/sdb1 /home reiserfs defaults 0 0" >> /etc/fstab
Step – 9
Now time to test:
Move to your desire runlevel
Create one user from yast2
Logged in with newly created user
Test all basic services you configured for that user
If everything looks normal, then inform all your users.
After getting no complaints from users, don’t forget to delete the /home_bkp directory to free space on your root (/) partition for which we have done the above exercise
That’s all for now…