2

I tried to use a bind mount from my /d(another partition)/usr to /usr

And I tried that several times using fstab and failed, can someone have a look?

fstab file:

# / was on /dev/nvme0n1p2 during installation
UUID=b3dc29ae-e63b-4ced-89ab-1173755b3f6c /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=3124-2C6F  /boot/efi       vfat    umask=0077      0       1
# /d was on /dev/sda during installation
UUID=2ca0cc41-b46c-4b39-8c08-70bccc8698d2 /d              ext4    defaults        0       2
/swapfile                                 none            swap    sw              0       0
/d/usr /usr bind bind 0 0

If I mount it somewhere that's not /usr everything works fine.

But if I mount on /usr, it gives the following error on startup:

mounting /d/usr on /root/usr failed: No such file or directory.
failed to mount /d/usr as /usr file system.

I copied these 2 errors myself because you can't actually copy them.

After that ubuntu leads me to a ash terminal and I can sudo mount -a just fine, but it stops me from starting up.

the fstab works well anytime after startup using sudo mount -a.

As K7AAY recommended, the version is Ubuntu Desktop 20.04 LTS, 64bit.

ygy
  • 151
  • 6
  • first "bind" should read "none", although I am not sure this will be a problem. Nevertheless, please try first again with /d/usr /usr none bind 0 0 – vanadium May 26 '20 at 14:05
  • @vanadium I changed it and it didn't work. Also, adding a folder in /d named /usr does not change anything. And I am a newbie to linux and ubuntu, may I ask if this have anything to do with mtab? – ygy May 26 '20 at 14:43
  • /usr is a very essential folder containing important system libraries.Why do you want to mount anything on /usr? – mook765 May 26 '20 at 14:47
  • Which Linux distro have you installed (Ubuntu server, Ubuntu desktop, Kubuntu, Lubuntu, Xubuntu, Ubuntu MATE, Mint, et al.), & which release number? Different releases have different tools for us to recommend. Please click [edit] & add that to your question, so all facts we need are in the question. Please don't use Add Comment, since that's our one-way channel to you. All facts about your PC should go in the Question with [edit] as this is a Q&A site, not a general forum, so things work differently here. – K7AAY May 26 '20 at 15:35
  • @mook765 I am pretty short on my SSD storage, after some updates I only have several Gibs left, I want to move my data on a SATA drive. – ygy May 27 '20 at 04:36
  • I doubt that this can work properly, I've tried to move /usr to a different partition in an earlier version, I cant't remember if I tried it with 16.04 or 18.04. Theoratically it should work but in praxis it doesn't. Maybe due to the importance of /usr, maybe a problem with systemd. I don't know if we can have /usr on a dedicated partition when we install the OS this way from the beginning, never tried this. – mook765 May 27 '20 at 06:55
  • @mook765 I previously attempted to use a dedicated partition and it actually works. But the problem is my /usr is not that likely to take up 2TB and I don't know if I should add anything else in the partition, I don't feel like I should create a new partition for it. At this point I do think Ubuntu is special because a lot of others have attempted folder mount /usr on other Linux/Unix systems and succeeded. – ygy May 27 '20 at 11:10

2 Answers2

0

You’re right that it works in some distributions (e.g. it’s straightforward with Slackware) and not for others (e.g. "recent" releases of Ubuntu).

The reason is explained on Booting Without /usr is Broken. I can’t choose quotes but the article is short and worth a read.

But at the end :

There is no way to reliably bring up a modern system with an empty /usr. There are two alternatives to fix it: move /usr back to the rootfs or use an initramfs which can hide the split-off from the system.

If you’re willing to try the second way, maybe this page can help.

In my case I decided to not waste more time on that and chose the first way. My rationale for having a separate /usr partition being space issues on the root partition of an already partitioned hard drive (and I really don’t want to repartition it), I moved /var and /usr/share to their own instead, it seems to work so far.

0

It's apparent that you need the mount command to mount filesystems onto your device.(Except the root partition). But if you have the /usr moved to another partition, the mount command is gone. What is left is /bin(which is a symlink to /usr/bin in some distros but not the case on some others(such as Gentoo)) and /sbin(usually not a symlink). However, in ubuntu, /bin is a symlink, upon the displacement of /usr, mount becomes totally unreachable.

Then how may we solve this? You may generate a initramfs to boot on separate partitions. An initramfs can include the mount command, the filesystem tools(btrfs-progs, e2fsprogs for example), which can help mount the /usr partition onto the root partition and can thus enable /usr on another partition. If your root partition is ext4 and the kernel has ext4 support only as a kernel module, the initramfs can contain tools to make it mount.(If you are curious, the kernel exists(highly possibly) in the /boot directory, which is another partition(likely to be fat32, which can be read by the bootloader and BIOS), so the kernel is always reachable).

Note that a initramfs can do a lot beyond that, such as enable boot with Full Disk Encryprtion. If the tools to decrypt the root partition becomes unavaliable(encrypted), initramfs can give an unencrypted "backup" to make the system decrypt the system first.

Since most Ubuntu users are unfamiliar to initramfs, here's some additional information:

Gentoo Wiki on initramfs

Arch Wiki on initramfs

ygy
  • 151
  • 6