Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fsck to dracut modules #1352

Merged
merged 10 commits into from
May 25, 2022
Merged

Add fsck to dracut modules #1352

merged 10 commits into from
May 25, 2022

Conversation

mudler
Copy link
Contributor

@mudler mudler commented May 20, 2022

Also sets up fsck.repair=yes and fsck.mode=force by default.
Derivatives can opt-out by providing their own bootargs.cfg

Fixes: #1323

Signed-off-by: Ettore Di Giacinto edigiacinto@suse.com

@@ -29,7 +29,7 @@ install() {
# Include utilities required for cos-setup services,
# probably a devoted cos-setup dracut module makes sense
inst_multiple -o \
partprobe sync udevadm lsblk sgdisk parted mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.vfat mkfs.fat mkfs.xfs blkid e2fsck resize2fs mount xfs_growfs umount
/usr/lib/systemd/systemd-fsck partprobe sync udevadm lsblk sgdisk parted mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.vfat mkfs.fat mkfs.xfs blkid e2fsck resize2fs mount xfs_growfs umount
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be already included - BUT - I feel more safe being explicit here. I'm not sure if there is any reason to NOT do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any reason not to do it. However this is part of the 00systemd module here https://github.com/dracutdevs/dracut/blob/1befc6416743a527824f0f2cc25471e86a6f8a79/modules.d/00systemd/module-setup.sh#L33-L41 so from a dracut perspective I guess the proper way of enforcing it would be to require systemd module in depends function. I doubt we explicitly require systemd module anywhere, assuming it is already there, which could not be the case.

So, I'd suggest adding systemd in depends, then keep this systemd-fsckinclusion here is good to explicitly tell we make use of systemd-fsck. I am wondering if shouldn't we use the ${systemdutildir} variable instead of the absolute path, just incase there are divergences on distros or the installation path of systemd evolves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks for the pointers!

@mudler
Copy link
Contributor Author

mudler commented May 21, 2022

mmm seems the tpm.mount in tumbleweed is in /usr/lib/systemd/system/tmp.mount as opposed to leap where is in /usr/share/systemd/tmp.mount

exit 0
else
umount "${cos_state}"
fi
done
}

function dofsCheck {
# Iterate over current partitions
Copy link
Contributor Author

@mudler mudler May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidcassany here while testing I corrupted COS_PERSISTENT in a way that no labels were properly detected anymore, but by running efsck on the disk id manually I could restore them just fine. When no labels are identified, it just skips all our loops, as we loop over labels

Since this could happen, I'm back at scanning all the partitions found. I'm not sure if this is maybe too invasive on some front and maybe better to make it opt-in - but on the other hand I don't see why someone would disable a fscheck integrity utility running on boot. I guess, in that case fsck.mode=skip could be passed, so I didn't felt to add any option to instrument it even more.

@mudler mudler force-pushed the fsck branch 2 times, most recently from ee3d14c to 1399503 Compare May 24, 2022 12:41
@mudler
Copy link
Contributor Author

mudler commented May 24, 2022

who did forgot to bump initrd? me!

@mudler
Copy link
Contributor Author

mudler commented May 24, 2022

ok, tested locally and seems to work just fine, I've enabled it now by default on the default bootargs.cfg that we ship. Will try now to add a test for it 🤞

@mudler
Copy link
Contributor Author

mudler commented May 24, 2022

Just waiting for tests to pass, but should be good for review as I've checked locally and works

@mudler mudler marked this pull request as ready for review May 24, 2022 14:21
@mudler mudler requested review from davidcassany, Itxaka and mjura May 24, 2022 14:21
@mudler
Copy link
Contributor Author

mudler commented May 25, 2022

oh my, tests went green

mudler added 6 commits May 25, 2022 09:52
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Derivatives can opt-out from it by specifying a custom bootargs.cfg

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
- |
/bin/bash -c " \
if [ -e /usr/share/systemd/tmp.mount ]; then \
cp /usr/share/systemd/tmp.mount /etc/systemd/system; \
Copy link
Contributor

@Itxaka Itxaka May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something to do with the underlying distro change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be, note that TW alreay has this mountpoint by default, probably SLE for rancher too. The old logic was valid when opensuse meant leap, if we include TW, this logic is safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup exactly, this happens to be in two different places - tw and leap have it differently

@davidcassany
Copy link
Contributor

mmm seems the tpm.mount in tumbleweed is in /usr/lib/systemd/system/tmp.mount as opposed to leap where is in /usr/share/systemd/tmp.mount

Yes this is just because Leap has not done the switch to tmpfs mount in /tmp by default yet. This is something we should check for teal now that I am thinking about it, whast is SLE for Rancher using for /tmp by default?

Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, nice 👍

Just a couple of nits regarding the module dependencies and systemd-fsck absolute path usage.

@@ -2,4 +2,4 @@ hostonly_cmdline="no"
hostonly="no"
compress="xz"
omit_dracutmodules+=" multipath "
add_dracutmodules+=" livenet dmsquash-live "
add_dracutmodules+=" fs-lib livenet dmsquash-live "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm I am not so sure about it. If this is a dependency of systemd-fsck I doubt it should be here. Instead better add it in depends() in packages/immutable-rootfs/30cos-immutable-rootfs/module-setup.sh, so each installation of the immutable-rootfs module will also pull and include this dracut module.


# FSCHECK if cos_root_perm == "ro" on both
if [ "$cos_root_perm" == "ro" ]; then
/usr/lib/systemd/systemd-fsck "/dev/disk/by-label/${label}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This absolute path frightens me... I am not sure if we have the ${systemdutilsdir} variable here, I doubt it though. Probably we could install a symlink under /sbin in module_setup.sh and just use systemd-fsck here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, it frightens me as well, but the fact that systemd-fsck is not having a binary in /sbin etc hold me off from doing any special setup. I just wonder why is not installed as a normal binary to begin with ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@mudler mudler May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmh but might not be just available when calling it inside scripts. I just wonder how dracut handles it as its used already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed now!

depends() {
echo rootfs-block dm
echo rootfs-block dm fs-lib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fs-lib is here, then it should not be needed in dracut.conf file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch good catch, I think it slipped in while I was testing

- |
/bin/bash -c " \
if [ -e /usr/share/systemd/tmp.mount ]; then \
cp /usr/share/systemd/tmp.mount /etc/systemd/system; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be, note that TW alreay has this mountpoint by default, probably SLE for rancher too. The old logic was valid when opensuse meant leap, if we include TW, this logic is safer.

@@ -2,7 +2,7 @@ set kernel=/boot/vmlinuz
if [ -n "$recoverylabel" ]; then
set kernelcmd="console=tty1 console=ttyS0 root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5 rd.neednet=1 rd.cos.oemlabel=@OEM_LABEL@"
else
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1 rd.neednet=1 rd.cos.oemlabel=@OEM_LABEL@"
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1 rd.neednet=1 rd.cos.oemlabel=@OEM_LABEL@ fsck.mode=force fsck.repair=yes"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any fsck.repair definition, hence I guess this is something that systemd-fsck parses, right? If this something custom from our side I'd suggest defining it with the rd.cos... prefix, I think it is not the case though, just to double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, those are read by systemd-fsck directly, so we don't need to do any special handling ourselves 🥳

mudler added 3 commits May 25, 2022 11:46
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
@mudler mudler enabled auto-merge (squash) May 25, 2022 10:10
Copy link
Contributor

@mjura mjura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@mudler mudler merged commit 363b822 into master May 25, 2022
@mudler mudler deleted the fsck branch May 25, 2022 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs integrity check on boot
4 participants