Score:1

How to get around 'device in use' error when preseeding Ubuntu 22.04 install with encrypted LVM

gb flag

I am trying to make a custom install ISO for Ubuntu with Cubic and Ubiquity's preseed option. I have been tearing my hair out trying to get it to automatically partition the entire disk as an encrypted LVM like the GUI installer allows one to do. I have tried nearly a dozen example preseed configurations I've found online, all of which end with the installer erroring out during partitioning because:

No modifications can be made to the device: Encrypted Volume (sda1p2_crypt) for the following reasons: In use by LVM module group crypt or whatever the recipe has named the LVM group. I assume these recipes worked for prior versions of Ubuntu.

At first, I thought this error was just because the disk has some pre-existing partitioning with encrypted LVMs, so I ran an sgdisk -Z /dev/sda, restarted, and retried but the issues persist.

I can, of course, manually partition the disk just fine with the GUI of the installer.

Here's a sample section from the preseed:

d-i partman-auto/method string crypto
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto-lvm/new_vg_name string crypt
d-i partman-auto/choose_recipe select root-encrypted
d-i partman-auto/expert_recipe string                         \
      root-encrypted ::                                       \
              500 500 500 ext4                                \
                      $primary{ } $bootable{ }                \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ /boot }                     \
              .                                               \
              2000 2000 2000 linux-swap                       \
                      $lvmok{ } lv_name{ swap }               \
                      in_vg { crypt }                         \
                      $primary{ }                             \
                      method{ swap } format{ }                \
              .                                               \
              500 10000 1000000000 ext4                       \
                      $lvmok{ } lv_name{ rootpart }           \
                      in_vg { crypt }                         \
                      $primary{ }                             \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ / }                         \
              .                                               
d-i partman-md/device_remove_md boolean true
d-i partman-basicfilesystems/no_mount_point boolean false
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

Another one which produces the same error. In this one, I am not using a custom recipe, instead just opting for the built-in recipe.

#Get around the prompt for UEFI-only
d-i partman-efi/non_efi_system boolean true
d-i partman/default_filesystem string ext4

# In addition, you'll need to specify the method to use.
# The presently available methods are:
# - regular: use the usual partition types for your architecture
# - lvm:     use LVM to partition the disk
# - crypto:  use LVM within an encrypted partition
d-i partman-auto/method string crypto
d-i partman-crypto/passphrase password mypassword7
d-i partman-crypto/passphrase-again password mypassword7

# If one of the disks that are going to be automatically partitioned
# contains an old LVM configuration, the user will normally receive a
# warning. This can be preseeded away...
d-i partman-lvm/device_remove_lvm boolean true
# The same applies to pre-existing software RAID array:
d-i partman-md/device_remove_md boolean true
# And the same goes for the confirmation to write the lvm partitions.
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

# For LVM partitioning, you can select how much of the volume group to use
# for logical volumes.
d-i partman-auto-lvm/guided_size string max

# You can choose one of the three predefined partitioning recipes:
# - atomic: all files in one partition
# - home:   separate /home partition
# - multi:  separate /home, /var, and /tmp partitions
d-i partman-auto/choose_recipe select atomic

# This makes partman automatically partition without confirmation, provided
# that you told it what to do using one of the methods above.
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

What is the partman configuration needed to make this work?

Score:0
gb flag

After extensive attempts, research, and reading the experiences of others trying to accomplish this, I have come to the conclusion that this is impossible due to some bug in the installer.

The Ubuntu Server iso w/ autoinstall and subiquity can accomplish this quite cleanly with the autoinstall functionality and I would suggest that for anybody as an alternative to going down the rabbit hole of solving this issue.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.