How Can I Add the Empty Partition of an Expanded System Disk to the Non-end Root Partition Online?
Scenarios
If the capacity of system disk partitions is inconsistent with the actual system disk capacity after an ECS is created, you can add the empty partition to the root partition of the system disk.
This section describes how to add the empty partition to the non-end root partition online.
Procedure
In the following operations, the ECS that runs CentOS 6.5 64bit and has a 100 GB system disk is used as an example. The system disk has two partitions, /dev/xvda1: root and /dev/xvda2: swap, and the root partition is not the end partition.
- Run the following command to view disk partitions:
parted -l /dev/xvda
[root@sluo-ecs-a611 ~]# parted -l /dev/xvdaDisk /dev/xvda: 107GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags1 1049kB 41.0GB 40.9GB primary ext4 boot2 41.0GB 42.9GB 2000MB primary linux-swap(v1)The first is the root partition, and the second is the swap partition.
- View and edit the fstab partition table to delete the swap partition attachment information.
- Run the following command to view the fstab partition table:
tail -n 3 /etc/fstab
[root@sluo-ecs-a611 ~]# tail -n 3 /etc/fstab#UUID=7c4fce5d-f8f7-4ed6-8463-f2bd22d0ddea / ext4 defaults 1 1UUID=5de3cf2c-30c6-4fb2-9e63-830439d4e674 swap swap defaults 0 0 - Run the following command to edit the fstab partition table and delete the swap partition attachment information.
vi /etc/fstab
tail -n 3 /etc/fstab
[root@sluo-ecs-a611 ~]# vi /etc/fstab[root@sluo-ecs-a611 ~]# tail -n 3 /etc/fstab#UUID=7c4fce5d-f8f7-4ed6-8463-f2bd22d0ddea / ext4 defaults 1 1
- Run the following command to view the fstab partition table:
- Run the following command to disable the swap partition:
swapoff -a
- Delete the swap partition.
- Run the following command to view the partition:
parted /dev/xvda
[root@sluo-ecs-a611 ~]# parted /dev/xvdaGNU Parted 3.1Using /dev/xvdaWelcome to GNU Parted! Type ´help´ to view a list of commands.(parted) helpalign-check TYPE N check partition N for TYPE(min|opt) alignmenthelp [COMMAND] print general help, or help on COMMANDmklabel,mktable LABEL-TYPE create a new disklabel (partition table)mkpart PART-TYPE [FS-TYPE] START END make a partitionname NUMBER NAME name partition NUMBER as NAMEprint [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or aparticular partitionquit exit programrescue START END rescue a lost partition near START and ENDrm NUMBER delete partition NUMBERselect DEVICE choose the device to editdisk_set FLAG STATE change the FLAG on selected devicedisk_toggle [FLAG] toggle the state of FLAG on selected deviceset NUMBER FLAG STATE change the FLAG on partition NUMBERtoggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBERunit UNIT set the default unit to UNITversion display the version number and copyright information of GNU Parted(parted) - Press p.Disk /dev/xvda: 107GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags1 1049kB 41.0GB 40.9GB primary ext4 boot2 41.0GB 42.9GB 2000MB primary linux-swap(v1)
- Run the following command to delete the partition:
rm 2
(parted) rm2 - Press p.(parted) pDisk /dev/xvda: 107GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags1 1049kB 41.0GB 40.9GB primary ext4 boot
- Run the following command to edit the fstab partition table:
quit
(parted) quitInformation: You may need to update /etc/fstab.
- Run the following command to view the partition:
- Run the following command to view partition after the swap partition is deleted:
parted -l /dev/xvda
[root@sluo-ecs-a611 ~]# parted -l /dev/xvdaDisk /dev/xvda: 107GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags1 1049kB 41.0GB 40.9GB primary ext4 boot - Run the following command to install the growpart tool:
This tool may be integrated in the cloud-utils-growpart/cloud-utils/cloud-initramfs-tools/cloud-init package. Run the yum install cloud-* command to ensure it is available.
yum install cloud-utils-growpart
- Run the following command to expand the root partition (the first partition) using growpart:
growpart /dev/xvda 1
[root@sluo-ecs-a611 ~]# growpart /dev/xvda 1CHANGED: partition=1 start=2048 old: size=79978496 end=79980544 new: size=209710462,end=209712510 - Run the following command to verify that online capacity expansion is successful:[root@sluo-ecs-a611 ~]# parted -l /dev/xvdaDisk /dev/xvda: 107GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags1 1049kB 107GB 107GB primary ext4 boot
- Run the following command to expand the capacity of the file system:
resize2fs -f $Partition name
Suppose the partition name is /dev/xvda1, run the following command:
[root@sluo-ecs-a611 ~]# resize2fs -f /dev/xvda1resize2fs 1.42.9 (28-Dec-2013)Filesystem at /dev/xvda1 is mounted on /; on-line resizing requiredold_desc_blocks = 3, new_desc_blocks = 3....[root@sluo-ecs-a611 ~] # df -hT //Check file system capacity expansion
- Scenarios
- Procedure