You are not logged in.

#1 2021-10-28 16:44:40

cloverskull
Member
Registered: 2018-09-30
Posts: 277

Does /etc/fstab cause root partition to be re-mounted?

Hey folks,

For whatever reason I’ve gone down the fstab rabbit hole of late, and one thing in particular stands out as something I’ve discovered I don’t really understand. The bootloader mounts the root file system, and mount options can be specified on the kernel command line. However, the root partition is _also_ listed in /etc/fstab. Does this mean the root partition is mounted by the bootloader, and then mounted again due to what’s in /etc/fstab?

If the answer to the above is yes, I suppose my next question would be…is this necessary? What would happen if I pulled the root partition out of /etc/fstab? Would it remain mounted from the boot process? And what would happen to fsck?

I’m always looking for ways to eke out a millisecond of additional performance, and the bootup process is one place where I’ve invested quite a bit. I’m curious if there’s another way to optimize here. Also, posted in newbie corner since I’m not sure where else to throw something like this. Thanks for reading.

Offline

#2 2021-10-28 17:12:32

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Does /etc/fstab cause root partition to be re-mounted?

cloverskull wrote:

Does this mean the root partition is mounted by the bootloader, and then mounted again due to what’s in /etc/fstab?

Kernel and/or initrd do the mounting, not the bootloader AFAIK. For remount see https://man.archlinux.org/man/systemd-remount-fs.8

If the answer to the above is yes, I suppose my next question would be…is this necessary? What would happen if I pulled the root partition out of /etc/fstab? Would it remain mounted from the boot process? And what would happen to fsck?

Yeah, you (often?) don't need root in fstab. The mkinitcpio fsck hook probably doesn't care about fstab either, see https://wiki.archlinux.org/title/Fsck#B … e_checking

Last edited by Raynman (2021-10-28 17:13:37)

Offline

#3 2021-10-28 18:22:57

cloverskull
Member
Registered: 2018-09-30
Posts: 277

Re: Does /etc/fstab cause root partition to be re-mounted?

Raynman wrote:

Kernel and/or initrd do the mounting, not the bootloader AFAIK. For remount see https://man.archlinux.org/man/systemd-remount-fs.8

Thanks for the clarification - looks like I was off on some of my language but the remounting of the root filesystem does still take place, so perhaps there's still something to this conversation smile

Yeah, you (often?) don't need root in fstab. The mkinitcpio fsck hook probably doesn't care about fstab either, see https://wiki.archlinux.org/title/Fsck#B … e_checking

Interesting - perhaps it's time to try an experiment. I'd like to completely remove my root filesystem from fstab, maybe perform a before/after comparison using something like systemd-analyze blame or just do a seat of the pants countdown timer.

One potential additional detail here that may be interesting is that I'm using LVM and my root fs is spread across two nvme drives. In /etc/fstab I use the UUID of the ext4 volume in /dev/mapper and in systemd-boot I use the name of the volume, i.e. /dev/arch-vg/rootfs.

My fstab line:

# /dev/mapper/arch--vg-rootfs
UUID=c507580e-636a-4f7c-8d2e-fdec5d591e58       /               ext4            rw,discard,noatime,errors=remount-ro    0 1

My boot configuration in systemd-boot:

options root=/dev/arch-vg/rootfs rw sysrq_always_enabled=1 rootflags=noatime quiet splash loglevel=3 rd.systemd.show_status=auto rd.udev.log_level=3 fbcon=nodefer nowatchdog transparent_hugepage=never mitigations=off audit=0 acpi_enforce_resources=lax random.trust_cpu=1 iommu=pt amdgpu.ppfeaturemask=0xffffffff kernel.nmi_watchdog=0 radeon.dpm=0

Obviously there are some extraneous details here but I just want to make sure I'm doing this right smile So, according to the link you shared regarding fsck, merely setting 'rw' as the mounting option will effectively do fsck as long as it's in mkinitcpio, which it is. In fact, I'll share my relevant mkinitcpio.conf lines here for completeness:

MODULES=(amdgpu vfat ext4)
BINARIES=()
FILES=()
HOOKS=(base systemd sd-plymouth autodetect modconf block lvm2 keyboard fsck)
COMPRESSION="zstd"
COMPRESSION_OPTIONS=(-9)

I suppose to make sure kernel/initrd mount my root fs with all appropriate options, my systemd-boot "rootflags" option should include discard,noatime,errors=remount-ro. Aside from this change, does anything else jump out as needing changed prior to commenting out the relevant line in fstab and...giving it a whirl? https://butt.holdings

Thanks!

Offline

#4 2021-10-28 19:23:18

loqs
Member
Registered: 2014-03-06
Posts: 18,994

Re: Does /etc/fstab cause root partition to be re-mounted?

cloverskull wrote:

So, according to the link you shared regarding fsck, merely setting 'rw' as the mounting option will effectively do fsck as long as it's in mkinitcpio, which it is.

That is certainly true when the initrd does not use systemd and the fsck hook is run.  I am doubtful if it is also true for systemd based initrds such as yours.

Offline

#5 2021-10-28 19:33:10

cloverskull
Member
Registered: 2018-09-30
Posts: 277

Re: Does /etc/fstab cause root partition to be re-mounted?

Hm, ok, so changing back from systemd hooks to udev and configuring my kernel boot parameters in systemd-boot would be necessary? Sorry if any of my language is inaccurate here smile

Offline

#6 2021-10-28 19:42:47

loqs
Member
Registered: 2014-03-06
Posts: 18,994

Re: Does /etc/fstab cause root partition to be re-mounted?

Before that I would suggest trying changing rw to ro,  the root filesystem is then mounted readonly which meets the start condition for  systemd-fsck-root.service ConditionPathIsReadWrite=!/
What I am not sure is if systemd-fsck-root.service will remount / RW on completion or if without an fstab entry for / it will remain RO.
Edit:
Looks like it would normally need a fstab entry for systemd-remount-fs.service to remount it RW,  exception [1] is if SYSTEMD_REMOUNT_ROOT_RW=TRUE is set (usually set by systemd-gpt-auto-generator)

[1] https://github.com/systemd/systemd/blob … -fs.c#L107

Last edited by loqs (2021-10-28 19:59:23)

Offline

#7 2021-10-28 20:32:49

cloverskull
Member
Registered: 2018-09-30
Posts: 277

Re: Does /etc/fstab cause root partition to be re-mounted?

Ah, so maybe much of this is a fool's errand. Perhaps the best bet for me would be to mount it ro with my kernel command line and then let fstab remount it rw. Alas...

This is all pretty interesting nevertheless.

Edit - I have gone ahead and changed my kernel boot parameter from rw to ro and confirmed that systemd does the fsck'ing based on what's in /etc/fstab, which while in practice doesn't make anything feel particularly different, it does seem to be a bit cleaner. Oh well.

I've also removed fsck (and keyboard, just for fun) from mkinitcpio.conf and all is well.

Last edited by cloverskull (2021-10-28 21:26:59)

Offline

Board footer

Powered by FluxBB