Jump to content

PartMan

From Wikitech

This page is about partitioning with preseed and partman.

Background Info

Debian preseed's partman options are an incomprehensible automatic partitioning language.{{fact}} You can now test your new partman recipes in a virtual environment with preseed-test, which is quicker and easier than dealing with real hardware.

Standard recipes / disk layout

Most hosts are installed via standard partman recipes found in modules/install_server/files/autoinstall/partman/ . There are a few categories of standard recipes: software, hardware RAID, plus VMs for which including partman/flat.cfg virtual.cfg in netboot.cfg is sufficient.

When reimaging an host please consider switching to efi boot (the default when running the provision cookbook), going forward only efi standard recipes will be supported. Newer hosts have stopped supporting legacy boot altogether.

The netboot.cfg file is generated by puppet, from configuration located in modules/profile/data/profile/installserver/preseed.yaml. This was done to avoid typos creep through the file.

Software raid

The host has a number N of equal size devices and will be installed with the chosen raid level L (0, 1, 10) plus LVM on top using volume group vg0. The need to be added to preseed.yaml in the following manner for a a group of servers called fooserver1001-fooserver1004:

'fooserver100[1-4]':
  - partman/standard-efi.cfg
  - partman/raidL-Ndev-efi.cfg

A special case is software raid0 for which a common recipe snippet needs to be included:

'barserver*':
  - partman/standard-efi.cfg
  - partman/raid0-efi.cfg
  - partman/raid0-Ndev-efi.cfg

Hardware raid

In this case the host uses on board hardware raid and typically a single block device is presented to the operating system. The host will have LVM on top of the hardware raid, similar to software raid. Intended usage of the recipe is:

'fooserver*':
  - partman/standard-efi.cfg
  - partman/hwraid-1dev.cfg

JBOD

Standard recipes assume partman will take control of all devices on the host. The jbod variant is used when the operating system will live on a subset of all devices. The intended use case is hosts with two sets of storage devices attached: smaller device(s) for the operating system, and larger devices for data. We are interested in locating and managing the former set (OS devices) and we can not hard code device names in recipes because device name assignment is asynchronous. Any data device is assumed to be managed by Puppet and/or software deployed by Puppet (e.g. ceph).

The jbod variant will consider operating system devices any sd* or nvme* device that is smaller than 1TB and partition them accordingly. Assembling a software raid array is not required, for example when the OS device is backed by hardware raid and thus exposed as a single device. The standard LVM layout will be deployed on top of any number of devices and raid arrays.

Usage is the same as any other standard recipe:

'fooserver*'
  - partman/standard-efi.cfg
  - partman/raid1-jbod-efi.cfg  # or hwraid-jbod-efi.cfg for a single OS device backed by hardware raid
All volume groups will be nuked, not only vg0. Partitions and raid arrays on non-OS devices will be left intact.

See also bug T439831 for more context and information on this work.

LVM layout

The standard recipes provide a / logical volume of 80GB, swap 1GB and a /srv taking up to 80% of the remaining space on the standard volume group (vg0). The vg space is not all allocated at installation time to provide some leeway in emergencies and a little bit of headroom in capacity planning. The logical volumes and their filesystems can be expanded online at any time with e.g. lvextend --resizefs. See also documentation on extending LVM.

For cases where less space needs to be pre-allocated (e.g. more LVs will be created by puppet on vg0) then d-i partman-auto-lvm/guided_size string can be overridden in a later custom recipe. Check out for example how custom/prometheus.cfg achieves it.

Non-standard recipes

While a majority of cases are covered by standard recipes, some special cases remain. These are typically storage hosts of some kind and their recipes live in partman/custom/. New hosts/use cases should strive to use the standard recipes if at all possible, if not consider whether a custom recipe can be adapted to your use case.

Help Files

These files are in the Debian packages, and give some explanation

Important note about how partman calculates the final size of the partitions

From https://www.bishnet.net/tim/blog/2015/01/29/understanding-partman-autoexpert_recipe/

I recently created the mw-raid1-lvm partman recipe for new app-servers, ending up with the following config:

# Define physical partitions
d-i	partman-auto/expert_recipe	string	multiraid ::	\
	1000	1000	-1	raid				\
		method{ raid }					\
		$lvmignore{ }					\
		.						\
	10000 71000 600000000 ext4				\
		method{ format }				\
		format{ }					\
		use_filesystem{ }				\
		filesystem{ ext4 }				\
		lv_name{ root }					\
		$defaultignore{ }				\
		$lvmok{ }					\
		mountpoint{ / }					\
		.						\
	10000 30000 200000000 ext4				\
		method{ format }				\
		format{ }					\
		use_filesystem{ }				\
		filesystem{ ext4 }				\
		lv_name{ srv }					\
		$defaultignore{ }				\
		$lvmok{ }					\
		mountpoint{ /srv }				\
		.						\
	10000 27500 200000000 ext4				\
		lv_name{ placeholder }				\
		$defaultignore{ }				\
		$lvmok{ }					\
		.

# Parameters are:
# <raidtype> <devcount> <sparecount> <fstype> <mountpoint> \
#	<devices> <sparedevices>
d-i	partman-auto-raid/recipe	string		\
		1	2	0	lvm	-	\
			/dev/sda1#/dev/sdb1		\
		.

In this case each host offers two 1TB disks, and I wanted to have a single software RAID1 device and LVM Volumes on top of it. The hard part was how to find the right values for min/priority/max in the expert-recipe. After a lot of unsuccessful tests with numbers that I thought to have some sense, I found the link at the beginning of this section that enlightened me.

Let's start with the end result of the above example:

elukey@mw1321:~$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev                         10M     0   10M   0% /dev
tmpfs                        13G  9.1M   13G   1% /run
/dev/dm-0                   563G  7.8G  527G   2% /
tmpfs                        32G     0   32G   0% /dev/shm
tmpfs                       5.0M     0  5.0M   0% /run/lock
tmpfs                        32G     0   32G   0% /sys/fs/cgroup
tmpfs                       1.0G     0  1.0G   0% /var/lib/nginx
/dev/mapper/mw1321--vg-srv  191G  8.0G  173G   5% /srv

elukey@mw1321:~$ sudo lvs
  LV          VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  placeholder mw1321-vg -wi-a----- 166.04g
  root        mw1321-vg -wi-ao---- 571.66g
  srv         mw1321-vg -wi-ao---- 193.69g

elukey@mw1321:~$ sudo pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/md0   mw1321-vg lvm2 a--  931.38g    0

What I originally wanted was a LVM volume for root with 600GB, a /srv one with 200GB and 200GB free (the placeholder volume, that is required since partman will allocate all the remaining space in the PV to the last volume defined). The end result is pretty close, but I had to do the following calculations:

	10000 71000 600000000 ext4
        # root
	10000 30000 200000000 ext4
        # srv			
	10000 27500 200000000 ext4
	    # placeholder

Each LVM volume starts with a minimum size of 10G (the first value), so ~970GB are left to use (remember that the underlying PV is a sw RAID1 of 1TB usable space). In order to achieve my goal, the following GBs are needed:

  • 590 for root (~61% of the 970GB)
  • 190 for srv (~20% of the 970GB)
  • 190 for placeholder (~17.5% of the 970GB - this value was a mistake since the most correct one should have been 20%, but the last volume defined should get the remaining space anyway. In this case the srv volume gets a bit more space).

These are exactly the values that you can obtain subtracting the priority value (the middle one) with the minimum one (the first one on the left).

Please note that this is my current understanding of how Partman works, do not trust it blindly.

Config language

<owner> <question name> <question type> <value>

<owner>: "d-i" which stands for Debian Installer.

<question name>: partman-auto, partman-auto-raid and partman-auto-lvm are the packages that handle automatic partitioning of various types, and some of the questions (prompts) issued by them are described here:

<question type> says what sort of value to expect (e.g. string, boolean, select (for a menu)...)

<question value> this is where you put the answer that you would otherwise be entering interactively

NOTE that after the question type you can put only one space or tab; any other whitespace will get stuffed in at the front of the value, which you probably don't want.

Dissecting a Semi-working configuration

(by semi-working, I mean that you must hit <enter> twice, but not answer any meaningful questions.)

# Automatic software RAID 1 with LVM partitioning

d-i     partman-auto/method     string  raid

This sentence makes partman know that it will be making a raid

# Use the first two disks
d-i     partman-auto/disk       string  /dev/sda /dev/sdb

after d-i partman-auto/disk you must put the list of hard drives that are going to be used

# Define physical partitions
d-i     partman-auto/expert_recipe      string  \
                multiraid ::                                                    \
                        400000    1000    9500000       raid                    \
                                $primary{ }  method{ raid }                     \
                        .                                                       \

                        4000    1200    4100    linux-swap                      \
                        $primary{ } method{ swap } format{ }                    \
                        .

An interesting thing about partman is that you can put everything on one line, or you can break lines using the character "\". Use a "." in between hard drives.

  • $primary{ } is needed to make the partition a primary partition.
  • method { } is used to tell it what type to format. You can use swap, raid, or format.
  • format { } tells partman to format the partition. Don't put this statement in a section that you will be using for the raid. use_filesystem{ } makes partman use a file system (don't know why this isn't done by the filesystem command)
  • filesystem{ X } use ext3, murderfs, xfs, etc in here to tell it what filesystem to run
  • mountpoint{ X } use things like /, /mnt/sda3, etc

Note that the sizes listed must fit on the physical disks - using 950000 1000 995000 will work fine on a 1T disk but fail on a 250G disk. The characteristics of 'fail' are that it throws you back to the screen that asks "Guided whole disk, guided xxx, or manual?".

# Parameters are:
# <raidtype> <devcount> <sparecount> <fstype> <mountpoint> \
#          <devices> <sparedevices>
d-i     partman-auto-raid/recipe        string  \
                1       2       0       ext3    /                       \
                        /dev/sda1#/dev/sdb1                             \
                .

This snippet is telling us to make a raid 1, with 2 devices, 0 spares, ext3 filesystem, mounted at /, and across /dev/sda1 and /dev/sda2

d-i     partman-md/confirm              boolean true

Theoretically now it confirms stuff automatically. It doesn't. Partman lies

d-i     partman-md/device_remove_md     boolean true

This lets partman remove any existing raids

d-i     partman/confirm_write_new_label boolean true
d-i     partman/choose_partition        select  finish
d-i     partman/confirm                 boolean true

d-i     partman-lvm/device_remove_lvm   boolean true

d-i     mdadm/boot_degraded             boolean true

Most of these possibly do what they appear to do.

Boot degraded is important - if we have a disk failure we'd still like the system to boot, just warn us.

Dissecting another config

# Application server specific configuration

# Implementation specific hack:
d-i	partman-auto/init_automatically_partition	select	20some_device__________/var/lib/partman/devices/=dev=sda
d-i     partman-auto/method     string  regular
d-i	partman-auto/disk	string	/dev/sda

d-i	partman/choose_partition	select Finish partitioning and write changes to disk
d-i	partman/confirm			boolean	      true

# Note, expert_recipe wants to fill up the entire disk
# See http://d-i.alioth.debian.org/svn/debian-installer/installer/doc/devel/partman-auto-recipe.txt
d-i   partman-auto/expert_recipe	string	apache : 3000 5000 8000 ext3 $primary{ } $bootable{ } method{ format } format{ } use_filesystem{ }
 filesystem{ ext3 } mountpoint{ / } . 1000 1000 1000 linux-swap method{ swap } format{ } . 64 1000 10000000 jfs method{ format } format{ } use_fil
esystem{ } filesystem{ jfs } mountpoint{ /a } .
d-i		   partman-auto/choose_recipe	   apache

# Preseeding of other packages
fontconfig   fontconfig/enable_bitmaps	boolean	true

These are preseed file entries that get fed to prompts issued by the installer. Syntax:

<owner> <question name> <question type> <value>

<owner>: "d-i" which stands for Debian Installer.

<question name>: partman-auto, partman-auto-raid and partman-auto-lvm are the packages that handle automatic partitioning of various types, and some of the questions (prompts) issued by them are described here:

<question type> says what sort of value to expect (e.g. string, boolean, select (for a menu)...)

<question value> this is where you put the answer that you would otherwise be entering interactively

NOTE that after the question type you can put only one space or tab; any other whitespace will get stuffed in at the front of the value, which you probably don't want.

The first few lines of the sample config file should be obvious: select the device, choose the partition method and confirm. After that an "expert recipe" for partioning is defined, and given the name "apache". This allows it to be chosen later from the list of recipes.

Let's look at the particular recipe: it says

  • 3000 5000 8000 ext3 $primary{ } $bootable{ } method{ format } format{ } use_filesystem{ } filesystem{ ext3 } mountpoint{ / }
    3000: minumum size of partition in mb
    5000: priority if it and other listed partitions are vying for space on the disk (this is compared with the priorities of the other partitions)
    8000: maximum size of partition in mb (80GB; this is for 80GB disks, which the apaches all have.)
    ext3: filesystem type
    $primary{ }: this is a primary, not logical partition
    $bootable{ }: this is a bootable partition
    method{ format }: set to format to format the partition, to "keep" to not format, and to "swap" for swap partitions
    format{ }: also needed so the partition will be formatted
    use_filesystem{ }: this partition will have a filesystem on it (it won't be swap, lvm, etc)
    filesystem{ ext3 }: what filesystem it gets
    mountpoint{ / }: where it's mounted

The other two lines in the recipe should now be obvious.

  • 1000 1000 1000 linux-swap method{ swap } format{ }
  • 64 1000 10000000 jfs method{ format } format{ } use_filesystem{ } filesystem{ jfs } mountpoint{ /a }

Preserving Data

When you want to reimage without losing data, you can use the reuse-parts.cfg partman recipe, along with a specific disk configuration.

These recipes can be found in: gerrit:plugins/gitiles/operations/puppet/+/refs/heads/production/modules/install_server/files/autoinstall/partman/custom/

If you have a particularly important volume, or if you are doing the first of a large set of hosts, it may be helpful to add a manual verification step, by using the reuse-parts-test.cfg recipe, instead.

Verifying before applying

If you also associate your host with the reuse-parts-test.cfg recipe, you can inspect the results of the recipe via the serial console before it is applied.

What you are looking for is a K on the partition/mount point you need to preserve, as well as any LVM PVs/VGs/LVs that comprise that partition.

Other Helpful Documents