Linux move home to another partition

Arch Linux

You are not logged in.

#1 2016-05-06 18:52:57

[SOLVED]Move home to another disk

I have been using Arch for a week, I pre-installed a couple of times now, but the last time I forgot something. I divided my disks to have separate /home and /root (and /boot but irrelevant for my question). So I installed everyting on /dev/sdaX, but now it got me, that I forgot to assign /home to be on /sdaY. I’d like to have my home on the other partition. Is it possible now. (even considering losing all my data on the user now), can I just mount (reassign) the home directory on the other partition?

I hope someone understands my quesion!

Last edited by Mladia (2016-05-06 20:18:20)

#2 2016-05-06 19:48:41

Re: [SOLVED]Move home to another disk

can I just mount (reassign) the home directory on the other partition?

Yes, assuming you already created a filesystem on the new partition. Add an entry in /etc/fstab to make it mount automatically after reboot.

(even considering losing all my data on the user now),

To save data, mount new home partition to somewhere else, copy data (ie. with «rsync -a» as root), then umount the partition and mount it again on /home.

#3 2016-05-06 20:07:14

Re: [SOLVED]Move home to another disk

1. I got the UUID for the /dev/sda8 (that I want to make new /home)
2. added entry to fstab for it to be mounted on /media/home (random dir)
3. sudo mount -a
4. coppied everything with rsync and fancy arguments
5. changed the last added entry to fstab for the location from /media/home to /home
6. sudo mount -a
7. done
8. .
9. profit!

Good luck to all, who are trying this

Источник

How to Move Home Directory to New Partition or Disk in Linux

On any Linux system, one of the directories that will surely grow in size has to be the /home directory. This is because system accounts (users) directories will reside in /home except root account – here users will continuously store documents and other files.

Another important directory with the same behavior is /var , it contains log files whose size will gradually increase as the system continues to run such as log files, web files, print spool files etc.

When these directories fill up, this can cause critical problems on the root file system resulting into system boot failure or some other related issues. However, sometimes you can only notice this after installing your system and configuring all directories on the root file system/partition.

In this guide, we will show how to move the home directory into a dedicated partition possibly on a new storage disk in Linux.

Installing and Partitioning a New Hard Disk in Linux

Before we proceed any further, we’ll briefly explain how to add a new hard disk to an existing Linux server.

Note: If you already have a partition ready for the operation, move to the section which explains the steps for moving /home directory in a partition of its own below.

We’ll assume you have attached the new disk to the system. On a hard disk, the number of partitions to be created as well as the partition table is normally determined by disk label type and the first few bytes of space will define the MBR (Master Boot Record) which stores the partition table as well as the boot loader (for bootable disks).

Although there are many label types, Linux only accepts two: MSDOS MBR (516 bytes in size) or GPT (GUID Partition Table) MBR.

Let’s also assume that the new new hard disk (/dev/sdb of size 270 GB used for the purpose of this guide, you probably need a bigger capacity on a server for large user base.

First you need to set the disk label type using fdisk or parted; we have used GPT label name in this example.

Note: fdisk only supports MSDOS MBR for now and parted supports both labels.

Now create the first partition (/dev/sdb1) with size 106GB. We have reserved 1024MB of space for the MBR.

Explaining the command above:

  • a – option to specify the partition alignment.
  • mkpart – sub command to create the partition.
  • primary – sets partition type as primary on the hard disk (other values are logical or extended).
  • 1074MB – beginning of partition.
  • 107GB – end of partition.
Читайте также:  Bad system config info при загрузке windows 10 как исправить через биос

Now check the free space on the disk as follows.

We will create another partition (/dev/sdb2) with size 154GB.

Next, let’s set the filesystem type on each partition.

To view all storage devices attached on the system, type.

List New Storage Device

Moving Home Directory into a Dedicated Partition

Now we have added the new disk and created the necessary partition; it’s now time to move the home folder into one of the partitions. To use a fileysystem, it has to be mounted to the root filesystem at a mount point: the target directory such as /home.

First list the filesystem usage using df command on the system.

Linux Filesystem Usage

We will start by creating a new directory /srv/home where we can mount /dev/sdb1 for the time being.

Then move the content of /home into /srv/home (so they will be practically stored in /dev/sdb1) using rsync command or cp command.

After that, we will find the difference between the two directories using the diff tool, if all is well, continue to the next step.

Afterwards, delete all the old content in the /home as follows.

Next unmount /srv/home.

Finally, we have to mount the filesystem /dev/sdb1 to /home for the mean time.

The above changes will last only for the current boot, add the line below in the /etc/fstab to make the changes permanent.

Use following command to get the partition UUID.

Once you know the partition UUID, open /etc/fstab file add following line.

Explaining the field in the line above:

  • UUID – specifies the block device, you can alternatively use the device file /dev/sdb1.
  • /home – this is the mount point.
  • etx4 – describes the filesystem type on the device/partition.
  • defaults – mount options, (here this value means rw, suid, dev, exec, auto, nouser, and async).
  • 0 – used by dump tool, 0 meaning don’t dump if filesystem is not present.
  • 2 – used by fsck tool for discovering filesystem check order, this value means check this device after root filesystem.

Save the file and reboot the system.

You can run following command to see that /home directory has been successfully moved into a dedicated partition.

Check Filesystem Usage on Linux

That’s It for now! To understand more about Linux file-system, read through these guides relating to filesystem management on Linux.

In this guide, we explained you how to move the /home directory into a dedicated partition in Linux. You can share any thoughts concerning this article via the comment form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Ubuntu Documentation

Overview

This guide offers detailed instructions for migrating your home directory into its own dedicated partition. Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro. This works because /home has a subdirectory for each user’s settings and files which contain all the data & settings of that user. Telling Ubuntu to use an existing home partition can be done by selecting «Manual Partitioning» during the installation of Ubuntu and specifying that you want your home partitions mount point to be /home, ensure you mark your /home partition not be formatted in the process. You should also make sure the usernames you enter for accounts during installation match usernames that existed in a previous installation.

This guide will follow these 8 basic steps:

  1. Set-up your new partition
  2. Find the uuid (=address) of the new partition
  3. Backup and edit your fstab to mount the new partition as /media/home (just for the time being) and reboot.
  4. Use rsync to migrate all data from /home into /media/home
  5. Check copying worked!
  6. Move /home to /old_home to avoid confusion later!
  7. Edit fstab again so the new partition mounts as /home instead of as /media/home
  8. Reboot or remount all. Check system seems to be working well
  9. Delete the /old_home after a while

The guide is written in such a way so that at any point in time if there is a system failure, power outage or random restart that it will not have a negative impact on the system and SHOULD safeguard against the possibility of the user accidentally deleting their home directory in the process.

Читайте также:  Windows 10 не находит камеру ноутбука

Creating a new partition

Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro. This works because /home has a subdirectory for each user’s settings and files which contain all the data & settings of that user. Also, fresh installs for linux typically like to wipe whatever partition they are being installed to so either the data & settings need to be backed-up elsewhere or else avoid the fuss each time by having /home on a different partition.

Setup Partitions

This is beyond the scope of this page. Try here if you need help. Memorize or write down the location of the partition, something like /sda3. When you do create a new partition it is highly suggested that you create an ext3 or ext4 partition to house your new home directory.

Find the uuid of the Partition

The uuid (Universally Unique Identifier) reference for all partitions can be found by opening a command-line to type the following:

Alternative Method

For some older releases of Ubuntu the «blkid» command might not work so this could be used instead

Now you just need to take note (copy&paste into a text-file) the uuid of the partition that you have set-up ready to be the new /home partition.

Setup Fstab

Your fstab is a file used to tell Ubuntu what partitions to mount at boot. The following commands will duplicate your current fstab, append the year-month-day to the end of the file name, compare the two files and open the original for editing.

1. Duplicate your fstab file:

2. Compare the two files to confirm the backup matches the original:

3. Open the original fstab in a text editor:

and add these lines into it

and replace the «. » with the UUID number of the intended /home partition.

NOTE: In the above example, the specified partition in the new text is an ext3, but if yours is an ext4 partition, you should change the part above that says «ext3» to say «ext4», in addition to replacing the . ‘s with the correct UUID. Also note that if you are using Kubuntu, Xubuntu or Lubuntu you may need to replace «gedit» with «kate», «mousepad» or «leafpad», respectively. They are text editors included with those distributions.

4. Save and Close the fstab file, then type the following command:

This command will create a new directory, later used for temporarily mounting the new partition. At the end of the procedure this directory can be removed.

Now you can restart your machine or instead of rebooting you might prefer to just re-load the updated fstab

Either should have mounted the new partition as /media/home. We will edit the fstab again later so this arrangement of the partition is only temporary.

Copy /home to the New Partition

Next we will copy all files, directories and sub-directories from your current /home directory into the new partition. If you do not have an encrypted home file system, just do the following:

I prefer adding the «—progress» tag just before the «—excludes» one — otherwise there is no indication of anything happening. The «—progress» tag reports on each file individually so you see tons of unfamiliar stuff scrolling by very fast. Rsync can be interrupted as many times as you like and it checks to see how much has already been done when you start it up again. So, this copying stage can be broken down into many sessions. After it has completed once it’s wise to run it a couple more times just to make sure it includes everything you may have added since first starting the first copying/syncing session — even if you’ve done the whole thing all in just one session.

The —exclude=’/*/.gvfs’ prevents rsync from complaining about not being able to copy .gvfs, but I believe it is optional. Even if rsync complains, it will copy everything else anyway. (See here for discussion on this)

Encrypted file systems

If you have an encrypted home file system, then the above will just leave you with an unencrypted copy of your files, which is probably not what you want. You could re-encrypt them after copying, or copy them in their encrypted form. Here is one way to do that.

First, you’ll need to shut down, and reboot from a LiveCD or USB stick. Then you’ll need to mount your root partition and new home partition. (You can do this by selecting those devices in the file viewer). They will be mounted under /media/ubuntu — so for example, if you named your root partition linux-root, then your old home directory will be found at /media/ubuntu/linux-root/home. And if you named your new home partition linux-home, then this will be found at /media/ubuntu/linux-home. So, now you can copy your encrypted home files (here assuming your partitions are named linux-root and linux-home):

Читайте также:  Драйвер usb serial ch340 для windows 10

There is no point trying to exclude any files with specific names, because the names of the files are encrypted too!

Leave your machine running from the LiveCD or USB for the moment.

Check Copying Worked

You should now have two duplicate copies of all the data within your home directory; the original being located in /home and the new duplicate located in /media/home. You should confirm all files and directories copied over successfully. One way to do this (for an unencrypted file system) is by using the diff command:

If you are doing this from a LiveCd or to an existing partition that already has stuff on it you may find differences but hopefully it should be obvious which diffs you can ignore.

You can also expect to see some errors about files not found. These are due to symbolic links that point to places that don’t presently exist (but will do after you have rebooted). You can ignore these — but check out anything else.

Encrypted file systems

If you have an encrypted file system, the command will look more like this.

Now you can shut-down, remove the LiveCD / USB stick, and reboot as normal.

Preparing fstab for the switch

We now need to modify the fstab again to point to the new partition and mount it as /home. So again on a command-line

and now edit the lines you added earlier, changing the «/media/home» part to simply say «/home» so that it looks like this:

Then, press Save, close the file but don’t reboot just yet.

Moving /home into /old_home

Backing up your old home, just in case things have not gone completely smoothly, is best done right now. Here is how:

As long as you have not rebooted yet, you will still see 2 copies of your /home directory; the new one on the new partition (currently mounted as /media/home) and the old one still in the same partition it was always in (currently mounted as /home). We need to move the contents of the old home directory out of the way and create an empty «place-holder» directory to act as a «mount point» for our new partition.

Type the following string of commands in to do all this at once:

By default, when you open a terminal window it places you within your home directory. Typing cd / takes us to the root directory and out of home so we can then use the sudo mv command to essentially rename /home into /old_home, and finally create a new, empty /home placeholder.

Reboot or Remount all

With;

  1. your fstab now edited to mount your new partition to our /home place-holder and
  2. the original /home now called /old_home,

it should be a good time to reboot your computer to check the whole thing really did work. Your new partition should mount as /home and everything should look exactly the same as it did before you started.

Btw, geeks might prefer to avoid rebooting by just re-loading the updated fstab

There is no need to reboot — unless you have an encrypted file system.

Troubleshooting

If you receive an error like ‘The volume may already be mounted’, use the following command to unmount the drive first before re-doing the last step again. (note the «n» should be missing from the command, making it «umount»)

Then try mounting again

Deleting the old Home

You can keep using the system as it is for ages before doing this, unless you are desperately short of space on the / partition. It’s probably best to leave this step until a long time after you have been using the system happily. When you do eventually feel safe enough to delete the old home then you can try;

Be careful with the above command because mis-typing it could result in the deletion of other files and directories!

Technical Notes and Resources

Rsync was chosen over cp and find|cpio because it seemed to maintain permissions.

Different filesystems on the same disk

If you’re moving from Windows and your new home partition is going to be an old ntfs partition (the D: disk) while you convert the C: disk to a journaling partition where you install Linux, this won’t work, there will be a huge load on the processor. You should convert the two partitions to ext3 or ext4 or keep both partitions as ntfs (I haven’t checked this last option). But working with two different filesystems on the same drive simultaneously doesn’t seem to be a good option.

Partitioning/Home/Moving (последним исправлял пользователь Simon Boddy 2015-11-13 13:16:06)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Оцените статью