summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog2
-rw-r--r--src/Propellor/Property/DiskImage.hs30
-rw-r--r--src/Propellor/Property/Grub.hs44
3 files changed, 48 insertions, 28 deletions
diff --git a/debian/changelog b/debian/changelog
index e5eacd30..f333b82a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ propellor (4.6.2) UNRELEASED; urgency=medium
non-symlinks in /etc/systemd/system/multi-user.target.wants,
which was used to configure systemd-nspawn parameters. Instead,
use a service.d/local.conf file to configure that.
+ * Grub: Added bootsMounted property, a generalization of
+ DiskImage.grubBooted
-- Joey Hess <id@joeyh.name> Thu, 27 Jul 2017 16:34:37 -0400
diff --git a/src/Propellor/Property/DiskImage.hs b/src/Propellor/Property/DiskImage.hs
index c68a99e6..f64f685a 100644
--- a/src/Propellor/Property/DiskImage.hs
+++ b/src/Propellor/Property/DiskImage.hs
@@ -363,35 +363,9 @@ unbootable msg = \_ _ -> property desc $ do
-- This does not install the grub package. You will need to add
-- the `Grub.installed` property to the chroot.
grubBooted :: Finalization
-grubBooted mnt loopdevs = combineProperties "disk image boots using grub" $ props
- -- bind mount host /dev so grub can access the loop devices
- & bindMount "/dev" (inmnt "/dev")
- & mounted "proc" "proc" (inmnt "/proc") mempty
- & mounted "sysfs" "sys" (inmnt "/sys") mempty
- -- update the initramfs so it gets the uuid of the root partition
- & inchroot "update-initramfs" ["-u"]
- `assume` MadeChange
- -- work around for http://bugs.debian.org/802717
- & check haveosprober (inchroot "chmod" ["-x", osprober])
- & inchroot "update-grub" []
- `assume` MadeChange
- & check haveosprober (inchroot "chmod" ["+x", osprober])
- & inchroot "grub-install" [wholediskloopdev]
- `assume` MadeChange
- -- sync all buffered changes out to the disk image
- -- may not be necessary, but seemed needed sometimes
- -- when using the disk image right away.
- & cmdProperty "sync" []
- `assume` NoChange
+grubBooted mnt loopdevs = Grub.bootsMounted mnt wholediskloopdev
+ `describe` "disk image boots using grub"
where
- -- cannot use </> since the filepath is absolute
- inmnt f = mnt ++ f
-
- inchroot cmd ps = cmdProperty "chroot" ([mnt, cmd] ++ ps)
-
- haveosprober = doesFileExist (inmnt osprober)
- osprober = "/etc/grub.d/30_os-prober"
-
-- It doesn't matter which loopdev we use; all
-- come from the same disk image, and it's the loop dev
-- for the whole disk image we seek.
diff --git a/src/Propellor/Property/Grub.hs b/src/Propellor/Property/Grub.hs
index 4bad7b2b..739a63e9 100644
--- a/src/Propellor/Property/Grub.hs
+++ b/src/Propellor/Property/Grub.hs
@@ -3,6 +3,7 @@ module Propellor.Property.Grub where
import Propellor.Base
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
+import Propellor.Property.Mount
import Propellor.Property.Chroot (inChroot)
import Propellor.Types.Info
import Propellor.Types.Bootloader
@@ -89,3 +90,46 @@ chainPVGrub rootdev bootdev timeout = combineProperties desc $ props
xenshim = scriptProperty ["grub-mkimage --prefix '(" ++ bootdev ++ ")/boot/grub' -c /boot/load.cf -O x86_64-xen /usr/lib/grub/x86_64-xen/*.mod > /boot/xen-shim"]
`assume` MadeChange
`describe` "/boot-xen-shim"
+
+-- | This is a version of `boots` that makes grub boot the system mounted
+-- at a particular directory. The OSDevice should be the underlying disk
+-- device that grub will be installed to (generally a whole disk,
+-- not a partition).
+bootsMounted :: FilePath -> OSDevice -> Property Linux
+bootsMounted mnt wholediskdev = combineProperties desc $ props
+ -- bind mount host /dev so grub can access the loop devices
+ & bindMount "/dev" (inmnt "/dev")
+ & mounted "proc" "proc" (inmnt "/proc") mempty
+ & mounted "sysfs" "sys" (inmnt "/sys") mempty
+ -- update the initramfs so it gets the uuid of the root partition
+ & inchroot "update-initramfs" ["-u"]
+ `assume` MadeChange
+ -- work around for http://bugs.debian.org/802717
+ & check haveosprober (inchroot "chmod" ["-x", osprober])
+ & inchroot "update-grub" []
+ `assume` MadeChange
+ & check haveosprober (inchroot "chmod" ["+x", osprober])
+ & inchroot "grub-install" [wholediskdev]
+ `assume` MadeChange
+ & cleanupmounts
+ -- sync all buffered changes out to the disk in case it's
+ -- used right away
+ & cmdProperty "sync" []
+ `assume` NoChange
+ where
+ desc = "grub boots " ++ wholediskdev
+
+ -- cannot use </> since the filepath is absolute
+ inmnt f = mnt ++ f
+
+ inchroot cmd ps = cmdProperty "chroot" ([mnt, cmd] ++ ps)
+
+ haveosprober = doesFileExist (inmnt osprober)
+ osprober = "/etc/grub.d/30_os-prober"
+
+ cleanupmounts :: Property Linux
+ cleanupmounts = property desc $ liftIO $ do
+ umountLazy (inmnt "/sys")
+ umountLazy (inmnt "/proc")
+ umountLazy (inmnt "/dev")
+ return NoChange