Scenario
This topic uses CentOS 7.6 64-bit as an example to describe how to use the fdisk partitioning tool to set partitions for a data disk. The information returned is for reference only.
Before You Begin
A data disk is attached to a cloud server or dedicated physical server and this data disk is not initialised.
Operation Steps
If the capacity of the new EVS is less than 2 TB, use the fdisk tool to initialise the Linux-based data disk in the following five steps:
Log in to the ECS
View the newly added data disk: Check whether the newly added data disk has been successfully attached to the cloud server and check its capacity.
Create an MBR partition: Create an independent logical partition for the newly added data disk to better organize and manage data.
Create and mount a file system: Create a file system for the new partition and use an independent file system to store data.
Set automatic disk mounting upon startup: The disk can be automatically mounted when the cloud server system starts.
Log in to the ECS
1. Log in to the console.
2. Click in the upper left corner of the console and select a Region. In this topic, China (Hong Kong 2) is selected.
3. Select Compute and click Elastic Cloud Server to go to the Cloud Server List page.
4. Locate the row that contains the cloud server for which the data disk is to be initialised, and in the Operation column, click Remote Login to log in to the cloud server. For more information, see Overview of Linux ECS Login.
Viewing the Newly Added Data Disk
Run the fdisk -l command to view the newly added data disk. The following information is returned:
The current cloud server has two disks, of which /dev/vda is the default system disk having a partition /dev/vda1 and /dev/vdb is the newly added data disk with a capacity of 40 GB to be initialised.
Creating an MBR Partition
This following section describes how to use the fdisk tool to create an MBR partition for the newly added data disk /dev/vdb.
1. Run the fdisk /dev/vdb command to access the fdisk partition tool. The following information is returned:
2. Type "n" and press Enter to create a new partition. The following information is returned:
3. The returned information shows that the disk has two partition types: "p" indicates a primary partition and e indicates an extended partition.
4. To create a primary partition, type "p" and press Enter. The following information is returned:
5. Partition number indicates the numbering of the primary partition. You can select a number ranging from 1 to 4.
6. As an example, when you select 1 as the partition number, you can type "1" as the primary partition number, and press Enter. The following information is returned:
7. "First sector" indicates the start cylinder area. The value can be between 2048 and 83886079 (2048 by default).
8. For example, select 2048, the default start cylinder number, and press Enter. The following information is returned:
"Last sector" indicates the end cylinder area. The value can be between 2048 and 83886079 (83886079 by default).
9. For example, select 83886079, the default end cylinder number, and press Enter. The following information is returned:
The partition has been created successfully and you have created a new partition for the 40 GB data disk.
10. Type "p" and press Enter to view the detailed information of the newly created partition. The following information is returned:
11. Type "w" and press Enter to write the partition result into the partition table. The following information is returned:
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. |
12. If the preceding information is displayed, partition /dev/vdb1 is created for disk /dev/vdb.
13. If an error occurs when you create a partition, you can type "q" to exit the fdisk partitioning tool, and the previous partition result will not be retained.
14. Run the partprobe command to synchronize the changes to the new partition table to the operating system.
Creating and Mounting a File System
1. Run the mkfs -t ext4 /dev/vdb1 command to create a file system for the newly created partition. In this example, an ext4 file system is created. Select an appropriate file system based on your business needs.
The formatting process takes a while. Do not quit the process before formatting is complete.
2. Run the mkdir /mnt/sdc command to create an attach point. In this example, /mnt/sdc is used as the attach point.
3. Run the mount /dev/vdb1 /mnt/sdc command to mount the newly created partition to the newly created mount directory.
4. Run the df -TH command to check the mount result. The following information is returned:
This indicates that the newly created partition /dev/vdb1 is mounted to /mnt/sdc.
Setting Automatic Disk Mounting upon Startup
If you want to automatically mount disks when the cloud server system starts, do not specify /dev/vdb1 in /etc/fstab because the sequential encoding of devices in the cloud may change when the cloud server stops or starts. For example, /dev/vdb1 may change to /dev/vdb2. We recommend that you use UUID to configure automatic disk mounting. The universally unique identifier (UUID) of a disk is the universally unique string that the Linux system provides for disk partitions.
1. Run the blkid /dev/vdb1 command to query the UUID of the disk partition. The following information is returned:
2. Run the vi /etc/fstab command to open the fstab file using the VI editor. Type "i" to go to the editing mode, move the cursor to the end of the file, and press Enter to add the following content. In the UUID= field, please enter the UUID you queried in the previous step, as shown in the figure:
3. Press ESC, type ":wq", and press Enter. Save settings and exit the editor.
4. To verify the automatic mounting function, unmount the mounted partition and run the umount /dev/vdb1 command, as shown in the figure:
5. Run mount –a to reload all the contents of the /etc/fstab file, as shown in the figure:
6. Run the mount |grep /mnt/sdc command to query the mount of the file system. The operations and returned information are shown in the following figure:
If the information shown in the figure is returned, the automatic disk mounting is successfully set.