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

Safe Haskell | None
Language | Haskell98

Propellor.Property.Parted

Contents

- Types
- Properties
- Partition table sizing

Synopsis

- data TableType
  - = MSDOS
  - | GPT
  - | AIX
  - | AMIGA
  - | BSD
  - | DVH
  - | LOOP
  - | MAC
  - | PC98
  - | SUN
- data PartTable = PartTable TableType Alignment [Partition]
- partTableSize :: PartTable -> ByteSize
- data Partition = Partition {
  - partType :: PartType
  - partSize :: PartSize
  - partFs :: Maybe Fs
  - partMkFsOpts :: MkfsOpts
  - partFlags :: [(PartFlag, Bool)]
  - partName :: Maybe String
  }
- mkPartition :: Maybe Fs -> PartSize -> Partition
- data Fs
  - = EXT2
  - | EXT3
  - | EXT4
  - | BTRFS
  - | REISERFS
  - | XFS
  - | FAT
  - | VFAT
  - | NTFS
  - | LinuxSwap
- data PartSize
  - = MegaBytes Integer
  - | Bytes Integer
- type ByteSize = Integer
- toPartSize :: ByteSize -> PartSize
- fromPartSize :: PartSize -> ByteSize
- reducePartSize :: PartSize -> PartSize -> PartSize
- newtype Alignment = Alignment ByteSize
- safeAlignment :: Alignment
- type MkfsOpts = [String]
- data PartType
  - = Primary
  - | Logical
  - | Extended
- data PartFlag
  - = BootFlag
  - | RootFlag
  - | SwapFlag
  - | HiddenFlag
  - | RaidFlag
  - | LvmFlag
  - | LbaFlag
  - | LegacyBootFlag
  - | IrstFlag
  - | EspFlag
  - | PaloFlag
  - | BiosGrubFlag
- partitioned :: Eep -> FilePath -> PartTable -> Property DebianLike
- parted :: Eep -> FilePath -> [String] -> Property (DebianLike + ArchLinux)
- data Eep = YesReallyDeleteDiskContents
- installed :: Property (DebianLike + ArchLinux)
- calcPartTable :: DiskSize -> TableType -> Alignment -> [PartSpec DiskPart] -> PartTable
- newtype DiskSize = DiskSize ByteSize
- data DiskPart
- data DiskSpaceUse
  - = Percent Int
  - | RemainingSpace
- useDiskSpace :: PartSpec DiskPart -> DiskSpaceUse -> PartSpec DiskPart
- defSz :: PartSize
- fudgeSz :: PartSize -> PartSize

# Types

data TableType Source #

Types of partition tables supported by parted.

Constructors

MSDOS |
GPT |
AIX |
AMIGA |
BSD |
DVH |
LOOP |
MAC |
PC98 |
SUN |

Instances

Show TableType Source # |
Methods showsPrec :: Int -> TableType -> ShowS show :: TableType -> String showList :: [TableType] -> ShowS
PartedVal TableType Source # |
Methods pval :: TableType -> String Source #

data PartTable Source #

A disk's partition table.

Constructors

PartTable TableType Alignment [Partition] |

Instances

Show PartTable Source # |
Methods showsPrec :: Int -> PartTable -> ShowS show :: PartTable -> String showList :: [PartTable] -> ShowS
Monoid PartTable Source # |
Methods mempty :: PartTable mappend :: PartTable -> PartTable -> PartTable mconcat :: [PartTable] -> PartTable

partTableSize :: PartTable -> ByteSize Source #

Gets the total size of the disk specified by the partition table.

data Partition Source #

A partition on the disk.

Constructors

Partition |

Fields

- partType :: PartType
- partSize :: PartSize
- partFs :: Maybe Fs
- partMkFsOpts :: MkfsOpts
- partFlags :: [(PartFlag, Bool)]

  flags can be set or unset (parted may set some flags by default)

- partName :: Maybe String

  optional name for partition (only works for GPT, PC98, MAC)

Instances

Show Partition Source # |
Methods showsPrec :: Int -> Partition -> ShowS show :: Partition -> String showList :: [Partition] -> ShowS

mkPartition :: Maybe Fs -> PartSize -> Partition Source #

Makes a Partition with defaults for non-important values.

data Fs Source #

Filesystems etc that can be used for a partition.

Constructors

EXT2 |
EXT3 |
EXT4 |
BTRFS |
REISERFS |
XFS |
FAT |
VFAT |
NTFS |
LinuxSwap |

Instances

Eq Fs Source # |
Methods (==) :: Fs -> Fs -> Bool (/=) :: Fs -> Fs -> Bool
Show Fs Source # |
Methods showsPrec :: Int -> Fs -> ShowS show :: Fs -> String showList :: [Fs] -> ShowS
PartedVal Fs Source # |
Methods pval :: Fs -> String Source #

data PartSize Source #

Size of a partition.

Constructors

MegaBytes Integer |
Bytes Integer |

Instances

Show PartSize Source # |
Methods showsPrec :: Int -> PartSize -> ShowS show :: PartSize -> String showList :: [PartSize] -> ShowS
Monoid PartSize Source # |
Methods mempty :: PartSize mappend :: PartSize -> PartSize -> PartSize mconcat :: [PartSize] -> PartSize

type ByteSize = Integer Source #

toPartSize :: ByteSize -> PartSize Source #

Rounds up to the nearest MegaByte.

fromPartSize :: PartSize -> ByteSize Source #

reducePartSize :: PartSize -> PartSize -> PartSize Source #

newtype Alignment Source #

Partitions need to be aligned for optimal efficiency. The alignment is a number of bytes.

Constructors

Alignment ByteSize |

Instances

Eq Alignment Source # |
Methods (==) :: Alignment -> Alignment -> Bool (/=) :: Alignment -> Alignment -> Bool
Ord Alignment Source # |
Methods compare :: Alignment -> Alignment -> Ordering (<) :: Alignment -> Alignment -> Bool (<=) :: Alignment -> Alignment -> Bool (>) :: Alignment -> Alignment -> Bool (>=) :: Alignment -> Alignment -> Bool max :: Alignment -> Alignment -> Alignment min :: Alignment -> Alignment -> Alignment
Show Alignment Source # |
Methods showsPrec :: Int -> Alignment -> ShowS show :: Alignment -> String showList :: [Alignment] -> ShowS

safeAlignment :: Alignment Source #

4MiB alignment is optimal for inexpensive flash drives and is a good safe default for all drives.

type MkfsOpts = [String] Source #

Options passed to a mkfs.* command when making a filesystem.

Eg, ["-m0"]

data PartType Source #

Type of a partition.

Constructors

Primary |
Logical |
Extended |

Instances

Show PartType Source # |
Methods showsPrec :: Int -> PartType -> ShowS show :: PartType -> String showList :: [PartType] -> ShowS
PartedVal PartType Source # |
Methods pval :: PartType -> String Source #

data PartFlag Source #

Flags that can be set on a partition.

Constructors

BootFlag |
RootFlag |
SwapFlag |
HiddenFlag |
RaidFlag |
LvmFlag |
LbaFlag |
LegacyBootFlag |
IrstFlag |
EspFlag |
PaloFlag |
BiosGrubFlag |

Instances

Show PartFlag Source # |
Methods showsPrec :: Int -> PartFlag -> ShowS show :: PartFlag -> String showList :: [PartFlag] -> ShowS
PartedVal PartFlag Source # |
Methods pval :: PartFlag -> String Source #

# Properties

partitioned :: Eep -> FilePath -> PartTable -> Property DebianLike Source #

Partitions a disk using parted, and formats the partitions.

The FilePath can be a block device (eg, /dev/sda), or a disk image file.

This deletes any existing partitions in the disk! Use with EXTREME caution!

parted :: Eep -> FilePath -> [String] -> Property (DebianLike + ArchLinux) Source #

Runs parted on a disk with the specified parameters.

Parted is run in script mode, so it will never prompt for input.

data Eep Source #

Constructors

YesReallyDeleteDiskContents |

installed :: Property (DebianLike + ArchLinux) Source #

Gets parted installed.

# Partition table sizing

calcPartTable :: DiskSize -> TableType -> Alignment -> [PartSpec DiskPart] -> PartTable Source #

Calculate a partition table, for a given size of disk.

For example:

    	calcPartTable (DiskSize (1024 * 1024 * 1024 * 100)) MSDOS safeAlignment
     		[ partition EXT2 `mountedAt` "/boot"
     			`setSize` MegaBytes 256
     			`setFlag` BootFlag
    		, partition EXT4 `mountedAt` "/"
    			`useDiskSpace` RemainingSpace
    		]

newtype DiskSize Source #

Size of a disk, in bytes.

Constructors

DiskSize ByteSize |

Instances

Show DiskSize Source # |
Methods showsPrec :: Int -> DiskSize -> ShowS show :: DiskSize -> String showList :: [DiskSize] -> ShowS

data DiskPart Source #

Instances

Monoid DiskPart Source # |
Methods mempty :: DiskPart mappend :: DiskPart -> DiskPart -> DiskPart mconcat :: [DiskPart] -> DiskPart

data DiskSpaceUse Source #

Constructors

Percent Int |
RemainingSpace |

useDiskSpace :: PartSpec DiskPart -> DiskSpaceUse -> PartSpec DiskPart Source #

Make a partition use some percentage of the size of the disk (less all fixed size partitions), or the remaining space in the disk.

defSz :: PartSize Source #

Default partition size when not otherwize specified is 128 MegaBytes.

fudgeSz :: PartSize -> PartSize Source #

When a partition is sized to fit the files that live in it, this fudge factor is added to the size of the files. This is necessary since filesystems have some space overhead.

Add 2% for filesystem overhead. Rationalle for picking 2%: A filesystem with 1% overhead might just sneak by as acceptable. Double that just in case. Add an additional 3 mb to deal with non-scaling overhead of filesystems (eg, superblocks). Add an additional 200 mb for temp files, journals, etc.