cloud-init LVM resize not working

IloGus

Member
Apr 25, 2020
8
0
6
France
Hello,

I'm trying to make a debian 10 template with cloud-init.
Virtualizing in KVM on Proxmox Virtual Environment 6.1-8

If there's anyone who can help me :)

When I clone the template and add freespace on the clone and booting I got this line in the log :

Code:
2020-04-25 17:57:19,864 - util.py[DEBUG]: resize_devices took 0.019 seconds
2020-04-25 17:57:19,864 - cc_growpart.py[DEBUG]: '/' SKIPPED: device_part_info(/dev/mapper/debian--vg-root) failed: /dev/mapper/debian--vg-root not a partition
2020-04-25 17:57:19,864 - handlers.py[DEBUG]: finish: init-network/config-growpart: SUCCESS: config-growpart ran successfully
2020-04-25 17:57:19,864 - stages.py[DEBUG]: Running module resizefs (<module 'cloudinit.config.cc_resizefs' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.py'>) with frequency always
2020-04-25 17:57:19,865 - handlers.py[DEBUG]: start: init-network/config-resizefs: running config-resizefs with frequency always
2020-04-25 17:57:19,865 - helpers.py[DEBUG]: Running config-resizefs using lock (<cloudinit.helpers.DummyLock object at 0x7fce90683ac8>)
2020-04-25 17:57:19,890 - util.py[DEBUG]: Reading from /proc/369/mountinfo (quiet=False)
2020-04-25 17:57:19,890 - util.py[DEBUG]: Read 2788 bytes from /proc/369/mountinfo
2020-04-25 17:57:19,890 - cc_resizefs.py[DEBUG]: resize_info: dev=/dev/mapper/debian--vg-root mnt_point=/ path=/
2020-04-25 17:57:19,890 - util.py[DEBUG]: Running command ['systemd-detect-virt', '--quiet', '--container'] with allowed return codes [0] (shell=False, capture=True)
2020-04-25 17:57:19,897 - util.py[DEBUG]: Running command ['running-in-container'] with allowed return codes [0] (shell=False, capture=True)
2020-04-25 17:57:19,899 - util.py[DEBUG]: Running command ['lxc-is-container'] with allowed return codes [0] (shell=False, capture=True)
2020-04-25 17:57:19,901 - util.py[DEBUG]: Reading from /proc/1/environ (quiet=False)
2020-04-25 17:57:19,901 - util.py[DEBUG]: Read 143 bytes from /proc/1/environ
2020-04-25 17:57:19,901 - util.py[DEBUG]: Reading from /proc/self/status (quiet=False)
2020-04-25 17:57:19,901 - util.py[DEBUG]: Read 1013 bytes from /proc/self/status
2020-04-25 17:57:19,901 - cc_resizefs.py[DEBUG]: Resizing / (ext4) using resize2fs /dev/mapper/debian--vg-root
2020-04-25 17:57:19,901 - util.py[DEBUG]: Running command ('resize2fs', '/dev/mapper/debian--vg-root') with allowed return codes [0] (shell=False, capture=True)
2020-04-25 17:57:20,024 - util.py[DEBUG]: Resizing took 0.123 seconds
2020-04-25 17:57:20,024 - cc_resizefs.py[DEBUG]: Resized root filesystem (type=ext4, val=True)
2020-04-25 17:57:20,025 - handlers.py[DEBUG]: finish: init-network/config-resizefs: SUCCESS: config-resizefs ran successfully

In put this in the 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

# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false

resize_rootfs: true

growpart:
  mode: auto
  devices: ['/']
  ignore_growroot_disabled: false

# Example datasource config
# datasource:
#    Ec2:
#      metadata_urls: [ 'blah.com' ]
#      timeout: 5 # (defaults to 50 seconds)
#      max_wait: 10 # (defaults to 120 seconds)

# 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
 - locale
 - set-passwords
 - grub-dpkg
 - apt-pipelining
 - apt-configure
 - ntp
 - timezone
 - runcmd
 - byobu

# The modules that run in the 'final' stage
cloud_final_modules:
 - package-update-upgrade-install
 - rightscale_userdata
 - scripts-vendor
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change

# 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
   # 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
 
2020-04-25 17:57:19,864 - cc_growpart.py[DEBUG]: '/' SKIPPED: device_part_info(/dev/mapper/debian--vg-root) failed: /dev/mapper/debian--vg-root not a partition
The root is on an LVM mapped device and not a partition. AFAIK, growpart works on partitions only.
 
Hi, I just encounter same problem, in my case, I am using two LVM logical volumes: root and swap, and the physical volume created in partition(/dev/sda1), therefor I need to run the growpart to expand the disk partition and then run the pvresize and lvresize to expand the LVM volumes. However, the current lates cloud-init still do not support expanding LVM at all, and there is problem to run the growpart script through cloud-init moudle runcmd.

So I have to create a shell scrip to do all this resize tasks, and call this script through the cloud-init module bootcmd (as the runcmd only run on first boot, but the bootcmd run on every boot).

Here is my shell script:

# vi /usr/bin/resizelvm
----------
#!/bin/sh
/usr/bin/growpart /dev/sda 1
/usr/sbin/pvresize -y -q /dev/sda1
/usr/sbin/lvresize -y -q -r -l +100%FREE /dev/debian/root
/usr/sbin/resize2fs -fF /dev/debian/root
exit 0
----------
# chmod 755 /usr/bin/resizelvm

and then modify the cloud-init configuration:

# vi /etc/cloud/cloud.cfg
bootcmd:
- [ /usr/bin/resizelvm ]
 
Last edited:
  • Like
Reactions: alteriks

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!