Initialize TiB data disks less than or equal to 2 (Linux)
prerequisite
background information
| | |
| | |
|
|
Operation steps
Step 1: Log in to the ECS instance and view the data disk
Connect ECS instances remotely. Run the following command to obtain the device name of the data disk. sudo fdisk -lu The running results are as follows, indicating that the current ECS instance has two cloud disks, /dev/vda Is the system disk, /dev/vdb It is a new data disk.
Step 2: Create partitions for the data disk
MBR partitions do not support capacities above 2 TiB. If the cloud disk capacity you use is greater than 2 TiB or may be expanded to more than 2 TiB later, please use GPT partition format when partitioning. The Parted tool is applicable to MBR partitions and GPT partitions. The fdisk partitioning tool is only applicable to MBR partitions.
Create GPT partition
Run the following command to install the Parted tool. sudo yum install -y parted explain The yum command in this step is applicable to Linux distributions such as CentOS. For other Linux distributions, please modify the installation command according to the actual package management software. For example, Debian or Ubuntu, use Apt get install<package name> 。 Use the Parted tool to partition the data disk. Run the following command to start partitioning. This operation is based on the data disk /dev/vdb Take for example. sudo parted /dev/vdb Among them, /dev/vdb It is the device name of the data disk. Please replace it according to the actual environment. Enter the following in the Parted interactive command line to set the GPT partition format. mklabel gpt Enter the following contents to divide a primary partition, and set the start and end positions of the partition. This operation takes the partition of a primary partition, the partition name is primary, and 100% capacity is given to the first partition as an example. mkpart primary 1 100% explain If you need to create multiple partitions for a single cloud disk, you need to repeat this step to create other partitions. Run the following command to check the partition alignment. Among them, one It is the corresponding partition number. It is generally recommended that you align partitions to obtain better cloud disk performance. align-check optimal 1 If the partition is aligned, the result is as follows: 1 aligned explain If the return is 1 not aligned , indicating that the partition is not aligned. See FAQ for initializing cloud disk 。 Enter the following to view the partition table. print Enter the following content to exit the Parted tool. quit
The partitioning process is shown below. Run the following command to make the system reread the partition table. partprobe Run the following command to view the new partition information. This operation is based on the data disk /dev/vdb Take for example. sudo fdisk -lu /dev/vdb Among them, /dev/vdb It is the device name of the data disk. Please replace it according to the actual environment. The running results are as follows. If the relevant information about gpt appears, the new partition has been created.
Create MBR partition
Create an MBR partition. Run the following command to partition the data disk. This operation is based on the data disk /dev/vdb Take for example. sudo fdisk -u /dev/vdb Among them, /dev/vdb It is the device name of the data disk. Please replace it according to the actual environment. Echo information is shown in the following figure. On the fdisk interactive command line, enter p And press Enter Key to view the partition of the data disk. Echo information is shown in the following figure. input n And press Enter Key to start creating a new partition. Echo information is shown in the following figure. Indicates that the cloud disk has two partition types: p Represents the primary partition. e Represents an extended partition. explain The cloud disk uses the MBR partition form. You can create up to four primary partitions, or three primary partitions and one extended partition. The extended partition cannot be used directly, but needs to be divided into several logical partitions. For more information, see Introduction to partition format 。
Take creating a primary partition as an example. input p And press Enter Key to start creating a primary partition. Echo information is shown in the following figure. Partition number Indicates the number of the primary partition. You can select 1-4. Enter the partition number and press Enter Key. This example takes creating a primary partition as an example Press Enter key , indicating that the partition number of the primary partition is one 。 Echo information is shown in the following figure. Enter the starting sector number and press Enter Key. First sector Indicates the starting sector number of the partition free space. You can select 2048-83886079, and the default value is 2048. In this example, directly Press Enter key , indicating that the default start sector number is selected two thousand and forty-eight 。 Echo information is shown in the following figure. explain The system will automatically prompt the starting sector number and ending sector number of the available space of the partition. You can customize or use the default value in this range. The starting sector number of the partition must be less than the ending sector number. Enter the last sector number and press Enter Key. Last sector Indicates the end sector number of the partition's available space. You can select 2048-83886079, and the default value is 83886079. In this example, directly Press Enter key , indicating that the default cut-off sector number is selected eighty-three million eight hundred and eighty-six thousand and seventy-nine 。 Echo information is shown in the following figure. explain The system will automatically prompt the starting sector number and ending sector number of the available space of the partition. You can customize or use the default value in this range. The starting sector number of the partition must be less than the ending sector number. input p And press Enter Key to view the partition planning of the data disk. Echo information is as shown in the figure below, indicating the new partition /dev/vdb1 Details of. explain If the above partition operation is incorrect, please enter q Exit the fdisk partition tool, and the previous partition results will not be retained. You can re partition according to the above steps. input w And press Enter Key to write the partition results to the partition table. The echo information is shown in the following figure, indicating that the partition creation is completed. explain If you need to create multiple partitions for a single cloud disk, you need to repeat this step to create other partitions.
Run the following command to view the new partition information. This operation is based on the data disk /dev/vdb Take for example. sudo fdisk -lu /dev/vdb Among them, /dev/vdb It is the device name of the data disk. Please replace it according to the actual environment. The running result is shown in the figure below. If /dev/vdb1 Indicates that the new partition has been created.
Step 3: Create a file system for the partition
Run the following command to install the e2fsprogs tool. sudo yum install -y e2fsprogs explain The yum command in this step is applicable to Linux distributions such as CentOS. For other Linux distributions, please modify the installation command according to the actual package management software. For example, Debian or Ubuntu, use Apt get install<package name> 。 Run the following command to create a file system. The following example command describes how to create ext4 and xfs file systems. Create ext4 file system sudo mkfs -t ext4 /dev/vdb1 Among them, /dev/vdb1 Is the partition name of the data disk. Please replace it according to the actual environment. important When the data disk has a capacity of 16 TiB and an error is reported when creating an ext4 file system, you need to check whether the e2fsprogs toolkit is higher than 1.42, and install a higher version of the e2fsprogs toolkit. See How to upgrade the e2fsprogs toolkit? 。 The ext4 file system's lazy init function will affect the I/O performance of the data disk. You can turn off the ext4 file system's lazy init function. See How to turn off the lazy init function of a Linux instance? 。
The example information shown in the figure below is represented as data disk partition /dev/vdb1 Create an ext4 file system. Create xfs file system sudo mkfs -t xfs /dev/vdb1 Among them, /dev/vdb1 Is the partition name of the data disk. Please replace it according to the actual environment. The example information shown in the figure below is represented as data disk partition /dev/vdb1 Create an xfs file system.
Step 4: Configure Auto attach partition after power on
Run the following command to backup /etc/fstab File. sudo cp /etc/fstab /etc/fstab.bak stay /etc/fstab Write the new partition information in. Root user Run the following command to modify /etc/fstab File. echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab Including: /dev/vdb1 : The partition name of the data disk. You need to replace it according to the actual environment. /mnt : The mount point of the partition. You need to replace it according to the actual environment. important This directory needs to be specified according to the actual environment. Please specify or create the directory to be mounted correctly. You can mount the partition to the existing directory of the environment, or you can first use the mkdir Command to create a new directory, and then mount it. ext4 : The file system type of the partition. You need to modify it according to the created file system type. defaults : The mount parameters of the file system. Please select the corresponding mount parameters according to the actual needs to meet your requirements for data security and performance of the file system. For more information, see Use the mount command to mount the ext4 file system 。
explain The Ubuntu 12.04 system does not support barrier. You need to run echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /mnt ext4 barrier=0 0 0 >> /etc/fstab Command. If your operating system is not Ubuntu 12.04, please ignore this instruction. If a single disk has multiple consecutive partitions, the partition information needs to be written separately /etc/fstab Medium. For example, data disk /dev/vdb There are 2 partitions /dev/vdb1 and /dev/vdb2 , you need to execute the following commands respectively: Echo ` blkid/dev/vdb1 | awk '{print $2}' | sed's/ "//g '`<mount point of/dev/vdb1><file system type of/dev/vdb1>defaults 0>>/etc/fstab Echo ` blkid/dev/vdb2 | awk '{print $2}' | sed's/ "//g '`<mount point of/dev/vdb2><file system type of/dev/vdb2>defaults 0>>/etc/fstab
Ordinary users Manual modification /etc/fstab File. See Configure UUID mode in fstab file to automatically mount data disk 。 Run the following command to view /etc/fstab New partition information in. cat /etc/fstab The results are shown below. Run the following command to mount /etc/fstab Configured file system. If there is no error output, it means your /etc/fstab The configuration is correct. sudo mount -a Run the following command to check whether the mount result meets your expectations. df -h The results are as follows. If the information of creating a new file system appears, the file system is mounted successfully.
FAQ for initializing cloud disk
How to solve the problem of misaligned partitions when creating GPT partitions?
Run the following command to view cloud disk parameters. cat /sys/block/vdb/queue/optimal_io_size cat /sys/block/vdb/queue/minimum_io_size cat /sys/block/vdb/alignment_offset cat /sys/block/vdb/queue/physical_block_size Run the following command to subdivide a primary partition. Mkpart primary<recommended sector value>s 100% Among them, <Recommended sector value>=(<optimal_io_size>+<alignment_offset>)/<physical_block_size> 。 For example, if 1024 is the calculated recommended sector value, you can run mkpart primary 1024s 100% Redivide a primary partition.
How to upgrade the e2fsprogs toolkit for Linux instances?
mkfs.ext4: Size of device /dev/vdb too big to be expressed in 32 bits using a blocksize of 4096.
Run the following command to check the current version of e2fsprogs. rpm -qa | grep e2fsprogs The running results are shown below. If the current version is lower than 1.42, follow the steps below to install the software. Run the following command to download e2fsprogs of version 1.42.8. You can also visit e2fsprogs Find the latest package. wget https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.42.8/e2fsprogs-1.42.8.tar.gz --no-check-certificate Compile a higher version of the tool. Run the following command to decompress the software package. tar xvzf e2fsprogs-1.42.8.tar.gz Run the following command to enter the software package directory. cd e2fsprogs-1.42.8 Run the following command to generate a Makefile file. ./configure Run the following command to compile e2fsprogs. make Run the following command to install e2fsprogs. make install
Run the following command to check whether the version is updated successfully. rpm -qa | grep e2fsprogs
How to turn off the lazy init function of a Linux instance?
sudo mke2fs -O 64bit,has_journal,extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize -E lazy_itable_init=0,lazy_journal_init=0 /dev/vdb1
Related Documents
How to initialize a new data disk larger than 2 TiB in the Linux system, see Initialize the TiB data disk larger than 2 。 How to initialize a new data disk less than or equal to 2 TiB in the Windows system, see Initialize TiB data disks less than or equal to 2 (Windows) 。 For cloud disk expansion, see Cloud Disk Expansion Guidelines 。
-
Introduction to this page (1)