0

I have a custom, non-default Ubuntu installation, where I use my other Linux distro's boot manager (rEFInd). As such, I don't want Ubuntu to see my EFI partition, on the principle that it has no business to what's there (which has already saved my ass last night when I did an rm -rf /*...). However, because I'm using btrfs as my file system, my /boot directory has to be in a UEFI-readable partition—like the EFI partition. So my solution to this conundrum is to shadow bind mount a subdirectory of the EFI partition, esp:\EFI\ubuntu, onto /boot through commands like these:

mount /dev/sdb2 /boot
mount --bind /boot/EFI/ubuntu /boot

This works perfectly. Ubuntu has access to a /boot partition that it can freely drop its vmlinuz and initramfs into and my boot manager automatically detects the installation. Booting and updating works as expected. The only caveat is, so far, that I needed to use the commands to mount /boot. So like any responsible sysadmin, I made an fstab entry:

UUID=XXXX-XXXX      /boot   vfat    rw,relatime 0 0
/boot/EFI/ubuntu    /boot   none    bind        0 0

Despite being analogous to the commands above, on boot the entire EFI partition remains mounted. The second line, performing the shadow bind mount, does not seem to execute. Is there a way to make this work in fstab and if not, what would be a reliable way to perform the bind mount as quickly as possible after the initial mount?

  • 1
    Does dmesg show the mounts executing. What happens when you do a mount -a? – Raman Sailopal Mar 29 '18 at 12:57
  • What is the output of mount? I am wondering if it is a race condition. – ctrl-alt-delor Mar 29 '18 at 12:58
  • Thanks @RamanSailopal, you helped me find an answer to my own question. – detuur Mar 29 '18 at 14:09
0

As @RamanSailopal suggested, the answer was (of course) in dmesg. The root of the problem was that systemd creates unit files from fstab entries, and for whatever reason, they must have a filename that maps to the mountpoint. In other words, multiple mounts per mountpoint are disallowed.

I worked around this by creating a systemd service file that injects itself as a dependency of local-fs.target, by all means acting like a regular systemd mount unit:

/etc/systemd/system/boot-shadow-mount.service:

# Performs the shadow bind mount to hide the ESP at /boot
# and instead expose the ubuntu subdirectory.

[Unit]
Description=/boot shadow bind mount
Requires=boot.mount
Conflicts=umount.target

[Service]
Type=oneshot
ExecStart=/bin/mount --bind /boot/EFI/ubuntu /boot
ExecStop=/bin/umount /boot
RemainAfterExit=True

[Install]
RequiredBy=local-fs.target unattended-upgrades.service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.