Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Moving /home to a separate partition after installation.

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Moving /home to a separate partition after installation.

#1 Post by edbarx »

Please note that this procedure can easily result in permanent data loss. Be sure to have a backup before taking the plunge. Other than that, enjoy! :)

In the successive posts of this thread, it was pointed out that using /mnt as a mount point may present some undesirable side effects like devices failing to mount. So, it is adviced to create a temporary directory under /mnt instead of using /mnt directly.

Code: Select all

cd /mnt
mkdir destination
In my howto replace /mnt with /mnt/destination.

In my past Linux years I have always used /mnt as a mount point without issues. However, I felt posting the opinion of others doesn't do harm even though I consider it not an absolute necessity.

If you have installed Debian to one partition and you are regretting that fact, be informed that you can easily assign a separate partition for /home, or any other directory you deem deserve to be transferred to a separate partition. This can be done without reinstalling because GNU/Linux doesn't hide its operational 'secrets' from its users. :)

The first thing to do is obviously to find enough free space for the new partition. Then, use a tool (gparted) to format the new partition to some native Linux filesystem like ext3 or ext4. Other filesystems exist but you have to inform yourself about the pros and cons in using them instead of ext3 and ext4. Once you have a separate formatted partition, you will need to copy the contents of the /home directory to the new partition. This can be done using various CLI tools under root. You can use cp -a and rsync. I use cp -a although in the past I used rsync. Make sure to mount the new partition before attempting to write to it and pay special attention to the mount point you will be using because you don't want to corrupt the existing partition.

Let us say, the new partition to hold the contents of /home is /dev/sda10:

To mount the partition:

Code: Select all

# mount /dev/sda10 /mnt
To copy /home to the new partition:

Code: Select all

# cp -a /home/* /mnt
Unmount the partition:

Code: Select all

# umount /mnt
After that, you will need to edit the /etc/fstab file so that at boot the new partition is mounted on /home. This can be done by adding a new entry to the file as root. To find the uuid of the partition, use the blkid command to list the uuids of the partitions.

Add the new entry to the fstab file as shown:

Code: Select all

UUID=the_long_long_uuid  /home           ext4    defaults,noatime        0       2
Save the file.

Reboot to test whether the installation uses the new partition. Use mount without parameters for that.

When you are 100% sure that the installation is using the new partition, you can delete the data under /home which is hidden when /home is used as a mount point. Don't do this while your installation is running, instead use a LiveCD for that. Be cautious because you can easily delete your valuable data especially if you dare to do this procedure without making a backup which I strongly discourage.

Using a Live Debian CD, issue this command as root although it shouldn't be necessary to be root.

Mount the root partition of the installation of which you want to purge the contents of /home.

Code: Select all

mount /dev/sda2 /mnt
I assumed /dev/sda2 contains the blessed installation.

cd to /mnt:

Code: Select all

cd /mnt
Perform the dangerous cleanup:

Code: Select all

rm -rf /mnt/home/*
Unmount the partition:

Code: Select all

# cd /
umount /mnt
NOTE:
This same procedure can be used to transfer any directory to a dedicated partition. However, different mount parameters have to be used in /etc/fstab because /home does not have the same permissions as system directories and you don't want to render your system insecure or unusable.

Enjoy! :)
Last edited by edbarx on 2013-05-02 17:47, edited 3 times in total.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Moving /home to a separate partition after installation.

#2 Post by dasein »

Using /mnt alone as a mount point is a bad idea. Better to create a specific temporary mount point (say /mnt/newhome).

User avatar
4D696B65
Site admin
Site admin
Posts: 2696
Joined: 2009-06-28 06:09
Been thanked: 86 times

Re: Moving /home to a separate partition after installation.

#3 Post by 4D696B65 »

dasein wrote:Using /mnt alone as a mount point is a bad idea. Better to create a specific temporary mount point (say /mnt/newhome).
+1

User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Re: Moving /home to a separate partition after installation.

#4 Post by edbarx »

dasein wrote:Using /mnt alone as a mount point is a bad idea. Better to create a specific temporary mount point (say /mnt/newhome).
Why is it a BAD idea? No reason? Dogma? :roll:
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Moving /home to a separate partition after installation.

#5 Post by dasein »

<Insert extended, caustic personal attack here>

Directories like /mnt and /media are meant as temporary mount points for multiple devices/filesystems. Mounting a single device at the top of such directories makes it impossible to use them as they were meant to be used.

The mere fact that you are ignorant of the consequences doesn't actually mean that those consequences don't exist.

:roll: is right.

User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Re: Moving /home to a separate partition after installation.

#6 Post by edbarx »

dasein wrote:Directories like /mnt and /media serve as temporary mount points for multiple devices/filesystems. Mounting a device at the top of such directories makes it impossible to use them for multiple devices.

The mere fact that you are ignorant of the consequences doesn't actually mean that those consequences don't exist.

:roll: is right.
So, it was only that triviality :!:

Clearly, my ignorance was more like an informed decision rather than a lack of knowledge. :wink:

Notwithstanding, I am of the opinion the changes are not an absolute necessity, I edited my original post to reflect what I was recommended.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Moving /home to a separate partition after installation.

#7 Post by Soapm »

mounting it in /home would make future moves easier. Then all you'd have to do is update fstab to mount your new drive and you're set...

The good thing about Linux is you don't have to do all that registry editing like with Windows...

lkraemer
Posts: 209
Joined: 2011-02-09 05:02
Been thanked: 4 times

Re: Moving /home to a separate partition after installation.

#8 Post by lkraemer »

edbarx,
THANKS! It worked just as you said. It did take a bit to resize my 240G partition back to 440 Gig, but heck it was worth it.

THANKS.

Larry

Post Reply