Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active September 16, 2022 09:09
Show Gist options
  • Save avoidik/386b593f268f226402eb3d0089b1ba76 to your computer and use it in GitHub Desktop.
Save avoidik/386b593f268f226402eb3d0089b1ba76 to your computer and use it in GitHub Desktop.
Configure Linux kernel to always scan disks

Update initramfs image with required binaries (if fsk for some reason isn't there)

tee /etc/initramfs-tools/hooks/e2fsck.sh <<'EOF' >/dev/null
#!/bin/sh
. /usr/share/initramfs-tools/hook-functions
copy_exec /sbin/e2fsck /sbin
copy_exec /sbin/fsck /sbin
copy_exec /sbin/fsck.ext2 /sbin
copy_exec /sbin/fsck.ext4 /sbin
copy_exec /sbin/logsave /sbin
EOF
sudo chmod +x /etc/initramfs-tools/hooks/e2fsck.sh
sudo update-initramfs -u -k all

Configure grub to always run fsck

sudo nano /etc/default/grub.d/50-cloudimg-settings.cfg

Append fsck.mode=force fsck.repair=yes to GRUB_CMDLINE_LINUX_DEFAULT line as follows

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force fsck.repair=yes"

You could optionally append few other parameters, mitigations=off zswap.enabled=1

Update grub boot image

sudo update-grub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment