Physical Server

Initializing Linux-based Data Disks

2024-12-16 09:02:08

Scenario

This topic uses CentOS 7.6 64-bit as an OS example for the physical server to describe how to use the fdisk 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 fdisk partitioning tool is used to set the data disk as the primary partition. The partition form is set to MBR by default, and the file system is set to ext4 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.

fdisk -l

The following information is returned:

[root@test-sharedDisk ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/vda: 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: gpt
Disk identifier: 942EF8CC-BD4F-4346-9713-78E8EB355090


#         Start          End    Size  Type            Name
1      2097152      4194303      1G  BIOS boot       primary
2      4194304     10485759      3G  Linux filesyste primary
3     10485760     20971519      5G  Linux filesyste primary
4     20971520    188743679     80G  Linux filesyste primary
5    188743680    209713151     10G  Linux filesyste primary

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 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

This indicates that the current server has two disks. /dev/vda is a system disk, and /dev/vdb 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 a Data Disk Using fdisk

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

fdisk /dev/vdb

The following information is returned:

[root@test-sharedDisk ~]# 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 0x59ac6ad9.

Command (m for help):

3.       Type "n" and press Enter to create a new partition.

The following information is returned:

Command (m   for help): nPartition   type:p   primary (0 primary, 0 extended, 4 free)e   extendedSelect   (default p):    

This indicates that there are two partition types:

l  "p" indicates a primary partition.

l  "e" indicates an extended partition.

4.       For example, to create a primary partition, type "p" and press Enter.

The following information is returned:

Select (default p): p
Partition number (1-4, default 1): 1

Partition number indicates the numbering of the primary partition. You can select a number between 1 and 4.

5. 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:

Partition number (1-4, default 1): 1
First sector (2048-62914559, default 2048):

"First sector" indicates the start cylinder area. The value can be between 2048 and 62914559 (2048 by default).

6. For example, select 2048, the default start cylinder number, and press Enter.

The following information is returned:

First sector (2048-62914559, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):

"Last sector" indicates the end cylinder area. The value can be between 2048 and 62914559 (62914559 by default).

7. For example, select 62914559, the default end cylinder number, and press Enter.

The following information is returned:

Last sector, +sectors or   +size{K,M,G} (2048-62914559, default 62914559): Using default value   62914559Partition 1 of type   Linux and of size 30 GiB is set Command (m for help): p    

This indicates the partition has been created. That is, one partition is created for the 10 GB data disk.

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

The following information is returned:

Command (m for help): p

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 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: 0x2c6e939c

  Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    62914559    31456256   83  Linux

Command (m for help): w

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

9. 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() [ 2244.854718]  vdb: vdb1
to re-read partition table.
Syncing disks.
[ 2244.860481]  vdb: vdb1

This indicates that the partition is created.

       Note:

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.

1.         Run the following command to synchronize the change to the new partition table to the operating system.

Partprobe

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

mkfs -t file system format /dev/vdb1

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

mkfs -t ext4 /dev/vdb1

The following information is returned:

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
1966080 inodes, 7864064 blocks
393203 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
240 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

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing 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/sdc" as an example:

mkdir /mnt/sdc

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

mount /dev/vdb1 Mount Point

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

mount /dev/vdb1 /mnt/sdc

[root@test-sharedDisk ~]# mount /dev/vdb1 /mnt/sdc
[ 3118.784219] EXT4-fs (vdb1): mounted filesystem with ordered data mode. Opts: (null)

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

df -TH

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

Scenario

If you want to automatically mount disks when the server system starts, do not specify /dev/vdb1 in /etc/fstab because the sequential encoding of devices on the cloud may change when the server stops or starts. For example, /dev/vdb may change to /dev/vdc. 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/vdb1

The following information is returned:

[root@test-sharedDisk ~]# blkid /dev/vdb1
/dev/vdb1: UUID="8f42fd24-1731-4016-8058-19795c3153c8" TYPE="ext4"

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=8f42fd24-1731-4016-8058-19795c3153c8 /mnt/sdc ext4 defaults 0 2

UUID=3C27-7C31 /boot/efi vfat defaults 0 0
UUID=d257ff0f-c5e1-4d90-af3a-de94720d90fe /boot ext2 defaults 0 0
UUID=9136110f-0c77-4174-9870-e8243dbe2662 / xfs defaults 0 1
UUID=8f42fd24-1731-4016-8058-19795c3153c8 /mnt/sdc ext4 defaults 0 2

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


MVt0GxozVKR4