Moving $HOME to a separate data partition?

Bo Berglund bo.berglund at gmail.com
Wed Oct 13 18:59:06 UTC 2021


Referring to earlier thread (now too long) named:
"Getting new hardware - can I just move the disk?"

This concerns the way to put "heavy" disk space" stuff on another partition so
as to keep the system partition lean and easy to back up.

My system uses about 30 GiB for the main stuff and then about 150 GiB for data
located in the home dir and served out by Apache and samba/nfs.

I want to separate the Linux system from my home stuff so the system can be more
easily backed up.

So I am now preparing the main drive using GParted and have done the following:

- Shrunk the system partition to the size of its content + about 30GB.
- Made a copy of this (working) partition on another drive as a backup
- Created a new ext4 data data partition in the free space (about 240 GiB)

Now I want to put a few sizable directories in my home dir (or possibly the
whole $HOME content) on this ext4 partition and mount it such that it will
appear as it is now.

/--home--user
           |--dir1
           |--dir2
           |--dir3
           |..
           |--big1  (contains 5 GiB of stuff)
           |--big2  (contains 8 GiB of stuff)
           |--big3  (contains 6 GiB of stuff)
           |--big4  (contains 5 GiB of stuff)
           |
           |--dir4
           |--dir5
           |--dir6
           |
           |--www  symlinked to Apache (contains 131 GB of stuff)
           |

The plan was to rsync the big1..big4 + www dirs to the data partition which can
be mounted as /dev/sda3

So I tried to create dirs big1..big4 on the data partition but it turns out that
I do not have permissions to do that!!

Very strange, how can I overcome this? The data partition directories shall
behave like normal directories below my home dir, but it seems only root can
write anything there.

If that can be overcome then I am now thinking about *how* to mount this
structure into my home dir such that these directories behave just like they do
right now when they are part of the single partition file system.

I tried to do a test mount after creating a dir test on the data partition (had
to use sudo) and a test dir in my home dir:

$ mkdir /home/bosse/test
$ sudo mount /dev/sda3/test /home/bosse/test
mount: /home/bosse/test: special device /dev/sda3/test does not exist (a path
prefix is not a directory).

So obviously ONLY the partition itself can be mounted and not a directory
therein...

next:
$ sudo mount /dev/sda3 /home/bosse/test  (This succeeds)

But:

$ mkdir test/video
mkdir: cannot create directory ‘test/video’: Permission denied

What I got out of this:

1) It seems like I have to be sudo to create directories in the root of the data
partition.

2) If I make a dir as sudo then it starts working:
$ sudo mkdir test/video   (succeeds)
cd test/video
touch file.txt (This file is created as intended by me (not sudo))

3) Maybe I have to mount the drive elsewhere and then symlink it into my home
dir?
Like so:
$ sudo mount /dev/sda2 /mnt/data
$ sudo ln -sf /mnt/data/video /home/bosse/www
$ sudo ln -sf /mnt/data/big1 /home/bosse/big1
$ sudo ln -sf /mnt/data/big2 /home/bosse/big2
etc

Questions:
1) Is this the only way out save for moving the *whole* $HOME dir onto the data
partition?

2) Will this work for Apache? It is symlinked to /home/bosse/www concerning the
content of the website. So there will be two symlinks in series...

Right now I have not moved any data so I cannot test it yet.
I must run the rsync stuff first to move the data to the data partition.

But I am not sure if I should just rsync the whole $HOME dir as is and then
mount it to /home/bosse in fstab.

With *all* of the home dir on the data partition as one entity mounted to the
/home/bosse dir I would not have to go through the hooplas like above.

If I keep the overall file structure the same as now even though the data has
changed partition, will then things like the nfs and samba shares I have
configured still work if the roots are "in place" albeit being mounted from
another partition?


-- 
Bo Berglund
Developer in Sweden





More information about the ubuntu-users mailing list