Auto partitioning multiple drives on an LVM using Ubuntu Preseed

My goal: format and partition two separate drives using LVM during an automated Ubuntu install.

The Debian preseed file isn’t, at first glance, as flexible as kickstart files but as with almost everything, once you dig a bit deeper you find out that they just do things differently. I couldn’t find a good reference on formatting multiple drives and I did find a few people saying it wasn’t possible so that was discouraging. In the end, it’s actually quite straightforward.

Generally you need to:

  1. Define your physical volumes and create volume groups
  2. Define your volumes and place them into volume groups
  3. Define sizing parameters to make sensible partition sizes for your expected usage

The working partman configuration is shown below, including some helpful comments. Probably the most confusing thing is what the three numbers do in the logical volume definition. In short, they are minimum size, priority and maximum size. A calculation is performed that assigns space based on an algorithm. I found Tim Bishop’s partman-auto/expert-recipe explanation to be the best explanation out there. Be warned – there is a lot of misinformation floating around about these values.

Here’s the working configuration:

d-i partman-auto/method string lvm

# These options remove any existing LVM and deploy a new system
# Without all of these set like this you can end up with errors
# when you try to reinstall a machine with existing volume groups
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-auto/expert_recipe string                         \
      pvs ::                                                  \
              20480 750000 750000 ext4                        \
                      $primary{ }                             \
                      method{ lvm }                           \
                      device{ /dev/sda }                      \
                      vg_name{ system }                       \
              .                                               \
              1000000 1000000000 1000000000 ext4              \
                      $primary{ }                             \
                      method{ lvm }                           \
                      device{ /dev/sdb }                      \
                      vg_name{ data }                         \
              .                                               \
      system ::                                               \
              20480 20498 5000000 ext4                        \
                      $lvmok{ }                               \
                      lv_name{ root }                         \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ / }                         \
                      in_vg{ system }                         \
              .                                               \
              2048 2050 8192 linux-swap                       \
                      $lvmok{ }                               \
                      lv_name{ swap }                         \
                      method{ swap } format{ }                \
                      in_vg{ system }                         \
              .                                               \
      data ::                                                 \
              1000000 1000009 -1  ext4                        \
                      $lvmok{ }                               \
                      lv_name{ var }                          \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ /data }                     \
                      in_vg{ data }                           \
              .                                               \
              100000 100001 500000 ext4                       \
                      $lvmok{ }                               \
                      lv_name{ datasnapshots }                \
                      \$defaultignore                         \
                      in_vg{ data }                           \
              .

The expected behaviour from my configuration is:

# '/' = Min size 20GB, max 5,000GB, percentage(18/20) 90%
# 1TB drive = everything apart from swap
20480 20498 5000000 ext4

# 'swap' = Min size 2GB, max 8GB, percentage(2/20) 10%
# 1TB drive = 8GB
2048 2050 8192 linux-swap

# '/data' - Min size 1TB, max unlimited, percentage(9/10) 90%
# 5TB drive = 4.5TB
1000000 1000009 -1 ext4

# '/data snapshots' - Min size 100GB, max 500GB, percentage(1/10) 10%
# 2TB drive = 500GB
100000 100001 500000 ext4

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.