This is a follow-up to a former question about systemd, BTRFS, /home being an individual subvolume and the following restriction of systemd I would like to work around:

The file system where the linked unit files are located must be accessible when systemd is started (e.g. anything underneath /home or /var is not allowed, unless those directories are located on the root file system).

/home is mounted by systemd properly, but contains service files which systemd should start during boot already as well and that doesn't work. /etc/fstab looks like the following:

# <file system> <mount point>   <type>  <options>  <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=0841ef72-e9d4-45ca-af22-a403783859c6 /        btrfs   noatime,nodiratime,subvol=@ 0     1

# /home was on /dev/sda1 during installation
UUID=0841ef72-e9d4-45ca-af22-a403783859c6 /home    btrfs   noatime,nodiratime,subvol=@home 0 2

As initrd is a compressed archive with lots of scripts, in theory it's possible to decompress that (gzip -dc /.../initrd.gz | cpio -id), change some scripts and mount /home additionally. I already found the following code in a file called init which seems to be responsible for mounting /. Following those function calls reveals parse logic for fstab etc.

maybe_break mount
log_begin_msg "Mounting root file system"
# Always load local and nfs (since these might be needed for /etc or
# /usr, irrespective of the boot script used to mount the rootfs).
. /scripts/local
. /scripts/nfs
. /scripts/${BOOT}
parse_numeric ${ROOT}
maybe_break mountroot

The problem is that I don't want to build a new initrd for each and every kernel update of Ubuntu of course.

So besides customizing the scripts manually, is there some other way to get initrd to mount additional file systems like /home? Something like kernel parameters provided during startup, maybe some hooks one is able to trigger using special files in / or such?

I found the following to be of interest:

if read_fstab_entry /usr; then
        log_begin_msg "Mounting /usr file system"
        mountfs /usr

If I understand correctly, this recognizes additional mount points like /usr already. But I couldn't find something like that for /home.

  • Uh, typically once your root filesystem is mounted /etc/fstab will have become available and will used to mount all your other file-systems so you won't have to add anything to your initrd image. – HBruijn May 2 '18 at 7:49
  • @HBruijn The problem is that systemd is mounting /home(?) and can't find service files I have there before that(!). I would like to workaround that using initrd and changed my question to make that more clear. – Thorsten Schöning May 2 '18 at 8:00
  • The bigger question is: why do you have services in /home in the first place? – Gerald Schneider May 2 '18 at 8:02
  • Then fix your service files rather than messing about in your initrd. – HBruijn May 2 '18 at 8:25
  • @GeraldSchneider Because /home contains various custom customer software and services. I had a look at user configs for systemd in the meantime, but have some trouble getting those executed automatically. But at least there status is correct. – Thorsten Schöning May 2 '18 at 17:19

Doing extra stuff in the initrd is as simple as writing a shell script (busybox shell to be precise), since initramfs-tools supports hooks/plugins.

In your case, create a script in /etc/initramfs-tools/scripts/local-bottom/mount-home which could look like:


   echo "$PREREQ"

case $1 in
   exit 0

# Mount /home
mount /dev/disk/by-uuid/1234567890 ${rootmnt}/home

Note: local-bottom is run after the rootfs has been mounted. The target rootfs is assembled in ${rootmnt}.

Then you can update-initramfs to update your initrd. Every kernel package update will then contain your custom script.

For more documentation, look into the man page of initramfs-tools.8.

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.