Physical Server

Initializing Linux-based Data Disks (parted)

2024-12-16 09:13:35

Scenario

This topic uses CentOS 7.6 64-bit as an OS example for the physical server to describe how to use the parted partitioning tool to set partitions for a data disk.

Note:

The formatting operation may differ depending on the operating system of the server. For more information on steps and differences, refer to the respective OS documentation.

Before You Begin

l  You have logged in to the physical server.

l  A data disk is mounted to the physical server and this data disk is not initialized.

Partitioning and Mounting Disks

This action takes the scenario as an example. If a new data disk is mounted to a physical server, the parted partitioning tool is used to set a partition for the data disk. The partition form is set to GPT and the file system is set to ext4 format and is mounted in /mnt/sdc, and Mount Automatically Upon Startup is enabled.

Operation Steps

1.       Run the following command to view the newly added data disk.

lsblk

The following information is returned:

[root@test-sharedDisk ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    252:0    0  100G  0 disk
├─vda1 252:1    0    1G  0 part
├─vda2 252:2    0    3G  0 part /boot/efi
├─vda3 252:3    0    5G  0 part /boot
├─vda4 252:4    0   80G  0 part /
└─vda5 252:5    0   10G  0 part
vdc    252:32   0   30G  0 disk

This indicates that the current server has two disks. /dev/vda is a system disk, and /dev/vdc is a newly added data disk.

2.         Run the following command to start the fdisk partitioning tool and plan the partitions of the newly added data disk.

Adding Data Disks Using parted

Take the newly mounted data disk "/dev/vdc" as an example:

parted /dev/vdc

The following information is returned:

[root@test-sharedDisk ~]# parted /dev/vdc
GNU Parted 3.1
Using /dev/vdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

3.       Type "p" and press Enter to view the partition form of the current disk.

The following information is returned:

(parted) pError:   /dev/vdc: unrecognised disk labelModel:   Virtio Block Device (virtblk)Disk   /dev/vdc: 32.2GBSector size   (logical/physical): 512B/512BPartition   Table: unknownDisk Flags:(parted)    

If Partition Table is unknown, the partition form is unknown.

4.       Enter the following command to set the disk partition form.

mklabel Disk Partition Form

The disk partition form includes MBR and GPT. Here GPT is taken as an example:

mklabel gpt

        Note:

l   The MBR supports a maximum disk capacity of 2 TB, the GPT supports a maximum disk capacity of 18 EB, and the current data disk supports a maximum disk capacity of 32 TB. If you want to use a disk capacity larger than 2 TB, use GPT as a partition form.

l   When a disk is in use, the original data on the disk will be cleared if the partition form is changed. Therefore, exercise caution with selecting a disk partition form when initializing the disk.

5.       Type "p" and press Enter to view the partition form after setting the partition form.

The following information is returned:

(parted) mklabel gpt(parted) pModel: Virtio Block   Device (virtblk)Disk /dev/vdc: 32.2GBSector size   (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number  Start    End  Size  File system    Name  Flags (parted)    

6.         Type "unit s" and press Enter to set the unit of measurement of the disk to cylinder.

The following information is returned:

7.         For example, to create a partition for the whole disk, type "mkpart opt 2048s 100%" and press Enter.

2048s indicates the start disk capacity and 100% indicates the end disk capacity. The specification here is for reference only. You can choose the right specification according to your business needs.

The following information is returned:

Note:

If "Warning: The resulting partition is not properly aligned for best performance.Ignore/Cancel? Ignore" performance optimization reminder is displayed, please enter "Ignore" to ignore this warning.

8.         Type "p" and press Enter to view the detailed information of the newly created partition.

The following information is returned:

(parted) pModel: Virtio Block   Device (virtblk)Disk /dev/vdc: 32.2GBSector size   (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number  Start     End     Size    File system  Name    Flags 1        1049kB  32.2GB  32.2GB               opt (parted)    


This indicates the detailed information of the newly created partition "/dev/vdc1".

9.       Type "q" and press Enter to exit the parted partitioning tool.

(parted) q
Information: You may need to update /etc/fstab.

10.       Run the following command to view the information of the disk partition.

Lsblk

The following information is returned:

[root@test-sharedDisk   ~]# lsblkNAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINTvda    252:0      0  100G  0 disk├─vda1 252:1    0      1G  0 part├─vda2 252:2    0      3G  0 part /boot/efi├─vda3 252:3    0      5G  0 part /boot├─vda4 252:4    0     80G  0 part /└─vda5 252:5    0     10G  0 partvdc    252:32     0   30G  0 disk└─vdc1 252:33   0     30G  0 part    

In this case, you can view the newly created partition "/dev/vdc1"

11.         Run the following command to set the newly created partition file system as the desired format.

mkfs -t file system format /dev/vdc1

Take setting the file system as "ext4" as an example:

mkfs -t ext4 /dev/vdc1

The following information is returned:

[root@test-sharedDisk   ~]# mkfs -t ext4 /dev/vdc1mke2fs 1.42.9   (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096   (log=2)Stride=0 blocks, Stripe   width=0 blocks1966080 inodes, 7863808   blocks393190 blocks (5.00%)   reserved for the super userFirst data block=0Maximum filesystem blocks=2155872256240 block groups32768 blocks per group,   32768 fragments per group8192 inodes per groupSuperblock backups   stored on blocks:        32768, 98304, 163840, 229376, 294912,   819200, 884736, 1605632, 2654208,        4096000 Allocating group tables:   doneWriting inode tables:   doneCreating journal (32768   blocks): doneWriting superblocks and   filesystem accounting information: done    

The formatting process takes a while. Observe the running status of the system and do not quit.

        Note:

The partition size differs depending on the file system. Please select an appropriate file system according to your business needs.

12.         Run the following command to create a mount point.

mkdir Mount Point

Take creating the mount point "/mnt/ndc" as an example:

mkdir /mnt/ndc

13.         Run the following command to mount the newly created partition to the newly created mount point in Step 12.

mount /dev/vdc1 Mount Point

Take mounting the newly created partition to "/mnt/ndc" as an example:

mount /dev/vdc1 /mnt/ndc

[root@test-sharedDisk ~]# mkdir /mnt/ndc
[root@test-sharedDisk ~]# mount /dev/vdc1 /mnt/ndc

14.         Run the following command to view the mount result.

df -TH

The following information is returned:

[root@test-sharedDisk   ~]# df -THFilesystem     Type        Size  Used Avail Use% Mounted on/dev/vda4      xfs        86G    4.2G   82G   5% /devtmpfs       devtmpfs  271G       0  271G   0% /devtmpfs          tmpfs     271G       0  271G   0% /dev/shmtmpfs          tmpfs     271G     21M  271G   1% /runtmpfs          tmpfs     271G       0  271G   0% /sys/fs/cgroup/dev/vda3      ext2      5.3G    184M  4.9G   4% /boot/dev/vda2      vfat      3.3G     11M  3.3G   1% /boot/efitmpfs          tmpfs      55G       0   55G   0% /run/user/0/dev/vdb1      ext4       32G     47M   30G   1% /mnt/sdc/dev/vdc1      ext4       32G     47M   30G   1% /mnt/ndc    

This indicates that the newly created partition /dev/vdc1 is mounted to /mnt/ndc.

Setting Automatic Disk Mounting upon Startup

Scenario

If you want to automatically mount disks when the server system starts, do not specify /dev/vdc1 in /etc/fstab because the sequential encoding of devices on the cloud may change when the server stops or starts. For example, /dev/vdc may change to /dev/vde. We recommend that you use UUID to configure automatic disk mounting.

        Note:

The Universally Unique Identifier (UUID) of a disk is the universally unique string that the Linux system provides for disk partitions.

Operation Steps

1.         Run the following command to query the UUID of the disk partition.

blkid Disk Partition

Take querying the UUID of the disk partition "/dev/vdb1" as an example:

blkid /dev/vdc1

The following information is returned:

[root@test-sharedDisk   ~]# blkid /dev/vdc1/dev/vdc1:   UUID="e89d4e92-ca22-4d10-a0ac-4a0606282cb1" TYPE="ext4"   PARTLABEL="opt"   PARTUUID="b95a3897-acf2-4037-a19c-d818744f1579"    

2.         Run the following command to open the "fstab" file using the vi editor.

vi /etc/fstab

3.         Press "i" to enter the Edit mode.

4.         Move the cursor to the end of the file and press Enter to add the following content: UUID=e89d4e92-ca22-4d10-a0ac-4a0606282cb1 /mnt/ndc ext4 defaults 0 2

UUID=3C27-7C31   /boot/efi vfat defaults 0 0UUID=d257ff0f-c5e1-4d90-af3a-de94720d90fe   /boot ext2 defaults 0 0UUID=9136110f-0c77-4174-9870-e8243dbe2662   / xfs defaults 0 1UUID=e89d4e92-ca22-4d10-a0ac-4a0606282cb1   /mnt/ndc ext4 defaults 0 2    

5.         Press ESC, type :wq and press Enter to save the settings and exit the editor.


LRjzYiLAlcM6