Safe Haskell | None |
---|---|
Language | Haskell98 |
Disk image generation.
This module is designed to be imported unqualified.
TODO run final
TODO avoid starting services while populating chroot and running final
- type DiskImage = FilePath
- imageBuilt :: DiskImage -> (FilePath -> Chroot) -> TableType -> [PartSpec] -> Finalization -> RevertableProperty
- imageRebuilt :: DiskImage -> (FilePath -> Chroot) -> TableType -> [PartSpec] -> Finalization -> RevertableProperty
- imageBuiltFrom :: DiskImage -> FilePath -> TableType -> [PartSpec] -> Property NoInfo -> RevertableProperty
- imageExists :: FilePath -> ByteSize -> Property NoInfo
- data Partition
- newtype PartSize = MegaBytes Integer
- data Fs
- type PartSpec = (MountPoint, PartSize -> Partition)
- type MountPoint = Maybe FilePath
- swapPartition :: PartSize -> PartSpec
- partition :: Fs -> PartSpec
- mountedAt :: PartSpec -> FilePath -> PartSpec
- addFreeSpace :: PartSpec -> PartSize -> PartSpec
- setSize :: PartSpec -> PartSize -> PartSpec
- data PartFlag
- setFlag :: PartSpec -> PartFlag -> PartSpec
- data TableType
- extended :: PartSpec -> PartSpec
- adjustp :: PartSpec -> (Partition -> Partition) -> PartSpec
- type Finalization = (Property NoInfo, Property NoInfo)
- grubBooted :: BIOS -> Finalization
- data BIOS
- noFinalization :: Finalization
Properties
imageBuilt :: DiskImage -> (FilePath -> Chroot) -> TableType -> [PartSpec] -> Finalization -> RevertableProperty 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.
Example use:
import Propellor.Property.DiskImage
let chroot d = Chroot.debootstrapped (System (Debian Unstable) "amd64") mempty d & Apt.installed ["linux-image-amd64"] & ... in imageBuilt "/srv/images/foo.img" chroot MSDOS [ partition EXT2 `mountedAt` "/boot" `setFlag` BootFlag , partition EXT4 `mountedAt` "/" `addFreeSpace` MegaBytes 100 , swapPartition (MegaBytes 256) ] (grubBooted PC)
imageRebuilt :: DiskImage -> (FilePath -> Chroot) -> TableType -> [PartSpec] -> Finalization -> RevertableProperty 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 -> [PartSpec] -> Property NoInfo -> RevertableProperty Source
Builds a disk image from the contents of a chroot.
The passed property is run inside the mounted disk image.
imageExists :: FilePath -> ByteSize -> Property NoInfo 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.
Partitioning
All partition sizing is done in megabytes, so that parted can automatically lay out the partitions.
Note that these are SI megabytes, not mebibytes.
Filesystems etc that can be used for a partition.
type PartSpec = (MountPoint, PartSize -> Partition) Source
Specifies a mount point and a constructor for a Partition.
The size that is eventually provided is the amount of space needed to hold the files that appear in the directory where the partition is to be mounted. Plus a fudge factor, since filesystems have some space overhead.
(Partitions that are not to be mounted (ie, LinuxSwap), or that have no corresponding directory in the chroot will have 128 MegaBytes provided as a default size.)
type MountPoint = Maybe FilePath Source
Where a partition is mounted. Use Nothing for eg, LinuxSwap.
swapPartition :: PartSize -> PartSpec Source
Specifies a swap partition of a given size.
partition :: Fs -> PartSpec Source
Specifies a partition with a given filesystem.
The partition is not mounted anywhere by default; use the combinators below to configure it.
addFreeSpace :: PartSpec -> PartSize -> PartSpec Source
Adds additional free space to the partition.
setSize :: PartSpec -> PartSize -> PartSpec Source
Forced a partition to be a specific size, instead of scaling to the size needed for the files in the chroot.
Flags that can be set on a partition.
Types of partition tables supported by parted.
Finalization
type Finalization = (Property NoInfo, Property NoInfo) 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 satisfied chrooted into the resulting disk image, and will typically take care of installing the boot loader to the disk image.
grubBooted :: BIOS -> Finalization Source
Makes grub be the boot loader of the disk image. TODO not implemented