How Do I Configure a Linux Private Image to Make It Automatically Expand Its Root Partition?

Constraints

Installation of growpart on Different OSs

To enable private images to automatically expand the root partition, install growpart.
Table 1 growpart installation packages for different OSs

OS

Tool Package

Debian/Ubuntu

cloud-init, cloud-utils, and cloud-initramfs-growroot

Fedora/CentOS

cloud-init, cloud-utils, and cloud-utils-growpart

SUSE/openSUSE

cloud-init and growpart

For Debian 9, use method 1 to install growpart. If the installation fails, use method 2 to install growpart.

Method 1:

Run the following command to install growpart:

apt-get install -y -f cloud-init cloud-utils cloud-initramfs-growroot

Method 2:

If method 1 fails, it may be because the installation source of Debian 9.0.0 is faulty. You need to download dependent packages cloud-utils and cloud-initramfs-growroot and install them.
  1. Run the following command to download the dependent packages:

    wget Package download path

    You can obtain the dependent packages from the following paths:

    http://ftp.br.debian.org/debian/pool/main/c/cloud-utils/cloud-utils_0.29-1_all.deb

    http://ftp.br.debian.org/debian/pool/main/c/cloud-initramfs-tools/cloud-initramfs-growroot_0.18.debian5_all.deb

  2. Run the following command to rectify the dependent packages:

    apt --fix-broken install

  3. Run the following command to install the dependent packages:

    dpkg -i cloud-utils package path cloud-initramfs-growroot package path

    An example command is dpkg -i /root/cloud-utils_0.29-1_all.deb /root/cloud-initramfs-growroot_0.18.debian5_all.deb.

For other Debian versions, run the following command to install dependent packages:

apt-get update;apt-get install cloud-utils cloud-initramfs-growroot

Procedure

Take the following as two examples of image disk partitioning:

If the root partition is the last partition, see Root partition at the last.

If the root partition is not the last partition, see Root partition not at the last.

If the parted command fails, ensure that the parted tool has been installed in the OS. Perform the following operations to install the tool:
  • For CentOS, run the following command:

    yum install parted

  • For Debian, run the following command:

    apt-get install parted