2014-07-07 06:58:34 +00:00
|
|
|
module Propellor.Property.Grub where
|
|
|
|
|
|
|
|
import Propellor
|
|
|
|
import qualified Propellor.Property.File as File
|
|
|
|
import qualified Propellor.Property.Apt as Apt
|
|
|
|
|
2015-01-19 18:26:18 +00:00
|
|
|
-- | Eg, \"hd0,0\" or \"xen/xvda1\"
|
2014-07-07 06:58:34 +00:00
|
|
|
type GrubDevice = String
|
|
|
|
|
2015-01-19 18:26:18 +00:00
|
|
|
-- | Eg, \"\/dev/sda\"
|
2014-12-05 20:22:11 +00:00
|
|
|
type OSDevice = String
|
|
|
|
|
2014-07-07 07:16:18 +00:00
|
|
|
type TimeoutSecs = Int
|
|
|
|
|
2014-12-05 20:22:11 +00:00
|
|
|
-- | Types of machines that grub can boot.
|
|
|
|
data BIOS = PC | EFI64 | EFI32 | Coreboot | Xen
|
|
|
|
|
|
|
|
-- | Installs the grub package. This does not make grub be used as the
|
|
|
|
-- bootloader.
|
|
|
|
--
|
|
|
|
-- This includes running update-grub, so that the grub boot menu is
|
|
|
|
-- created. It will be automatically updated when kernel packages are
|
|
|
|
-- installed.
|
2015-01-25 02:38:10 +00:00
|
|
|
installed :: BIOS -> Property NoInfo
|
2014-12-05 20:22:11 +00:00
|
|
|
installed bios =
|
|
|
|
Apt.installed [pkg] `describe` "grub package installed"
|
|
|
|
`before`
|
|
|
|
cmdProperty "update-grub" []
|
|
|
|
where
|
|
|
|
pkg = case bios of
|
|
|
|
PC -> "grub-pc"
|
|
|
|
EFI64 -> "grub-efi-amd64"
|
|
|
|
EFI32 -> "grub-efi-ia32"
|
|
|
|
Coreboot -> "grub-coreboot"
|
|
|
|
Xen -> "grub-xen"
|
|
|
|
|
|
|
|
-- | Installs grub onto a device, so the system can boot from that device.
|
|
|
|
--
|
|
|
|
-- You may want to install grub to multiple devices; eg for a system
|
|
|
|
-- that uses software RAID.
|
|
|
|
--
|
|
|
|
-- Note that this property does not check if grub is already installed
|
|
|
|
-- on the device; it always does the work to reinstall it. It's a good idea
|
|
|
|
-- to arrange for this property to only run once, by eg making it be run
|
|
|
|
-- onChange after OS.cleanInstallOnce.
|
2015-01-25 02:38:10 +00:00
|
|
|
boots :: OSDevice -> Property NoInfo
|
2014-12-05 20:22:11 +00:00
|
|
|
boots dev = cmdProperty "grub-install" [dev]
|
|
|
|
`describe` ("grub boots " ++ dev)
|
|
|
|
|
2014-07-07 06:58:34 +00:00
|
|
|
-- | Use PV-grub chaining to boot
|
|
|
|
--
|
|
|
|
-- Useful when the VPS's pv-grub is too old to boot a modern kernel image.
|
|
|
|
--
|
2014-12-09 18:22:37 +00:00
|
|
|
-- <http://notes.pault.ag/linode-pv-grub-chainning/>
|
2014-07-07 06:58:34 +00:00
|
|
|
--
|
|
|
|
-- The rootdev should be in the form "hd0", while the bootdev is in the form
|
|
|
|
-- "xen/xvda".
|
2015-01-25 02:38:10 +00:00
|
|
|
chainPVGrub :: GrubDevice -> GrubDevice -> TimeoutSecs -> Property NoInfo
|
2014-07-07 07:16:18 +00:00
|
|
|
chainPVGrub rootdev bootdev timeout = combineProperties desc
|
2014-07-07 07:08:12 +00:00
|
|
|
[ File.dirExists "/boot/grub"
|
|
|
|
, "/boot/grub/menu.lst" `File.hasContent`
|
2014-07-07 06:58:34 +00:00
|
|
|
[ "default 1"
|
2014-07-07 07:16:18 +00:00
|
|
|
, "timeout " ++ show timeout
|
2014-07-07 06:58:34 +00:00
|
|
|
, ""
|
|
|
|
, "title grub-xen shim"
|
|
|
|
, "root (" ++ rootdev ++ ")"
|
|
|
|
, "kernel /boot/xen-shim"
|
|
|
|
, "boot"
|
|
|
|
]
|
|
|
|
, "/boot/load.cf" `File.hasContent`
|
|
|
|
[ "configfile (" ++ bootdev ++ ")/boot/grub/grub.cfg" ]
|
2014-12-05 20:22:11 +00:00
|
|
|
, installed Xen
|
|
|
|
, flagFile (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"]) "/boot/xen-shim"
|
2014-07-07 06:58:34 +00:00
|
|
|
`describe` "/boot-xen-shim"
|
|
|
|
]
|
|
|
|
where
|
|
|
|
desc = "chain PV-grub"
|