propellor-4.0.1: property-based host configuration management in haskell

Safe HaskellNone
LanguageHaskell98

Propellor.Property.DiskImage

Contents

Description

Disk image generation.

This module is designed to be imported unqualified.

Synopsis

Partition specification

Properties

imageBuilt :: DiskImage -> (FilePath -> Chroot) -> TableType -> Finalization -> [PartSpec] -> RevertableProperty (HasInfo + DebianLike) Linux Source #

Creates a bootable disk image.

First the specified Chroot is set up, and its properties are satisfied.

Then, the disk image is set up, and the chroot is copied into the appropriate partition(s) of it.

Note that the disk image file is reused if it already exists, to avoid expensive IO to generate a new one. And, it's updated in-place, so its contents are undefined during the build process.

Note that the noServices property is automatically added to the chroot while the disk image is being built, which should prevent any daemons that are included from being started on the system that is building the disk image.

Example use:

 import Propellor.Property.DiskImage
 import Propellor.Property.Chroot
 
 foo = host "foo.example.com" $ props
 	& imageBuilt "/srv/diskimages/disk.img" mychroot
		MSDOS (grubBooted PC)
		[ partition EXT2 `mountedAt` "/boot"
			`setFlag` BootFlag
		, partition EXT4 `mountedAt` "/"
			`addFreeSpace` MegaBytes 100
			`mountOpt` errorReadonly
		, swapPartition (MegaBytes 256)
		]
  where
	mychroot d = debootstrapped mempty d $ props
		& osDebian Unstable X86_64
		& Apt.installed ["linux-image-amd64"]
		& User.hasPassword (User "root")
		& User.accountFor (User "demo")
 		& User.hasPassword (User "demo")
		& User.hasDesktopGroups (User "demo")
 		& ...

This can also be used with hostChroot to build a disk image that has all the properties of a Host. For example:

 foo :: Host
 foo = host "foo.example.com" $ props
	& imageBuilt "/srv/diskimages/bar-disk.img"
		(hostChroot bar (Debootstrapped mempty))
		MSDOS (grubBooted PC)
		[ partition EXT2 `mountedAt` "/boot"
			`setFlag` BootFlag
		, partition EXT4 `mountedAt` "/"
			`addFreeSpace` MegaBytes 5000
		, swapPartition (MegaBytes 256)
		]

 bar :: Host
 bar = host "bar.example.com" $ props
	& osDebian Unstable X86_64
	& Apt.installed ["linux-image-amd64"]
	& hasPassword (User "root")

imageRebuilt :: DiskImage -> (FilePath -> Chroot) -> TableType -> Finalization -> [PartSpec] -> RevertableProperty (HasInfo + DebianLike) Linux Source #

Like built, but the chroot is deleted and rebuilt from scratch each time. This is more expensive, but useful to ensure reproducible results when the properties of the chroot have been changed.

imageBuiltFrom :: DiskImage -> FilePath -> TableType -> Finalization -> [PartSpec] -> RevertableProperty (HasInfo + DebianLike) UnixLike Source #

Builds a disk image from the contents of a chroot.

imageExists :: FilePath -> ByteSize -> Property Linux Source #

Ensures that a disk image file of the specified size exists.

If the file doesn't exist, or is too small, creates a new one, full of 0's.

If the file is too large, truncates it down to the specified size.

Finalization

type Finalization = (Property Linux, FilePath -> [LoopDev] -> Property Linux) Source #

A pair of properties. The first property is satisfied within the chroot, and is typically used to download the boot loader.

The second property is run after the disk image is created, with its populated partition tree mounted in the provided location from the provided loop devices. This will typically take care of installing the boot loader to the image.

It's ok if the second property leaves additional things mounted in the partition tree.

grubBooted :: BIOS -> Finalization Source #

Makes grub be the boot loader of the disk image.

data BIOS Source #

Types of machines that grub can boot.

Constructors

PC 
EFI64 
EFI32 
Coreboot 
Xen