{"id":451,"date":"2015-01-29T15:43:28","date_gmt":"2015-01-29T15:43:28","guid":{"rendered":"https:\/\/www.bishnet.net\/tim\/blog\/?p=451"},"modified":"2015-01-31T22:37:52","modified_gmt":"2015-01-31T22:37:52","slug":"understanding-partman-autoexpert_recipe","status":"publish","type":"post","link":"https:\/\/www.bishnet.net\/tim\/blog\/2015\/01\/29\/understanding-partman-autoexpert_recipe\/","title":{"rendered":"Understanding partman-auto\/expert_recipe"},"content":{"rendered":"<p><em>TL;DR &#8211; Subtract the minimum size from the priority and compare this to other partitions to work out how much of the free space will be assigned to a partition.<\/em><\/p>\n<p>I&#8217;ve been trying to create a simple recipe for partitioning disks on new machines when using the Debian\/Ubuntu automated installer. This looks like it should be fairly straightforward, but the documentation makes it more confusing that it needs to be. First, here&#8217;s an example:<\/p>\n<pre>d-i partman-auto\/expert_recipe string \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 root :: \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8192 8241 16384 linux-swap \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $primary{ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 method{ swap } format{ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 . \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16384 16386 -1 ext4 \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $primary{ } $bootable{ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 method{ format } format{ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 use_filesystem{ } filesystem{ ext4 } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mountpoint{ \/ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 . \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8192 8241 16384 ext4 \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $primary{ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 method{ format } format{ } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 use_filesystem{ } filesystem{ ext4 } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mountpoint{ \/var } \\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .<\/pre>\n<p>I want at least 8GiB of swap and \/var, and at least 16GiB for the root filesystem. I don&#8217;t want swap or \/var to grow beyond 16GiB, but I&#8217;m happy for the root filesystem to grow to fill the disk. The first number for each partition is the <em>minimum<\/em> size, the second is the <em>priority<\/em>, and the third is the <em>maximum<\/em> (-1 being no maximum). The <em>minimum<\/em> and <em>maximum<\/em> definitions should be clear, but what does the <em>priority<\/em> field mean? Let&#8217;s consult the documentation:<\/p>\n<blockquote><p>&lt;priority&gt; is some size usually between &lt;minimal size&gt; and &lt;maximal size&gt;. It determines the priority of this partition in the contest with the other partitions for size. Notice that if &lt;priority&gt; is too small (relative to the priority of the other partitions) then this partition will have size close to &lt;minimal size&gt;. That&#8217;s why it is recommended to give small partitions a &lt;priority&gt; larger than their &lt;maximal size&gt;.<\/p><\/blockquote>\n<p>So it makes it clear what this number is about &#8211; it&#8217;s used to decide how much of the free space is assigned to a partition compared to the others &#8211; but it doesn&#8217;t explain how it does that, how the numbers are compared, or what they actually mean. There&#8217;s plenty of misinformation about this online, so I read through the code to work out what was really going on.<\/p>\n<p>The algorithm is actually fairly straightforward. First it works out a percentage weight for each partition. It does this by subtracting the <em>minimum<\/em> value from the <em>priority<\/em>. If the <em>priority<\/em> is less than the <em>minimum<\/em> the <em>minimum<\/em> is used instead, which results in a zero value for this calculation. The values for all partitions are then added together and a percentage calculated for each one. So in the above example we have percentages of 49%, 2% and 49% for each partition in turn (yes, it&#8217;s no coincidence that the priorities were chosen to make percentage calculations easy).<\/p>\n<p>Next, with a percentage weight for each partition it moves on to looking at the free space. It starts by giving each partition its <em>minimum<\/em> value (there must be enough disk space for that, otherwise the process fails) and then works out what space is left over. Each partition is then assigned a percentage of that left over space based on the figure from the previous step. That&#8217;s it &#8211; it&#8217;s as simple as that! Assuming none have gone over their <em>maximum<\/em> value we&#8217;re done.<\/p>\n<p>If a partition does get assigned a value over its <em>maximum<\/em> then the <em>maximum<\/em> is taken as the new size instead and the <em>priority<\/em> for that partition becomes zero. Another pass around the loop is done, ignoring that partition completely for the percentage calculations, and the remaining free space assigned to the other partitions. This process repeats until there is no more space, or until all have hit their <em>maximum<\/em> values.<\/p>\n<p>As a side note, when all partitions hit their <em>maximum<\/em> values the remaining space gets assigned to the last partition when the partitions are created. Personally I&#8217;d prefer it was left free on the disk, but it&#8217;s not configurable.<\/p>\n<p>So here&#8217;s my advice &#8211; use percentages yourself. Work out what percentage of the space you&#8217;d like assigned to each partition in each pass and then add this amount to the <em>minimum<\/em> value to work out the <em>priority<\/em>.<\/p>\n<p>The above was all deduced by reading the source code <a href=\"http:\/\/bazaar.launchpad.net\/~ubuntu-core-dev\/partman-auto\/ubuntu\/view\/head:\/lib\/recipes.sh\" target=\"_blank\">here<\/a>, specifically the expand_scheme<span class=\"pyg-o\">() function. Thank goodness for Open Source!<br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR &#8211; Subtract the minimum size from the priority and compare this to other partitions to work out how much of the free space will be assigned to a partition. I&#8217;ve been trying to create a simple recipe for partitioning disks on new machines when using the Debian\/Ubuntu automated installer. This looks like it should be fairly straightforward, but the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[138,137,139],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-computing","tag-debian","tag-partman","tag-ubuntu"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":8,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":464,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts\/451\/revisions\/464"}],"wp:attachment":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}