Growpart on Debian VM with LVM fails

bufu

New Member
Nov 27, 2022
8
0
1
Hi,

so I am building a Debian 12 VM template with cloud-init. I basically have everything working already, except the automatic resizing for the disk. When trying to run sudo growpart /dev/vda 5, it fails because of No space left on device..

Here is the full command output:

Code:
ciuser@debian:~$ lsblk
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0                  11:0    1    4M  0 rom
sr1                  11:1    1 1024M  0 rom
sr2                  11:2    1 1024M  0 rom
vda                 254:0    0   48G  0 disk
├─vda1              254:1    0  487M  0 part /boot
├─vda2              254:2    0    1K  0 part
└─vda5              254:5    0 31.5G  0 part
  └─debian--vg-root 253:0    0 31.5G  0 lvm  /
 
ciuser@debian:~$ sudo growpart /dev/vda 5
attempt to resize /dev/vda failed. sfdisk output below:
| Backup files:
|          MBR (offset     0, size   512): /tmp/growpart.ls8aej/orig.save-vda-0x00000000.bak
|          EBR (offset 512752640, size   512): /tmp/growpart.ls8aej/orig.save-vda-0x1e8ffc00.bak
|
| Disk /dev/vda: 48 GiB, 51539607552 bytes, 100663296 sectors
| Units: sectors of 1 * 512 = 512 bytes
| Sector size (logical/physical): 512 bytes / 512 bytes
| I/O size (minimum/optimal): 512 bytes / 512 bytes
| Disklabel type: dos
| Disk identifier: 0x3d44182f
|
| Old situation:
|
| Device     Boot   Start      End  Sectors  Size Id Type
| /dev/vda1  *       2048   999423   997376  487M 83 Linux
| /dev/vda2       1001470 67106815 66105346 31.5G  5 Extended
| /dev/vda5       1001472 67106815 66105344 31.5G 8e Linux LVM
|
| >>> Script header accepted.
| >>> Script header accepted.
| >>> Script header accepted.
| >>> Script header accepted.
| >>> Script header accepted.
| >>> Created a new DOS (MBR) disklabel with disk identifier 0x3d44182f.
| /dev/vda1: Created a new partition 1 of type 'Linux' and of size 487 MiB.
| Partition #1 contains a ext2 signature.
| /dev/vda2: Created a new partition 2 of type 'Extended' and of size 31.5 GiB.
| /dev/vda3: No free sectors available.
| Failed to add #3 partition: No space left on device
| Leaving.
|
FAILED: failed to resize
***** WARNING: Resize failed, attempting to revert ******
512+0 records in
512+0 records out
512 bytes copied, 0.00153709 s, 333 kB/s
512+0 records in
512+0 records out
512 bytes copied, 0.000825545 s, 620 kB/s
***** Restore appears to have gone OK ****

Does anyone know how you can fix this?
 
Well managed to work around it by simply installing Debian without LVM and adding a swap file instead of a partition in the end. Here are my preseed and cloud config files for anyone who needs it later :)

preseed.cfg:

Code:
# Locale
d-i debian-installer/language string ${vm_language}
d-i debian-installer/country string ${vm_country}
d-i debian-installer/locale string ${vm_locale}

# NTP
d-i time/zone string ${vm_timezone}
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string pool.ntp.org

# Keyboard Config
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select ${vm_keyboard_layout}
d-i keyboard-configuration/variant select ${vm_keyboard_variant}

# Network Config
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string ${vm_hostname}
d-i netcfg/get_domain string ${vm_domain}
d-i netcfg/hostname string ${vm_hostname}

# Root Account Setup
%{ if vm_root_login == "true" ~}
d-i passwd/root-login boolean true
%{ else ~}
d-i passwd/root-login boolean false
%{ endif ~}
d-i passwd/root-password-crypted password ${vm_password_hash}
d-i user-setup/encrypt-home boolean false

# User Setup
# set make-user to true to enable low-privilege user
%{ if vm_username != "root" ~}
d-i passwd/make-user boolean true
%{ else ~}
d-i passwd/make-user boolean false
%{ endif ~}
d-i passwd/user-fullname string ${vm_username}
d-i passwd/username string ${vm_username}
d-i passwd/user-password-crypted password ${vm_password_hash}
d-i user-setup/encrypt-home boolean false
d-i user-setup/allow-password-weak boolean true
d-i passwd/user-default-groups string audo cdrom video admin sudo

# Partitioning using ext4 without LVM
# d-i partman-auto/disk string /dev/vda
d-i partman-auto/method string regular

# Create root partition
d-i partman-auto/expert_recipe string                         \
      boot-root ::                                            \
              500 10000 1000000 ext4                          \
                      $primary{ } $bootable{ }                \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ / }                         \
              .

d-i partman-auto/choose_recipe select boot-root

# No additional partitions
d-i partman-basicfilesystems/no_mount_point boolean false
d-i partman-basicfilesystems/no_swap boolean false

# Write changes to disk
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

# Mirror Settings
d-i mirror/country string manual
d-i mirror/http/hostname string ftp.de.debian.org
d-i mirror/http/directory string /debian
d-i mirror/suite string bookworm
d-i mirror/http/proxy string

# APT Setup
d-i apt-setup/use_mirror boolean true
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string security.debian.org

# Meta packages & desktop environment
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select full-upgrade
popularity-contest popularity-contest/participate boolean false

# Essential packages
d-i pkgsel/include string ssh sudo cloud-init open-vm-tools qemu-guest-agent spice-vdagent vim

# Bootloader
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string default

# Configure SSH
d-i preseed/late_command string \
    mkdir -p /target/root/.ssh ; \
    %{ if vm_root_login == "true" ~}
    echo '${vm_ssh_public_key}' > /target/root/.ssh/authorized_keys ; \
    in-target chmod 600 /root/.ssh/authorized_keys ; \
    %{ endif ~}
    %{ if vm_username != "root" ~}
    mkdir -p /target/home/${vm_username}/.ssh ; \
    echo '${vm_ssh_public_key}' > /target/home/${vm_username}/.ssh/authorized_keys ; \
    in-target chmod 600 /home/${vm_username}/.ssh/authorized_keys ; \
    in-target chown ${vm_username}:${vm_username} /home/${vm_username}/.ssh/authorized_keys ; \
    echo '${vm_username} ${vm_sudo_permissions}' > /target/etc/sudoers.d/${vm_username} ; \
    in-target chmod 440 /etc/sudoers.d/${vm_username} ; \
    %{ endif ~}
    in-target sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config ; \
    in-target sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config ; \
    in-target sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config ; \
    in-target sed -i 's/#   StrictHostKeyChecking ask/StrictHostKeyChecking no/g' /etc/ssh/ssh_config ; \
    in-target systemctl enable ssh.service ; \
    in-target systemctl restart ssh.service ; \
    in-target fallocate -l 1G /swapfile ; \
    in-target chmod 600 /swapfile ; \
    in-target mkswap /swapfile ; \
    in-target swapon /swapfile ; \
    echo "/swapfile swap swap defaults 0 0" >> /target/etc/fstab ;

# Unmount ks.cfg ISO
d-i preseed/early_command string \
    umount /media && echo 1 > /sys/block/sr1/device/delete ;

d-i finish-install/reboot_in_progress no

cloud.cfg

Code:
# The top level settings are used as module
# and system configuration.
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
   - default
# If this is set, 'root' will not be able to ssh in and they 
# will get a message to login instead as the above $user (debian)
disable_root: false
# Change default root password from the preseed file to a random one
# chpasswd:
#  list: |
#   root:Pass
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
# This preverts apt/sources.list to be updated at boot time, which
# may be annoying.
apt_preserve_sources_list: true
# Update apt database on first boot (run 'apt-get update')
apt_update: true
# Upgrade the instance on first boot
apt_upgrade: true
# Reboot after package install/update if necessary
apt_reboot_if_required: true
resize_rootfs: true
growpart:
  mode: auto
  devices: ['/']
  ignore_growroot_disabled: false
# Write out new SSH daemon configuration. Standard debian 11 configuration
# apart from forbidding root login and disabling password authentication
# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - disk_setup
 - mounts
 - set_hostname
 - update_hostname
 - update_etc_hosts
 - ca-certs
 - rsyslog
 - users-groups
 - ssh
# The modules that run in the 'config' stage
cloud_config_modules:
# Emit the cloud config ready event
# this can be used by upstart jobs for 'start on cloud-config'.
 - emit_upstart
 - ssh-import-id
 - keyboard
 - locale
 - set-passwords
 - grub-dpkg
 - apt-pipelining
 - apt-configure
 - ntp
 - timezone
 - disable-ec2-metadata
 - runcmd
 - byobu
# The modules that run in the 'final' stage
cloud_final_modules:
 - package-update-upgrade-install
 - fan
 - landscape
 - write-files-deferred
 - puppet
 - chef
 - ansible
 - mcollective
 - salt-minion
 - reset_rmc
 - refresh_rmc_and_interface
 - rightscale_userdata
 - scripts-vendor
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - install-hotplug
 - final-message
 - power-state-change
final_message: "The system is finally up, after $UPTIME seconds"
# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
   # This will affect which distro class gets used
   distro: debian
   # Default user name + that default users groups (if added/used)
   default_user:
     name: debian
     lock_passwd: True
     gecos: Debian
     groups: [adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo, video]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash
     # Don't forget to add your public key here -- if you want. You can still add account after cloning thanks to Cloud-Init
     #ssh_authorized_keys:
   # Other config here will be given to the distro class and/or path classes
   paths:
      cloud_dir: /var/lib/cloud/
      templates_dir: /etc/cloud/templates/
      upstart_dir: /etc/init/
   package_mirrors:
     - arches: [default]
       failsafe:
         primary: http://deb.debian.org/debian
         security: http://security.debian.org/
   ssh_svcname: ssh
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!