After OS partitions of old versions are expanded, the OS must be restarted to update the file system.
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:
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
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
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.
For example, if the system disk size of CentOS 6.5 64bit is 40 GB, perform the following operations to configure a Linux private image so that it can automatically expand its root partition:
parted -l /dev/xvda
As shown in the command output, the root partition is the second partition and is 38.7 GB.
Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 42.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 4296MB 4295MB primary linux-swap(v1) 2 4296MB 42.9GB 38.7GB primary ext4 boot
Run the following command to install growpart:
yum install cloud-*
growpart may be contained in the cloud-utils-growpart/cloud-utils/cloud-initramfs-tools/cloud-init package. You can run the preceding command directly and then run the growpart command to check whether growpart has been installed successfully.
The command output is as follows:
/dev/xvda1: UUID="25ec3bdb-ba24-4561-bcdc-802edf42b85f" TYPE="swap" /dev/xvda2: UUID="1a1ce4de-e56a-4e1f-864d-31b7d9dfb547" TYPE="ext4"
[root@sluo-ecs-e6dc-resizefs ~]# poweroff Connection closed by foreign host. Disconnected from remote host at 11:08:54. Type `help´ to learn how to use Xshell prompt.
parted -l /dev/xvda
As shown in the command output, the root partition has been expanded automatically.
Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos NumberStartEndSizeTypeFile systemFlags 1 1049kB 4296MB 4295MB primary linux-swap(v1) 2 4296MB 53.7GB 49.4GB primary ext4 boot
The command output is as follows:
Filesystem Type Size Used Avail Use% Mounted on /dev/xvda2 ext4 49.4G 2.6G 46.8G 4% /dev/shm tmpfs tmpfs 4295M 0 4295M 0% /
parted -l /dev/xvda
As shown in the command output, the root partition is the first partition and is 40.9 GB. The swap partition is the second partition.
Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 42.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 41.0GB 40.9GB primary ext4 boot 2 41.0GB 42.9GB 2000MB primary linux-swap(v1)
tail -n 3 /etc/fstab
As shown in the command output, UUIDs of the two partitions are displayed.
# UUID=7c4fce5d-f8f7-4ed6-8463-f2bd22d0ddea / ext4 defaults 1 1 UUID=5de3cf2c-30c6-4fb2-9e63-830439d4e674 swap swap defaults 0 0
vi /etc/fstab
wq!
As shown in the command output, only the UUID of the root partition is displayed.
UUID=7c4fce5d-f8f7-4ed6-8463-f2bd22d0ddea / ext4 defaults 1 1
parted /dev/xvda
The command output is as follows:
[root@test-0912 bin]# parted /dev/xvda GNU Parted 3.1 Using /dev/xvda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
(parted) p Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 42.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 4296MB 4295MB primary linux-swap(v1) 2 4296MB 42.9GB 38.7GB primary xfs boot (parted)
The command output is as follows:
(parted) rm 2 (parted)
The command output is as follows:
(parted) p Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 42.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 41.0GB 40.9GB primary ext4 boot
parted -l /dev/xvda
As shown in the command output, the swap partition is deleted.
Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 42.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 41.0GB 40.9GB primary ext4 boot
Run the following command to install growpart:
yum install cloud-*
growpart may be contained in the cloud-utils-growpart/cloud-utils/cloud-initramfs-tools/cloud-init package. You can run the preceding command directly and then run the growpart command to check whether growpart has been installed successfully.
growpart /dev/xvda 1
The command output is as follows:
CHANGED: partition=1 start=2048 old: size=79978496 end=79980544 new: size=83873317,end=83875365
parted -l /dev/xvda
Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 42.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 42.9GB 42.9GB primary ext4 boot
The command output is as follows:
/dev/xvda1: UUID="7c4fce5d-f8f7-4ed6-8463-f2bd22d0ddea" TYPE="ext4"
[root@sluo-ecs-e6dc-resizefs ~]# poweroff Connection closed by foreign host. Disconnected from remote host at 11:08:54. Type `help´ to learn how to use Xshell prompt.
parted -l /dev/xvda
As shown in the command output, the root partition has been expanded to 107 GB.
Model: Xen Virtual Block Device (xvd) Disk /dev/xvda: 107GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 107GB 107GB primary ext4 boot
The value of Size is the size of the expanded root partition.