propellor-5.8.0: 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

class DiskImage d where Source #

Type class of disk image formats.

Methods

rawDiskImage :: d -> RawDiskImage Source #

Get the location where the raw disk image should be stored.

describeDiskImage :: d -> String Source #

Describe the disk image (for display to the user)

buildDiskImage :: d -> RevertableProperty DebianLike Linux Source #

Convert the raw disk image file in the rawDiskImage location into the desired disk image format. For best efficiency, the raw disk imasge file should be left unchanged on disk.

newtype RawDiskImage Source #

A raw disk image, that can be written directly out to a disk.

Constructors

RawDiskImage FilePath 

newtype VirtualBoxPointer Source #

A virtualbox .vmdk file, which contains a pointer to the raw disk image. This can be built very quickly.

imageBuilt :: DiskImage d => d -> (FilePath -> Chroot) -> TableType -> [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.

The partitions default to being sized just large enough to fit the files from the chroot. You can use addFreeSpace to make them a bit larger than that, or setSize to use a fixed size.

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 (RawDiskImage "/srv/diskimages/disk.img") mychroot
		MSDOS
		[ 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"]
		& Grub.installed PC
		& User.hasPassword (User "root")
		& User.accountFor (User "demo")
 		& User.hasPassword (User "demo")
		& User.hasDesktopGroups (User "demo")
 		& ...

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

Like imageBuilt, 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.

imageBuiltFor :: (DiskImage d, ChrootBootstrapper bootstrapper) => Host -> d -> bootstrapper -> RevertableProperty (HasInfo + DebianLike) Linux Source #

Create a bootable disk image for a Host.

This works just like imageBuilt, but partition table is determined by looking at the Host's hasPartitionTableType, hasPartition, and adjustPartition properties.

For example:

 foo :: Host
 foo = host "foo.example.com" $ props
	& imageBuiltFor bar
		(RawDiskImage "/srv/diskimages/bar-disk.img")
		(Debootstrapped mempty)

 bar :: Host
 bar = host "bar.example.com" $ props
	& hasPartiton
		( partition EXT2
		`mountedAt` "/boot"
		`partLocation` Beginning
		`addFreeSpace` MegaBytes 150
		)
	& hasPartiton
		( partition EXT4
		`mountedAt` "/"
		`addFreeSpace` MegaBytes 500
		)
	& osDebian Unstable X86_64
	& Apt.installed ["linux-image-amd64"]
	& Grub.installed PC
	& hasPassword (User "root")

imageRebuiltFor :: (DiskImage d, ChrootBootstrapper bootstrapper) => Host -> d -> bootstrapper -> RevertableProperty (HasInfo + DebianLike) Linux Source #

Like imageBuiltFor, but the chroot is deleted and rebuilt from scratch each time.

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

Builds a disk image from the contents of a chroot.

imageExists :: RawDiskImage -> 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.

data GrubTarget Source #

Platforms that grub can boot.

Constructors

PC 
EFI64 
EFI32 
Coreboot 
Xen 

noBootloader :: Property (HasInfo + UnixLike) Source #

Normally a boot loader is installed on a disk image. However, when the disk image will be booted by eg qemu booting the kernel and initrd, no boot loader is needed, and this property can be used.