From e248d2a99aff5bef7611ac0596b0aa2d1eda6629 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 27 Jun 2021 13:13:10 -0700 Subject: cmd/fscrypt: fix detection of GRUB installation Fix the GRUB detection logic to take into account that MOUNTPOINT/boot/grub might not be on the same filesystem as MOUNTPOINT, due to MOUNTPOINT/boot being another mountpoint. The warning is only appropriate when GRUB is installed on the same filesystem that encryption is going to be enabled on. --- cmd/fscrypt/errors.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/fscrypt/errors.go b/cmd/fscrypt/errors.go index 10d744a..bcf5b59 100644 --- a/cmd/fscrypt/errors.go +++ b/cmd/fscrypt/errors.go @@ -106,6 +106,12 @@ func getFullName(c *cli.Context) string { return c.App.HelpName } +func isGrubInstalledOnFilesystem(mnt *filesystem.Mount) bool { + dir := filepath.Join(mnt.Path, "boot/grub") + grubDirMount, _ := filesystem.FindMount(dir) + return grubDirMount == mnt +} + func suggestEnablingEncryption(mnt *filesystem.Mount) string { kconfig := "CONFIG_FS_ENCRYPTION=y" switch mnt.FilesystemType { @@ -136,7 +142,7 @@ func suggestEnablingEncryption(mnt *filesystem.Mount) string { > sudo tune2fs -O encrypt %q `, mnt.Device) - if _, err := os.Stat(filepath.Join(mnt.Path, "boot/grub")); err == nil { + if isGrubInstalledOnFilesystem(mnt) { s += ` WARNING: you seem to have GRUB installed on this filesystem. Before doing the above, make sure you are -- cgit v1.2.3