Extending Partitions and File Systems Offline (Linux Data Disk)
Some Linux OSs of earlier versions do not support command-line utilities like growpart and resize2fs, so disk partitions and file systems cannot be extended online (while mounted). To solve this problem, you can extend them offline (unmounted). You first need to unmount the disk and then extend the partitions and file systems. This section describes how to extend Linux data disks offline.
Prerequisites
- You have expanded the EVS disk capacity and attached the disk to a server on the console. For details, see Step 1: Expand Disk Capacity.
- You have backed up the disk data using snapshots. This prevents data loss caused by misoperations. For how to back up data using snapshots, see Creating an EVS Snapshot.
- 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.
Checking the Partition Table Format and File System
- Check the partition table format and file system.
- Check the partition table format of the data disk.
In this example, the /dev/vdb data disk is formatted into the /dev/vdb1 partition. The command output is as follows:
Device Boot Start End Sectors Size Id Type /dev/vdb1 * 2048 83886046 83883999 40G 83 Linux
- If the value under Type is Linux, the data disk uses the MBR partition table format.
- If the value under Type is GPT, the data disk uses the GPT partition table format.
- Check the file system type of the partition.
[test@ecs-test-0001 ~]# blkid /dev/vdb1 /dev/vdb1: UUID="b9a07b7b-9322-4e05-ab9b-14b8050cd8cc" TYPE="ext4"
The value under TYPE indicates the file system type.
- Check the partition table format of the data disk.
- Check whether the file system status is normal.
If the file system status is abnormal, rectify the fault and then perform subsequent operations.
Table 1 Status check File System Type
Command
Status Description
ext*
sudo e2fsck -n /dev/vdb1
The file system status is normal if its value is clean.
xfs
sudo xfs_repair -n /dev/vdb1
btrfs
sudo btrfsck /dev/vdb1
- The file system status is normal if it contains "found xxxx bytes used err is 0".
- Select a method to extend the partitions and file systems.
Determine the operation based on the partition table format and file system information.
Expansion Scenario
Operations
The data disk has been partitioned, and a file system has been created.
- To extend an existing MBR partition of the data disk, see Extending an Existing MBR Partition.
- To create a new MBR partition on the data disk, see Creating a New MBR Partition.
- To extend an existing GPT partition of the data disk, see Extending an Existing GPT Partition.
- To create a new GPT partition on the data disk, see Creating a New GPT Partition.
The data disk is brand new, has not been partitioned, and has no file system created on.
Expand the disk capacity on the console. Then, perform operations by referring to Initializing EVS Data Disks.
The data disk is used as a raw device, has a file system created on, but is not partitioned.
Expand the disk capacity on the console. Then, perform operations by referring to Extending the File System on a Raw Device.
The data disk is not attached to any server.
Attach the data disk to a server. Then, complete the expansion by referring to operations provided in this document.
- The maximum disk capacity that MBR supports is 2 TiB, and the disk space in access of 2 TiB cannot be used. To prevent data loss, you are advised to create an EVS disk greater than 2 TiB, format it with GPT, and then copy data from the MBR partition to the new GPT partition.
- If the expansion fails due to an error of the formatting tool, you can upgrade the tool version in advance or uninstall the tool and reinstall it.
Extending an Existing MBR Partition
To prevent data loss, you are advised not to directly extend the partition or file system of an existing partition. Instead, unmount the partition, extend the partition and file system, and then remount the partition. The operation varies depending on the kernel version of the Linux server:
- If the kernel version is earlier than 3.6, unmount the partition, modify the partition table, and then extend the file system.
- If the kernel version is 3.6 or later, modify the partition table, notify the kernel to update the partition table, and then extend the file system.
- Modify the partition table.
- Check the partition information and take note of the start and end sectors of the desired partition.
[test@ecs-test-0001 ~]# sudo fdisk -lu /dev/vdb Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xedd8c529 Device Boot Start End Blocks Id System /dev/wdb1 2048 20971519 10484736 83 Linux
In this example, the start sector of /dev/vdb is 2048, and the end sector is 20971519.
- Check the data disk's mount information and then unmount the partition based on the returned information. Ensure that the partition is fully unmounted.
- Check the data disk's mount information.
- Unmount the partition.
- Check the operation result.
The command output is as follows:
[test@ecs-test-0001 ~]# mount | grep "/dev/vdb" /dev/vdb1 on /mnt type ext4 (rw,relatime,data=ordered) [test@ecs-test-0001 ~]# sudo umount /dev/vdb1 [test@ecs-test-0001 ~]# mount | grep "/dev/vdb"
- Use fdisk to delete the partition.
This operation may cause data loss. You are advised to back up data in advance.
sudo fdisk -u /dev/vdb
- Enter p and press Enter to print the partition table information.
- Enter d and press Enter to delete the partition table.
- Enter p and press Enter to check that the partition is deleted.
- Enter w and press Enter to write the partition result and exit.
[test@ecs-test-0001 ~]# sudo fdisk -u /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. Command (m for help): p Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b Device Boot Start End Blocks Id System /dev/vdb1 2048 41943039 20970496 83 Linux Command (m for help): d Selected partition 1 Partition 1 is deleted Command (m for help): p Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b Device Boot Start End Blocks Id System Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
- Use fdisk to create a new partition.
- Enter p and press Enter to print the partition table information.
- Enter n and press Enter to create a new partition.
- Enter p and press Enter to create a primary partition.
- Enter 1 and press Enter to set a partition number. Partition number 1 is used in this example.
- Use the default start sector and press Enter.
- Use the default end sector and press Enter.
- Enter w and press Enter to write the partition result and exit.
The following example shows how to use fdisk to extend the capacity of /dev/vdb1 from 20 GiB to 40 GiB:
[test@ecs-test-0001 ~]# sudo fdisk -u /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. Command (m for help): p Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x38717fc1 Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-83886079, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): Partition 1 of type Linux and of size 40 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
- Run either of the following commands to notify the kernel to read the partition table of the data disk:
- sudo partprobe /dev/vdb
- sudo partprobe /dev/vdb1
- Check the data disk information and ensure that the partition table is successfully updated.
- Check the file system again and ensure that the file system status is clean after the partition is extended.
sudo e2fsck -f /dev/vdb1
If the file system status is not clean, run the sudo e2fsck -n /dev/vdb1 command.
- Check the partition information and take note of the start and end sectors of the desired partition.
- Extend the file system.
- ext* file system (such as ext3 or ext4):
- xfs file system:
- Mount the partition on /mnt.
sudo mount /dev/vdb1 /mnt
- Resize the xfs file system.
- Mount the partition on /mnt.
- btrfs file system:
Creating a New MBR Partition
To allocate the additional space to a new MBR partition, perform the following steps in the server OS:
- Create a new partition.
sudo fdisk -u /dev/vdb
- Enter p and press Enter to print the partition table information.
- Enter n and press Enter to create a new partition.
- Enter p and press Enter to create a primary partition.
- Enter 2 and press Enter to set a partition number. Partition number 2 is used in this example.
- Use the default start sector and press Enter.
- Use the default end sector and press Enter.
- Enter w and press Enter to write the partition result and exit.
The following example shows how to use fdisk to allocate the additional 20 GiB to a new MBR partition /dev/vdb2:
[test@ecs-test-0001 ~]# sudo fdisk -u /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. Command (m for help): p Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bcb4e Device Boot Start End Blocks Id System /dev/vdb1 2048 41943039 20970496 83 Linux Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 First sector (41943040-83886079, default 41943040): Using default value 41943040 Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079): Using default value 83886079 Partition 2 of type Linux and of size 20 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. - Check the partition result.
lsblk /dev/vdb
- Create a file system.
- Check the file system information.
blkid /dev/vdb2
[test@ecs-test-0001 ~]# blkid /dev/vdb2/dev/vdb2: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"
- Mount the partition.
sudo mount /dev/vdb2 /mnt
- Check the space and usage of the data disk.
df -h
If information about the new file system is displayed, the mount is successful.
Extending an Existing GPT Partition
To allocate the additional space to an existing GPT partition, perform the following steps in the server OS:
- Check the data disk's mount information and then unmount the partition based on the returned information. Ensure that the partition is fully unmounted.
Check the mount information.
mount | grep "/dev/vdb"
Unmount the desired partition.
sudo umount /dev/vdb1
Check the operation result.
mount | grep "/dev/vdb"
The command output is as follows:
[test@ecs-test-0001 ~]# mount | grep "/dev/vdb" /dev/vdb1 on /mnt type ext4 (rw,relatime,data=ordered) [test@ecs-test-0001 ~]# sudo umount /dev/vdb1 [test@ecs-test-0001 ~]# mount | grep "/dev/vdb"
- Use parted to allocate space to the existing GPT partition.
- Enter the parted tool.
Enter help to find out parted's usage instructions if needed.
- Check the partition information and take note of the partition number as well as the start and end sectors of the existing partition.
If Fix/Ignore/Cancel? and Fix/Ignore? are displayed, enter Fix for both of them.
- Delete the existing partition. In this example, delete the partition whose partition number is 1.
- Re-create a primary partition. In this example, the start sector of the original partition is 1049kB, and all of the additional space is allocated to the new partition.
mkpart primary 1049kB 100%
- Check whether the new partition is created.
- Exit the Parted tool.
The following example shows how to use Parted to extend an existing GPT partition to 3299GB:
[test@ecs-test-0001 ~]# sudo parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print 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? 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 4294967296 blocks) or continue with the current setting? Fix/Ignore? Fix 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 1100GB 1100GB ext4 primary (parted) rm 1 (parted) mkpart primary 1049kB 100% (parted) print 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 3299GB 3299GB ext4 primary (parted) quit Information: You may need to update /etc/fstab.
- Enter the parted tool.
- Check the file system consistency.
sudo fsck -f /dev/vdb1
The command output is as follows:
[test@ecs-test-0001 ~]# sudo fsck -f /dev/vdb1 fsck from util-linux 2.23.2 e2fsck 1.43.5 (04-Aug-2017) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vdb1: 11/67108864 files (0.0% non-contiguous), 4265369/268434944 blocks
- Extend the file system.
- ext* file system (such as ext3 or ext4):
- xfs file system:
- Mount the partition on /mnt.
sudo mount /dev/vdb1 /mnt
- Resize the xfs file system.
- Mount the partition on /mnt.
- btrfs file system:
Creating a New GPT Partition
To allocate the additional space to a new GPT partition and use GPT thereafter, perform the following steps in the server OS: In the following example, the /dev/vdb data disk originally has 4.8 TiB and one partition /dev/vdb1. The disk is then expanded to 32 TiB. The following steps use parted to allocate the additional space to a new GPT partition /dev/vdb2.
- Check information about the existing partition on the data disk.
sudo fdisk -l
The command output is as follows:
[test@ecs-test-0001 ~]# sudo fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000b1b45 Device Boot Start End Blocks Id System /dev/vda1 * 2048 83875364 41936658+ 83 Linux WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/vdb: 35184.4 GB, 35184372088832 bytes, 68719476736 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: gpt Disk identifier: BCE92401-F427-45CC-8B0D-B30EDF279C2F # Start End Size Type Name 1 2048 10307921919 4.8T Microsoft basic mnt
- Use parted to create a new partition and allocate space to the new partition.
- Enter the parted tool.
- Check the space to be allocated and take note of the sectors and size of the existing partition.
In this example, the start sector of /dev/vdb1 is 1049kB, the end sector is 5278GB, and the size is 5278 GiB.
(parted) print free Model: Virtio Block Device (virtblk) Disk /dev/vdb: 35.2TB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 17.4kB 1049kB 1031kB Free Space 1 1049kB 5278GB 5278GB ext4 mnt 5278GB 35.2TB 29.9TB Free Space - Set the start sector and allocate space for the new partition. In this example, create the /dev/vdb2 partition and name it test. Use the original partition's start sector 5278GB as the start sector and allocate all of the additional space to the new partition.
mkpart test 5278GB 100%
- Check whether the capacity (value under Size) changes.
print
The command output is as follows:
(parted) print Model: Virtio Block Device (virtblk) Disk /dev/vdb: 35.2TB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 5278GB 5278GB ext4 mnt 2 5278GB 35.2TB 29.9TB test
- Exit the Parted tool.
- Create a file system for the new partition.
- Check the changes on the partition size.
sudo fdisk -l
- Check the file system type on the storage device.
blkid
- Mount the new partition.
sudo mount /dev/vdb2 /mnt
Extending the File System on a Raw Device
If no partition but only a file system is created on a data disk, perform the following steps to extend the file system:
- Check the file system type on the storage device.
df -Th
In the command put, the value under Type indicates the file system type.
- Run the corresponding command to extend the file system based on the file system type.
- xfs file systems:
Run the xfs_growfs command to extend the file system.
sudo xfs_growfs /mnt
In the command, /mnt is the mount point of the file system.
The xfs_growfs use mount points to identify devices, for example, xfs_growfs /mnt. You can run xfs_growfs --help to find out the usage of xfs_growfs of different versions.
- ext* and btrfs file systems:
- Check the data disk's mount information.
- Unmount the data disk.
- Check the operation result.
The command output is as follows:
[test@ecs-test-0001 ~]# mount | grep "/dev/vdb" [test@ecs-test-0001 ~]# sudo umount /dev/vdb [test@ecs-test-0001 ~]# mount | grep "/dev/vdb"
- Extend the file system.
- Mount the disk on a mount point.
- xfs file systems:
- Check the capacity expansion result of the data disk.
df -Th
If the file system has been extended, the expansion is successful.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot