Moving home to new drive subdirectory, I have some questions

Hello. I know it’s pretty straight forward to mount an entire partition to /home, but I didn’t really find any examples online of people mounting a subdirectory to /home. So I wanted to double check here to make sure I’m doing it correctly before I reboot my system and end up with an unbootable system.

Steps that I’ve done:

  1. Created a Linux filesystem partition with fdisk
  2. Created an ext4 filesystem with mkfs
  3. Mounted new partition /dev/sda1 to /mnt
  4. Run: cp -rp /home /mnt (I want home to be a subdirectory, not the root of the filesystem)
  5. Added the following entries to /etc/fstab (UUID removed)
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/sda1      ext4    defaults,noatime 0 2
/mnt/sda1/home                            /home          none    defaults,nofail,nobootwait,bind 0 2

And from here the steps that I think I need to do to finish before rebooting:
6. Unmount /dev/sda1 and run mkdir /mnt/sda1
7. Run mv /home /home.old just in case, and then: mkdir /home
8. Ready to reboot?

My questions are:

  1. Is there anything I’m missing?
  2. Can I move /home while logged in? Or do I need to use a live disc?
  3. Is my new fstab entries correct?

Don’t move/copy the whole directory /home
but rather only it’s contents
like this after you mounted what is going to be your new /home partition:

cp -ar /home/* /mnt

What you did created a /home directory with all the files under it

What you need is just the contents of the /home directory.

You can then mount that partition to /home in your main system:

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /home ext4 none defaults 0 2

no need for two mounts and a bind mount …

because:
that directory already exists in your main system, you just need to mount the partition containing the contents of it
to /home

You may get away with copying while logged in
but it’s cleaner to just log out of the graphical session and do it from TTY via
sudo su -
then you are root and can copy without problems.

ps:
reading again I realized that you wrote this:

I probably misunderstood what you wanted to do
so my post likely missed the mark

… although I saw you trying to do exactly what I described

3 Likes

The first question that springs to mind is Why do you want to do this?”

  1. There is no sane rationale behind moving the home directories outside of /home in the root directory, and /mnt is intended as a temporary mountpoint only.

  2. The change will probably be undone again when the filesystem package is updated. This package ensures that the filesystem hierarchy is sane and compliant with the Filesystem Hierarchy Standard.

That should be… :arrow_down:

cp -RPp

You’d want to preserve permissions and file ownership.

You can do it from runlevel 1, logged in as root. It would not be a good idea to do it from the normal mode of operation. Doing it via a live USB/CD/DVD is probably the better/easier way.

I’ve written a tutorial on how to split off a directory onto another volume, with /home as an example, but it does not cover a modification of the directory hierarchy. :arrow_down:

5 Likes

Well, I’m coming from Windows, so that might offer you some insight into my perspective, and, while yes, the users directory on Windows is on C:, my new system has a 512GB M2 SSD for the OS, and a 4TB HDD for storage. I do not want to clutter the paltry 512 GB with downloads, documents, and other such user files. I want to use the 4TB storage drive for that.

The other concern I have is that I am migrating my files (> 1TB of data) from my old Windows 7 PC to this new PC. I don’t want that data to be locked up/encrypted under a user home directory. I also don’t want to worry about having to rebalance partitions, should my user directory or my storage directory grow in size.

1 Like

I don’t think so.

No, while moving (copy+rm) no other process should access the files.

Instead of the live disk, you can switch to rescue target (on the terminal): systemctl isolate rescue.target and do everything on the terminal as root.

  • Since you use bind, no fsck is needed. So 0 20 0 and the ext4 partition gets already checked.
  • nofail,nobootwait is suboptimal here. /home is a part of system, so crazy stuff can happen when it is not there.

I am as crazy as the OP is. I guess he has the same thought as I had…

He has an external HDD, and he bothers to format it just for /home, since he wants to use the partition not only for home, but also for other things. If /home is full, he needs to partition it again, and that can take hours. I totally understand that.

That is a method which mimics the mount of a btrfs subvolume in some way, which is really flexibile.

1 Like

Then why not use btrfs? It’s easy to create subvolumes, and they are dynamic in size — the free space is shared by all subvolumes.

I’m entirely unfamiliar with this, but a preliminary search on the subject makes it sound like it could replace ext4? But are there any cons to using btrfs? What I read suggests it to be entirely superior to ext4 with features that ext4 doesn’t support, as well as much larger volumes, with many more files, and larger max file sizes. Filesystems aren’t something a Windows user gives any thought since there were no options, it was just NTFS.

You can’t mount a subdirectory of a partition like that…
You can only mount a whole partition, or a subvolume if the filesystem on that partition provides that functionality like BTRFS/etc

My whole system is on BTRFS, actually BTRFS inside an encrypted partition :wink:

You can find good Information about Btrfs in the wiki


Switch from Windows - how to use GNU/Linux:


Working with Drives


System hirarchy:

https://man.archlinux.org/man/file-hierarchy.7

1 Like

Encryption setup is usually directly on the partition. If you don’t want your data partition to be encrypted, then just don’t set it. :person_shrugging:


Then just use a single partition for the whole drive. :person_shrugging:
Putting the home folder as a subdirectory rather than the root folder has no relation with this.

2 Likes

I am fan of BTRFS, but there are cases where you don’t want to use it.

  • Not on a slow HDD, even on USB HDDs. SSDs are preferred for BTRFS.
  • There is a really stable (buyable) EXT4 driver on windows, but not for BTRFS.

I appreciate using it on my root file system, but I would never use it for any critical files.

ext4 is the gold standard on linux when it comes to filesystems and it works darn good.

I am just talking about my expirience:

  • ext4 on HDDs and USB HDDs and for critical files
  • BTRFS for SSDs and root file systems and non-critical files.
1 Like

Yes, that is correct. In fact, Theodore Ts’o, the maintainer of ext4, said himself that ext4 was only a mild step up from ext3 and a placeholder for btrfs, and that he expects btrfs usage to supersede that of ext4 in the foreseeable future.

Every filesystem has pros and cons. Personally, I’ve been using btrfs on this machine here — which is my production system — since 2019, and I haven’t had any problems with it yet. It’s rock-solid stable and it’s pretty fast too.

Comparing btrfs to ext4 is actually unfair, because btrfs is much more like zfs in terms of its feature set and internal operation.

2 Likes

Thank you, everyone, for the information. I will spend some more time reading all of this and, hopefully, find the optimal path forward. BTRFS sounds like it might be the way to go.

1 Like

Believe me… you can. :wink: It is the same as:

sudo mount --bind /mnt/sda1/home /home

Never used a bind mount?

1 Like

As I said in my ps before, I might have misunderstood you.
Hence the questions:

Is your goal to use the new disk partition as your /home directory?
Completely replacing what is currently in your /home (and all users in it)?
This is what it looked like to me.

Or do you want to use the new disk partition as some way of expanding available space for your user account
(/home/user)?
I don’t think so - the copying you did would not have been necessary.
This can be done by mounting the empty disk partition to some directory in /home/user
like:
/home/user/external_disk

1 Like

No. I wanted a subdirectory to be /home, not the partition root.

Yes, I don’t want user files on the OS partition, since it’s a small partition.

Why not? When I installed Manjaro, I only had one drive (and one partition). Under these circumstances, isn’t /home actually a subdirectory of the root partition? I wanted to move /home to /other-volume/home, and then bind /other-volume/home to /home. The reasoning, as previously stated, was that I wanted to use /other-volume as more than just a /home directory. I wanted other directories on the volume for other data.

After all, in my eyes, a storage filesystem should be structured to meet the needs of the user.

I hadn’t really considered this as an option, more or less out of ignorance. Also, I was under the impression that the /home/user directories would be encrypted, and I didn’t want my other data to be encrypted. Also my ignorance, if that’s not the case.

1 Like

It would be much simpler to simply mount another partition to /home — after moving your data to said partition first, of course — or to mount a btrfs subvolume there.

1 Like

This is probably you, misunderstanding me.

It is.
Always.
Not only “under these circumstances”.

What you don’t seem to grasp is:
The /home directory as such is always part of the / file system structure.
It’s always there.
It can’t be moved - but you can attach a separate storage there - like your new partition.

You can attach your new, bigger partition to this point (mount it to that directory).

You copy all of the content of your current /home directory, which currently is on your original drive,
to this new partition.
Then you attach (mount) that partition, the new disk which now contains what was previously in your /home directory
to /home
Voila: you now have all the space on the new disk available for /home - as well as your original content.

I don’t quite understand what you mean by this.
You can always create new directories under /home
They will then also all be on the new drive partition.

Perhaps you can describe your final goal, the structure you want to achieve.
We could then recommend how to achieve that.

And mount additional partitions/devices on those as well. A mountpoint does not have to be a root-level directory.

For instance, the EFI System Partition is commonly mounted on /boot/efi, and the contents of /boot can themselves exist either on the root filesystem or on a separate partition.

To the end-user, it all looks the same, regardless of whether it’s a separate volume or not. That’s what the unified directory hierarchy of UNIX is all about. /boot is /boot and /home is /home, whether its contents live on the root filesystem, on another filesystem on the same computer, or even on a filesystem on a server across the network.

1 Like

You asking me? :rofl:

But yea seems i misread /mnt/sda1/home as /dev/sda1/home :woman_facepalming:
Ahh well we’re all human… :woman_shrugging: