HowTo: Use Separate Partitions for the Users' Data [i.e. /home] and the Root Filesystem

Many new Linux users perform their first installations on a single partition. Then after a time they realise that greater security is achieved by moving the user directories under /home across to a separate partiton. There are many ways to achieve this transition. The one used here is structured for the convenience of new users.

THE SHORT VERSION

  • Log in to runlevel 1 as the root user and activate the X Window system
  • Rename the old /home directory to store and save the user data
  • Create your new home partition and mount it in /home
  • Copy the stored user data to the new /home directory using cp with the -a archive switch
  • Reboot and log on as a normal user

THE LONG VERSION

Runlevel 1 as root, with X Window system: First you switch to a state where you have the minimum of services running, you have root authority to carry out the modifications and you have the X windows system so you can use the normal GUI tools. Reboot the computer and log on as root. Then open a terminal and issue the init 1 command by entering the following in a console:

init 1

X Windows will be replaced by a full-screen console. You will be presented with a login prompt lie so:

hostname login:

Ignore it. It's spurious and will just confuse the issue if you respond. You wait for an invitation to enter root's password, like so:

give root password for login:

It may take some time, up to a minute, before the password invitation for root appears. Once you are logged in, enter the command startx to activate the X Windows system and enable the graphic interface.:

startx

Store the old /home data: You can now disassociate the old /home from the filesystem to make way for the new /home partition by renaming the old /home directory to /oldhome. Open a console and issue this re-naming command:

mv /home /oldhome
pic of partitioner


Create the new /home: Open Yast partitioner --> System --> Partitioner and create your new partition. Make sure to add the mount point /home as in the screenshot.

Copy the stored user data to the new /home directory: When you exit Yast Partitioner the new /home partition will be mounted in the filesystem. The scene is set for adding the user data to the new /home. Simply open a console and issue the copy command with the -R option set and with option -p set to preserve file and directory ownership. Here's the console command:

cp -a /oldhome/* /home

FYI: The archive switch, -a, is the same as switches -dpPR. It preserves permissions, ownership and time stamps and also copies links but does not follow symbolic links.

Job done: simply reboot when the copy command has finished and log in as a normal user to return to normal operations. There is a backup copy of the user data in directory /oldhome which you should keep for a time, as a precaution.

Credits: thanks to hcvv and ken_yap for discussion & clarification