How to move your home directory safely in SLED/SLES

By: dhardik

September 25, 2008 12:23 pm





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% /


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


Note: You must be aware that runlevel 1 is single user mode so you must have physical access of the system.


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


Note: Please specify your file system type before executing the above command, I have ‘reiserfs’ as default.


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…

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.

Tags: ,
Categories: SUSE Linux Enterprise Desktop, SUSE Linux Enterprise Server, Technical Solutions

Disclaimer: As with everything else in the SUSE Blog, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.