Initializing a Linux Data Disk Greater Than 2 TB (parted)
Scenarios
This section uses CentOS 7.4 64bit to describe how to use parted to initialize a data disk whose capacity is greater than 2 TB. In the following operations, the capacity of the example disk is 3 TB.
The maximum disk capacity supported by MBR is 2 TB, and that supported by GPT is 18 EB. Therefore, use the GPT partition style if your disk capacity is greater than 2 TB. In Linux OSs, if the GPT partition style is used, the fdisk partitioning tool cannot be used. The parted partitioning tool must be used. For details about disk partition styles, see Introduction to Data Disk Initialization Scenarios and Partition Styles.
The method for initializing a disk varies depending on the OSs running on the BMS. This document is for reference only. For detailed operations and differences, see the product documents of the OSs running on the corresponding BMSs.
When using an EVS disk for the first time, if you have not initialized the disk, including creating partitions and file systems, the additional capacity added to the disk in a later expansion operation may not be normally used.
Prerequisites
- You have logged in to the BMS.
- A data disk has been attached to the BMS and has not been initialized.
Creating Partitions and Attaching a Disk
The following example shows how to use parted to create a partition on a new data disk that has been attached to the BMS. The default partitioning style is GPT and the default file system format is ext4. Mount the file system to /mnt/sdc, and configure automatic mounting upon system start.
- Run the following command to query information about the added data disk:
lsblk
Information similar to the following is displayed:
[root@bms-centos74 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├─vda1 253:1 0 1G 0 part /boot └─vda2 253:2 0 39G 0 part / vdb 253:16 0 3T 0 disk
The command output shows that the BMS has two disks, system disk /dev/vda and data disk /dev/vdb.
- Run the following command to enter parted to partition the added data disk:
parted Added data disk
In this example, /dev/vdb is the newly added data disk.
parted /dev/vdb
Information similar to the following is displayed:
[root@bms-centos74 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
- Enter p and press Enter to view the current disk partition style.
Information similar to the following is displayed:
(parted) p Error: /dev/vdb: unrecognised disk label Model: Virtio Block Device (virtblk) Disk /dev/vdb: 3299GB Sector size (logical/physical): 512B/512B Partition Table: unknown Disk Flags: (parted)
In the command output, the Partition Table value is unknown, indicating that the disk partition style is unknown.
- Run the following command to set the disk partition style:
mklabel Disk partition style
The disk partition style can be MBR or GPT. If the disk capacity is greater than 2 TB, choose the GPT partition style.
mklabel gpt
The maximum disk capacity supported by MBR is 2 TB, and that supported by GPT is 18 EB. Because a data disk currently supports up to 32 TB, use the GPT partition style if your disk capacity is larger than 2 TB.
If you change the disk partition style after the disk has been used, the original data on the disk will be cleared. Therefore, select a proper disk partition style when initializing the disk.
- Enter p and press Enter to view the disk partition style.
Information similar to the following is displayed:
(parted) mklabel gpt (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 (parted)
- Enter unit s and press Enter to set the measurement unit of the disk to sector numbers.
- Enter mkpart opt 2048s 100% and press Enter.
In this example, one partition is created for the added data disk. Variable 2048s indicates the disk start capacity, and variable 100% indicates the disk end capacity. The two values are used for reference only. You can determine the number of partitions and the partition capacity based on your service requirements.
Information similar to the following is displayed:(parted) mkpart opt 2048s 100% Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? Cancel
If the preceding warning message is displayed, enter Cancel to stop the partitioning. Then, find the first sector with the best disk performance and use that value to partition the disk. In this example, the first sector with the best disk performance is 2048s. Therefore, the system does not display the warning message.
- Enter p and press Enter to view the details about the created partition.
Information similar to the following is displayed:
(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 6442448895s 6442446848s opt
Details about the dev/vdb1 partition are displayed.
- Enter q and press Enter to exit parted.
- Run the following command to view the disk partition information:
lsblk
Information similar to the following is displayed:
[root@bms-centos74 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├─vda1 253:1 0 1G 0 part /boot └─vda2 253:2 0 39G 0 part / vdb 253:16 0 3T 0 disk └─vdb1 253:17 0 3T 0 part
In the command output, /dev/vdb1 is the partition you created.
- Run the following command to set the format for the file system of the newly created partition:
mkfs -t File system format /dev/vdb1
For example, run the following command to set the ext4 file system for the /dev/vdb1 partition:
mkfs -t ext4 /dev/vdb1
Information similar to the following is displayed:
[root@bms-centos74 ~]# mkfs -t ext4 /dev/vdb1 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 201326592 inodes, 805305856 blocks 40265292 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2952790016 24576 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, 512000000, 550731776, 644972544 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
The formatting takes a period of time. Observe the system running status and do not exit.
The partition sizes supported by file systems vary. Therefore, you are advised to choose an appropriate file system based on your service requirements.
- Run the following command to create a mount point:
mkdir Mount point
For example, run the following command to create the /mnt/sdc mount point:
mkdir /mnt/sdc
- Run the following command to mount the new partition on the created mount point:
mount /dev/vdb1 Mount point
For example, run the following command to mount the newly created partition on /mnt/sdc:
mount /dev/vdb1 /mnt/sdc
- Run the following command to view the mount result:
df -TH
Information similar to the following is displayed:
[root@bms-centos74 ~]# df -TH Filesystem Type Size Used Avail Use% Mounted on /dev/vda2 ext4 42G 1.5G 38G 4% / devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs tmpfs 2.0G 8.9M 2.0G 1% /run tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/vda1 ext4 1.1G 153M 801M 17% /boot tmpfs tmpfs 398M 0 398M 0% /run/user/0 /dev/vdb1 ext4 3.3T 93M 3.1T 1% /mnt/sdc
In the command output, the newly created dev/vdb1 partition has been mounted on /mnt/sdc.
Setting Automatic Disk Mounting at System Start
To automatically attach a disk when a BMS starts, you should not specify its partition, for example /dev/vdb1, in /etc/fstab. This is because the sequence of cloud devices may change during the BMS stop and start, for example, /dev/vdb1 may change to /dev/vdb2. You are advised to use the UUID in /etc/fstab to automatically attach a disk at system start.
The universally unique identifier (UUID) is the unique character string for disk partitions in a Linux system.
- Run the following command to query the partition UUID:
blkid Disk partition
For example, run the following command to query the UUID of /dev/vdb1:
blkid /dev/vdb1
Information similar to the following is displayed:
[root@bms-centos74 ~]# blkid /dev/vdb1 /dev/vdb1: UUID="bdd29fe6-9cee-4d4f-a553-9faad281f89b" TYPE="ext4" PARTLABEL="opt" PARTUUID="c7122c92-ed14-430b-9ece-259920d5ee74"
In the command output, the UUID of /dev/vdb1 is displayed.
- Run the following command to open the fstab file using the vi editor:
vi /etc/fstab
- Press i to enter the editing mode.
- Move the cursor to the end of the file and press Enter. Then add the following information:
UUID=bdd29fe6-9cee-4d4f-a553-9faad281f89b /mnt/sdc ext4 defaults 0 2
- Press Esc, enter :wq, and press Enter.
The system saves the configurations and exits the vi editor.
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