Extending Disk Partitions and File Systems (Linux)
Scenarios
After a disk is expanded on the console, the disk size is enlarged, but the disk partition and file system are not extended. You must log in to the server to extend the partition and file system before you can view and use the additional space. Specifically, you can add the additional space to an existing partition and file system or create a new partition and file system with the additional space.
This section describes how to extend partitions and file systems on a system or data disk in Linux. The extension operations may vary depending on the server OS. Perform extension operations based on your server OS.
Scenario |
Partition Style |
Disk Function |
OS |
File System Format |
Capacity Expansion Tool |
Example Configuration |
---|---|---|---|---|---|---|
Extending an Existing Partition |
GPT or MBR |
System disk Data disk |
|
ext* (such as ext2, ext3, and ext4), xfs, and btrfs |
growpart |
|
Extending an Existing MBR Partition (for System Disks Whose Kernel Version Is Earlier Than 3.6.0) |
MBR |
System disk |
The kernel version is earlier than 3.6.0. |
ext* (such as ext2, ext3, and ext4), xfs, and btrfs |
dracut-modules-growroot |
|
Creating a New MBR Partition |
MBR |
System disk Data disk |
Not limited |
ext* (such as ext2, ext3, and ext4), xfs, and btrfs |
|
|
Creating a New GPT Partition |
GPT |
Data disk |
Not limited |
ext* (such as ext2, ext3, and ext4), xfs, and btrfs |
parted |
|
You can run uname -a to check the Linux kernel version.
For how to extend partitions and file systems on a BMS system disk, see How Do I Increase the Size of the Root Partition of a BMS Which Is Quickly Provisioned?
If the disk is not partitioned, see How Do I Extend the File System of an Unpartitioned Data Disk in Linux?
Notes and Constraints
- The additional space of a data disk cannot be added to the root partition. To extend the root partition, expand the system disk instead.
- During an expansion, the additional space is added to the end of the disk. If the disk has multiple partitions, the additional space can only be allocated to the partition at the disk end.
- If a disk uses MBR, the storage space in excess of 2 TiB cannot be used because the maximum capacity that MBR supports is 2 TiB. If your disk already uses MBR for partitioning and you require more than 2 TiB after the capacity expansion, do as follows:
- (Recommended) Create a new EVS disk and use GPT.
- Back up the disk data, perform the expansion, and then change the partition style from MBR to GPT. During this change, services will be interrupted and data on the disk will be erased.
Prerequisites
- You have expanded the disk capacity and attached the disk to a server on the console. For details, see Step 1: Expand Disk Capacity.
- The disk has been backed up using CBR or snapshots. For details, see Backing Up EVS Disks and Managing EVS Snapshots (OBT) respectively.
- You have logged in to the server.
- For how to log in to an ECS, see Logging In to an ECS.
- For how to log in to a BMS, see Logging In to a BMS.
Originally, data disk /dev/vdb has 100 GiB and one partition /dev/vdb1. Then, the disk is expanded to 150 GiB. The following example shows you how to allocate the additional 50 GiB to the existing /dev/vdb1 partition.
- Check whether the growpart tool is installed.
growpart
- If the tool instructions are returned, the tool has been installed, and you do not need to install it again.
[root@ecs-centos76 ~]# growpart growpart disk partition rewrite partition table so that partition takes up all the space it can options: -h | --help print Usage and exit --fudge F if part could be resized, but change would be less than 'F' bytes, do not resize (def ault: 1048576) -N | --dry-run only report what would be done, show new 'sfdisk -d' -v | --verbose increase verbosity / debug -u | --update R update the the kernel partition table info after growing this requires kernel support and 'partx --update' R is one of: - 'auto': [default] update partition if possible - 'force' : try despite- sanity checks (fail on failure) - 'off' : do not attempt - 'on' : fail if sanity checks indicate no support Example: - growpart /dev/sda 1 Resize partition 1 on /dev/sda must supply disk and part it ion-number [root@ecs-centos76 ~l#
- If no tool instructions are returned, run the following command to install the tool:
yum install cloud-utils-growpart
Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 8.0 kB 00:00:00 ... Package cloud-utils-growpart-0.29-2.el7.noarch already installed and latest version Nothing to do
The installation is successful.
- If the tool instructions are returned, the tool has been installed, and you do not need to install it again.
- Check the partition information of the /dev/vdb disk.
lsblk
[root@ecs-centos76 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├vda1 253:1 0 40G 0 part / vdb 253:16 0 150G 0 disk ├vdb1 253:17 0 100G 0 part /mnt/sdc
We can see that /dev/vdb has 150 GiB, the /dev/vdb1 partition has 100 GiB, and the additional 50 GiB space is not allocated.
If the disk is not partitioned, you need to directly extend the file system, go to 4.
- Add the additional space to the /dev/vdb1 partition.
growpart /dev/vdb 1
[root@ecs-test-0001 ~]# growpart /dev/vdb 1 CHANGED: partition=1 start=2048 old: size=209713152 end=209715200 new: size=314570719,end=314572767
- If the following information is displayed:
no tools available to resize disk with 'gpt' FAILED: failed to get a resizer for id ''
The disk uses the GPT partition style, and the gdisk tool is required when you use growpart to add the additional space. In this case, run yum install gdisk, enter y to install gdisk, and then run the preceding growpart command.
- If the following information is displayed:
growpart /dev/vda 1 unexpected output in sfdisk --version [sfdisk is from util-linux 2.23.2]
Check whether the system character set (language environment) is en_US.UTF-8. If not, run export LC_ALL=en_US.UTF-8.
- If error message "NOCHANGE:partition 1 is size xxxxxxx. it cannot be grown" or "No space left on the block device" is returned, the expansion may be failed because the server disk is full (100% usage). Back up the disk data and clear unnecessary files or programs.
- If the following information is displayed:
- Extend the file system of the /dev/vdb1 partition.
- Check the file system format of the /dev/vdb1 partition.
parted /dev/vdb
P
[root@ecs-centos74 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049KB 107GB 107GB ext4 /dev/vdb1 (parted)
Enter q and press Enter to exit parted.
- Extend the file system. As the file system format of /dev/vdb1 is ext4, we use the following command.
resize2fs /dev/vdb1
[root@ecs-test-0001 ~]# resize2fs /dev/vdb1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/vdb1 is mounted on /mnt/sdc; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 19 The filesystem on /dev/vdb1 is now 39321339 blocks long.
- If the error message "open: No such file or directory while opening /dev/vdb1" is returned, an incorrect partition is specified. Run parted to view disk partitions.
- If the file system format is xfs, run the following command (/mnt/sdc is the mount point of /dev/vdb1. Change it based on your actual condition):
sudo xfs_growfs /mnt/sdc
[root@ecs-test-0001 ~]# sudo xfs_growfs /mnt/sdc meta-data=/dev/vdb1 isize=512 agcount=4, agsize=6553536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=26214144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=12799, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 26214144 to 39321339
- Check the file system format of the /dev/vdb1 partition.
- Check the partition size after extension.
lsblk
[root@ecs-centos76 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├vda1 253:1 0 40G 0 part / vdb 253:16 0 150G 0 disk ├vdb1 253:17 0 150G 0 part /mnt/sdc
We can see that the /dev/vdb data disk now has 150 GiB and the /dev/vdb1 partition has 150 GiB, meaning that the extension operation is successful.
If you are expanding a data disk and the OS kernel is earlier than 3.6.0, after the partition and file system are extended, you need to run reboot to make the additional space available for use. Restarting the OS will interrupt services. To prevent any data loss after the restart, ensure that you have backed up the disk data before the restart. To back up data using CBR, see Backing Up EVS Disks. To back up data using snapshots, see Managing EVS Snapshots (OBT).
Originally, system disk /dev/vda has 40 GiB and one partition /dev/vda1. Then, the disk is expanded to 100 GiB. The following example shows you how to allocate the additional 60 GiB to the existing /dev/vda1 partition.
- If the OS kernel version is earlier than 3.6.0, you need to reboot the system after extending an existing MBR partition to make the additional space available. During the reboot, services will be interrupted. After the reboot, the additional space is automatically added to the last partition of the system disk.
- To prevent data loss after a reboot, you are advised to use CBR to back up the disk data before initializing a disk.
- If your OS kernel version is earlier than 3.6.0 and you want to create a new partition with the additional space, see Creating a New MBR Partition.
- (Optional) Install the dracut-modules-growroot tool.
yum install dracut-modules-growroot
[root@ecs-test-0002 ~]# yum install dracut-modules-growroot Loaded plugins: fastestmirror, security Setting up Install Process Loading mirror speeds from cached hostfile epel/metalink | 4.3 kB 00:00 * epel: pubmirror1.math.uh.edu base | 3.7 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 Package dracut-modules-growroot-0.20-2.el6.noarch already installed and latest version Nothing to do
Skip this step if the tool is already installed.
- Regenerate the initramfs file.
dracut -f
The initramfs file helps the Linux kernel to access drivers on external storage devices.
- Check the information of the /dev/vda disk.
lsblk
[root@ecs-test-0002 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 100G 0 disk ├vda1 253:1 0 40G 0 part / vdb 253:16 0 100G 0 disk ├vdb1 253:17 0 100G 0 part /mnt/sdc
We can see that the /dev/vda system disk has the /dev/vda1 partition, then the disk is expanded to 100 GiB, and the additional space is not allocated. So, /dev/vda has 100 GiB, and /dev/vda1 has 40 GiB.
- Restart the server.
reboot
Reconnect to the server after it is restarted.
- Check the information of the /dev/vda disk.
lsblk
[root@ecs-test-0002 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 100G 0 disk ├vda1 253:1 0 100G 0 part / vdb 253:16 0 100G 0 disk ├vdb1 253:17 0 100G 0 part /mnt/sdc
We can now see that /dev/vda has 100 GiB and /dev/vdb1 also has 100 GiB.
Originally, data disk /dev/vdb has 100 GiB and one partition /dev/vdb1, and then the disk is expanded to 150 GiB. The following example shows you how to use fdisk to allocate the additional 50 GiB to a new partition (/dev/vdb2).
- Check the information of the /dev/vdb disk.
- Check disk partition sizes.
lsblk
[root@ecs-test-0001 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk └vda1 253:1 0 40G 0 part / vdb 253:16 0 150G 0 disk └vdb1 253:17 0 100G 0 part /mnt/sdc
We can see that the /dev/vdb data disk has the /dev/vdb1 partition, then 50 GiB is added to the disk, and the additional 50 GiB is not allocated. So, /dev/vdb has 150 GiB, and /dev/vdb1 has 100 GiB.
- Check the disk partition style.
p
[root@ecs-test-0001 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 161GiB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size File system Name Flags 1 1049kB 107GiB 107GiB ext4 /dev/vdb1 (parted)
In this example, the disk uses MBR.
Enter q and press Enter to exit parted.
- If Partition Table: msdos is returned, the partition style is MBR.
- If Partition Table: gpt is returned, the partition style is GPT.
- If Partition Table: loop is returned, the disk is not partitioned (the entire disk is partitioned into one partition), and only a file system is created.
- Check disk partition sizes.
- Use the additional space to create a second primary partition /dev/vdb2 on the /dev/vdb disk.
- Create the partition.
n
p[root@ecs-test-0001 ~]# fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x38717fc1. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (2-4, default 2):
Partition type shows that there are two types of partitions. Choosing p creates a primary partition and choosing e creates an extended partition.
Partition number indicates the serial number of the primary partition. Because partition number 1 has been used, the value ranges from 2 to 4.
MBR supported up to four primary partitions or three primary partitions plus one extended partition.
The number of logical partitions allowed in the extended partition is not limited, so theoretically you can create as many logical partitions as you want. If you need five or more partitions, use the "primary partitions + one extended partition" model and then create logical partitions in the extended partition.
- Enter 2 as the primary partition number and view the first sector range.
Partition number (2-4, default 2): 2 First sector (83886080-209715199, default 83886080):
First sector shows the first sector range. The value ranges from 83886080 to 209715199, and the default value is 83886080.
- Press Enter to use the default first sector and then press Enter to use the default last sector.
First sector (83886080-209715199, default 83886080): using default value 83886080 Last sector, +sectors or +size{K,M,G} (83886080-209715199, default 209715199): using default value 209715199 Partition 2 of type Linux and of size 40 GB is set Command (m for help):
Last sector shows the last sector range. The value ranges from 83886080 to 209715199, and the default value is 209715199.
If you want to create two or more partitions, calculate the first and last sectors of the partitions as follows:
Assume that the /dev/vdb data disk has 100 GiB, and you are going to partition it into two primary partitions, first primary partition /dev/vdb1 (40 GiB) and second primary partition /dev/vdb2 (60 GiB).
Based on the facts that Capacity = Sectors value x 512 bytes and 1 GiB = 1073741824 bytes, the sector value can be calculated using Sectors value = Capacity/512 bytes.- Sector value of the data disk /dev/vdb (100 GiB) is 209715200 (100 x 1073741824/512), so the disk's last sector is 209715199 (209715200 – 1).
In the preceding example, First sector (2048-209715199, default 2048) means that the first sector of the disk ranges from 2048 to 209715199.
- Sector value of the first primary partition /dev/vdb1 (40 GiB) is 83886080 (40 x 1073741824/512), so the partition's last sector is 83886079 (83886080 – 1).
In this example, the default first sector is used as first sector of this partition, which is 2048.
- Sector value of the second primary partition /dev/vdb2 (60 GiB) is 125829120 (60 x 1073741824/512), so the partition's last sector is 125829119 (125829120 – 1).
First sector = Last sector of /dev/vdb1 + 1 = 83886079 + 1 = 83886080
Last sector = First sector + Sector value – 1 = 83886080 + 125829120 – 1 = 209715199
- Sector value of the data disk /dev/vdb (100 GiB) is 209715200 (100 x 1073741824/512), so the disk's last sector is 209715199 (209715200 – 1).
- Create the partition.
- Check the size and partition style of the new partition.
- Enter p and press Enter to print details of the /dev/vdb2 partition.
Command (m for help): p Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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 Disk label type: dos Disk identifier: 0x994727e5 Device Boot Start End Blocks Id System /dev/vdb1 2048 83886079 41942016 83 Linux /dev/vdb2 83886080 209715199 62914560 83 Linux Command (m for help):
- Enter w and press Enter to write the changes to the partition table.
In case that you want to discard the changes made before, you can exit fdisk by entering q and press Enter. Then, re-create the partition.
- Synchronize the new partition table to the OS.
If error message -bash: partprobe: command not found is returned, the system cannot identify the command. In this case, run yum install -y parted to install the command. Then run the command again.
- If the following error information is displayed, enter Fix.
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?
The GPT partition table information is stored at the start of the disk. To reduce the risk of damage, a backup of the information is saved at the end of the disk. When you extend the disk, the end of the disk changes accordingly. In this case, enter Fix to move the backup file of the information to the new disk end.
- If the following warning information is displayed, enter Fix.
Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600 blocks) or continue with the current setting? Fix/Ignore? Fix
After you enter Fix, the system automatically sets the GPT partition style for the additional space.
- Enter p and press Enter to print details of the /dev/vdb2 partition.
- Create an ext4 file system on the /dev/vdb2 partition.
mkfs -t ext4 /dev/vdb2
It takes some time to create a file system. Observe the system running status and do not exit.
[root@ecs-test-0001 ~]# mkfs -t ext4 /dev/vdb2 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 2621440 inodes, 10485504 blocks 524275 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2157969408 320 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Run parted /dev/vdb and enter p to check the file system format.
[root@ecs-test-0001 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 107GiB 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 2 42.9GB 107GB 64.4GB primary ext4 (parted) q [root@ecs-test-0001 ~]#
Enter q and press Enter to exit parted.
An ext4 file system is created for the /dev/vdb2 partition.
- Create a directory (mount point) and mount the new partition on the created mount point.
mkdir -p /mnt/sdd
mount /dev/vdb2 /mnt/sdd
lsblk
View the mount results.[root@ecs-test-0001 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├vda1 253:1 0 40G 0 part / vdb 253:16 0 150G 0 disk ├vdb1 253:17 0 100G 0 part /mnt/sdc ├vdb2 253:18 0 50G 0 part /mnt/sdd
You should now see that partition /dev/vdb2 is mounted on /mnt/sdd.
- Use the partition UUID to configure auto mount at startup.
- If device names are used to identify disks in the /etc/fstab file, your server may fail to run after reboot. This is because device names are assigned dynamically and may change (for example, from /dev/vdb1 to /dev/vdb2) after a stop or start.
- UUIDs are the unique character strings for identifying partitions in Linux.
- Query the UUID of the /dev/vdb2 partition.
blkid /dev/vdb2
[root@ecs-test-0001 ~]# blkid /dev/vdb2 /dev/vdb2: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"
The UUID of /dev/vdb2 is 0b3040e2-1367-4abb-841d-ddb0b92693df.
- Configure auto mount at startup.
Press i to enter editing mode, move the cursor to the end of the file, press Enter, and add the partition information.
UUID=0b3040e2-1367-4abb-841d-ddb0b92693df /mnt/sdd ext4 defaults 0 2
Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
Table 2 Parameter description Example Value
Description
UUID=0b3040e2-1367-4abb-841d-ddb0b92693df
The UUID of the partition.
/mnt/sdc
The mount point of the partition.
ext4
The file system format of the partition.
defaults
The partition mount option. Normally, this parameter is set to defaults.
0
- The Linux dump backup option.
- 0: Linux dump backup is not used. Usually, dump backup is not used, and you can set this parameter to 0.
- 1: Linux dump backup is used.
2
- The fsck option, which means whether to use fsck to check the disk during startup.
- 2: The check starts from the partitions whose mount points are non-root directories. / is the root directory.
- 1: The check starts from the partitions whose mount points are root directories.
- 0: The fsck option is not used.
- The Linux dump backup option.
- Verify that auto mount takes effect.
umount /dev/vdb2
mount -a
The system reloads all the content in the /etc/fstab file.
Query file system mounting information.
mount | grep /mnt/sdd
If information similar to the following is displayed, auto mount has taken effect:
root@ecs-test-0001 ~]# mount | grep /mnt/sdd /dev/vdb2 on /mnt/sdd type ext4 (rw,relatime,data=ordered)
Originally, data disk /dev/vdb has 2 TiB and one partition /dev/vdb1, and then the disk is expanded to 3 TiB. The following example shows you how to use parted to allocate the additional 1 TiB to a new GPT partition (/dev/vdb2).
- Check the information of the /dev/vdb disk.
- Check disk partition sizes.
lsblk
[root@ecs-test-0001 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk └vda1 253:1 0 40G 0 part / vdb 253:16 0 3T 0 disk └vdb1 253:17 0 2T 0 part /mnt/sdc
We can see that the /dev/vdb data disk has the /dev/vdb1 partition, then 1 TiB is added to the disk, and the additional space is not allocated. So, /dev/vdb has 3 TiB, and /dev/vdb1 has 2 TiB.
- Check the disk partition style.
p
[root@ecs-test-0001 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 3299GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2199GB 2199GB ext4 /dev/vdb1 (parted)
In this example, the disk uses GPT.
Enter q and press Enter to exit parted.
- If Partition Table: msdos is returned, the partition style is MBR.
- If Partition Table: gpt is returned, the partition style is GPT.
- If Partition Table: loop is returned, the disk is not partitioned (the entire disk is partitioned into one partition), and only a file system is created.
- Check disk partition sizes.
- Create a new partition /dev/vdb2 on the /dev/vdb disk.
- Create the /dev/vdb2 partition.
parted /dev/vdb
unit s
p
[root@ecs-centos74 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) unit s (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 6442450944s Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 2048s 4294965247s 4294963200s ext4 /dev/vdb1 (parted)
Take note of the last sector of the /dev/vdb1 partition, which is 4294965247s.
- If error message -bash: parted: command not found is returned, the system cannot identify the command. In this case, run yum install -y parted to install the command. Then run the command again.
- If the following error information is displayed, enter Fix.
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)? Fix/Ignore/Cancel?
The GPT partition table information is stored at the start of the disk. To reduce the risk of damage, a backup of the information is saved at the end of the disk. When you extend the disk, the end of the disk changes accordingly. In this case, enter Fix to move the backup file of the information to the new disk end.
- If the following warning information is displayed, enter Fix.
Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600 blocks) or continue with the current setting? Fix/Ignore?
After you enter Fix, the system automatically sets the GPT partition style for the additional space.
- Set the partition name and size.
mkpart /dev/vdb2 4294965248s 100%
p
In the command, 4294965248s is the first sector of this partition, which is the last sector of the /dev/vdb1 partition plus one, and 100% sets the last sector of this partition, which means to use 100% of the disk remaining space for /dev/vdb2.
Enter q and press Enter to exit parted.
- Check the /dev/vdb2 partition.
lsblk
[root@ecs-centos74 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├─vda1 253:1 0 40G 0 part / vdb 253:16 0 3T 0 disk ├─vdb1 253:17 0 2T 0 part /mnt/sdc ├─vdb2 253:18 0 1T 0 part
- Create the /dev/vdb2 partition.
- Create an ext4 file system on the /dev/vdb2 partition.
mkfs -t ext4 /dev/vdb2
It takes some time to create a file system. Observe the system running status and do not exit.
[root@ecs-test-0001 ~]# mkfs -t ext4 /dev/vdb2 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 67108864 inodes, 268435456 blocks 13421772 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2415919104 8192 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@ecs-test-0001 ~]#
Run parted /dev/vdb and enter p to check the file system format.
[root@ecs-test-0001 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Virtio Block Device (virtblk) Disk /dev/vdb: 3299GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2199GB 2199GB ext4 /dev/vdb1 2 2199GB 3299GB 1100GB ext4 /dev/vdb2 (parted) q [root@ecs-test-0001 ~]#
Enter q and press Enter to exit parted.
- Create a directory (mount point) and mount the new partition on the created mount point.
mkdir -p /mnt/sdc
mount /dev/vdb1 /mnt/sdc
lsblk
[root@ecs-test-0001 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├vda1 253:1 0 40G 0 part / vdb 253:16 0 3T 0 disk ├vdb1 253:17 0 2T 0 part /mnt/sdc ├vdb2 253:18 0 1T 0 part /mnt/sdd
You should now see that partition /dev/vdb2 is mounted on /mnt/sdd.
- Use the partition UUID to configure auto mount at startup.
- If device names are used to identify disks in the /etc/fstab file, your server may fail to run after reboot. This is because device names are assigned dynamically and may change (for example, from /dev/vdb1 to /dev/vdb2) after a stop or start.
- UUIDs are the unique character strings for identifying partitions in Linux.
- Query the UUID of the /dev/vdb2 partition.
blkid /dev/vdb2
[root@ecs-test-0001 ~]# blkid /dev/vdb2 /dev/vdb2: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"
The UUID of /dev/vdb2 is 0b3040e2-1367-4abb-841d-ddb0b92693df.
- Configure auto mount at startup.
Press i to enter editing mode, move the cursor to the end of the file, press Enter, and add the partition information.
UUID=0b3040e2-1367-4abb-841d-ddb0b92693df /mnt/sdd ext4 defaults 0 2
Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
Table 3 Parameter description Example Value
Description
UUID=0b3040e2-1367-4abb-841d-ddb0b92693df
The UUID of the partition.
/mnt/sdc
The mount point of the partition.
ext4
The file system format of the partition.
defaults
The partition mount option. Normally, this parameter is set to defaults.
0
- The Linux dump backup option.
- 0: Linux dump backup is not used. Usually, dump backup is not used, and you can set this parameter to 0.
- 1: Linux dump backup is used.
2
- The fsck option, which means whether to use fsck to check the disk during startup.
- 2: The check starts from the partitions whose mount points are non-root directories. / is the root directory.
- 1: The check starts from the partitions whose mount points are root directories.
- 0: The fsck option is not used.
- The Linux dump backup option.
- Verify that auto mount takes effect.
umount /dev/vdb2
mount -a
The system reloads all the content in the /etc/fstab file.
Query file system mounting information.
mount | grep /mnt/sdd
If information similar to the following is displayed, auto mount has taken effect:
root@ecs-test-0001 ~]# mount | grep /mnt/sdd /dev/vdb2 on /mnt/sdd type ext4 (rw,relatime,data=ordered)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.