Dedicated home partition

Header

Intro

How to use the same home partition for reinstalling a distro or using a new distro but wanting to use the same home partition (i.e. preferences, Documents…)

Before Installing

Find the user and group id’s (uid and gid) on your current distro before reinstalling/adding new distro and write them down:

id

And the username of your regular user:

whoami

Get your home partition fstab entry:

grep home /etc/fstab

If your fstab uses a UUID, keep in mind that this will change if you change your partition map.

Note: If only wanted to change the permissions on the home partition to match a new install, see the final step.

Install

During the installation process the you will be asked about partitioning. You should not partition unless you know what you are doing. Some distro’s will safely allow resizing and adding new partitions. Some partitions tools can safely shrink, expanded, and add new partition. If you need a new partition or a reorganization of partitions consider adding parted to the installer CD if it isn’t already and partitioning with that.

When you got your disk partitioned, start the installer and manually set the partitions you plan to use. Don’t use the dedicated home partition or the installer will likely erase it. Also during the install don’t use the username from your previous install, likely the installer will choose a different uid and gid so this is best not to, later matching id’s will be set. Finish installation and reboot.

After Reboot

Exit if automatically logged in and goto console Ctl+Alt+F1. Log in as root and find out what the newly created user uid/gid is.

id <new-username>

Keep a note of the groups the distro added and also be sure the new user didn’t get the same uid as the one you already had.

Add a new user:

adduser

For username select your old username, for uid match the old one. If you’d like to prevent possible uid conflicts in the future, consider using a higher uid like 1050. Enter gid to match the one you are using on the new system. Then add the groups that match the user that the distro created.

You can also use the useradd command but I find the former easier. For example (careful though as groups may vary from system to system):

useradd -d /home/user --uid 1050 -G adm,audio,cdrom,cdrw,fcron,portage,users,usb,video,wheel -s /bin/bash

Delete distro created user:

userdel <username>

And delete the folder in the home directory for that user:

rm -rf /home/*

This will delete everything in the home folder (it is not sane to mount a partition on an folder containing contents.)

Add home partition to fstab

Add the home partition to be loaded at boot (if already not added). For example:

nano /etc/fstab
...
/dev/sda5 /home       ext4    defaults   0 1

Besure to enter the correct filesytem type and settings.

Now reboot and login to your new user.

Match your home partition to your new distro ids

Warning: If you’ve done the above you’re already done, don’t this.

Mount the home partition and change to the directory of the dedicated home partition:

mount /dev/<home-partition>
cd /mnt/<home partition>

Then change the old user and group id’s to the new one:

find . -uid <old-uid-number> -gid <old-gid-number> -exec chown -h <username>:<usergroup> {} +

This will change permissions on all files/folders/links that have both the old uid number and gid number. Some (very few) files will not match but most programs will eventually write to them and update them. To update all file/folders/links:

find . -exec chown -h USERNAME:USERGROUP {} +/

2 thoughts on “Dedicated home partition

Leave a comment