After a newly created data disk is attached to a server, you must log in to the server and initialize the disk before you can use the disk. This section describes how to initialize a Linux data disk. The operations may vary depending on the server OS.
The maximum disk size that MBR supports is 2 TiB, and that GPT supports is 18 EiB. If your disk capacity is less than 2 TiB, you can use either the MBR or GPT partition style. However, if your disk is greater than 2 TiB or you may expand it to over 2 TiB later, use GPT when initializing disks.
Operation | OS Requirements | Partition Style | Common File Systems | Example Configuration |
|---|---|---|---|---|
None | MBR | ext* (such as ext2, ext3, and ext4), xfs, and btrfs |
| |
None |
|
The disk has been attached to a server. For how to attach disks, see Attaching an EVS Disk.
The following example shows you how to use fdisk to create two primary partitions (/dev/vdb1: 40 GiB; /dev/vdb2: 60 GiB) on the /dev/vdb data disk and set the partition style to MBR.
For how to log in to an ECS, see the Elastic Cloud Server User Guide.
lsblk
The command output shows that there are two EVS disks. /dev/vda is the system disk, and /dev/vdb is the new data disk, whose 100 GiB is not partitioned.
fdisk /dev/vdb
n
p
1
First sector (2048-209715199, default 2048): 2048Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 83886079Partition 1 of type Linux and of size 40 GB is set
Sector | /dev/vdb1 (40 GiB) | /dev/vdb2 (60 GiB) | Formula for Calculating the Value of sectors |
|---|---|---|---|
First sector | 2048 (The first sector of the /dev/vdb data disk is used.) | Last sector of /dev/vdb1 + 1 = 83886079 + 1 = 83886080 | Value of sectors = Capacity × 1073741824/512 |
Last sector | Value of sectors – 1 = (40 × 1073741824/512) – 1 = 83886079 | First sector + Value of sectors – 1 = 83886080 + (60 × 1073741824/512) – 1 = 209715199 |
n
p
2
Command (m for help): nPartition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): pPartition number (1-4, default 2): 2
First sector (83886080-209715199, default 83886080): 83886080Last sector, +sectors or +size{K,M,G} (83886080-209715199, default 209715199): 209715199Partition 2 of type Linux and of size 60 GB is set
p
Disk label type: dos indicates the MBR partition style.
In case that you want to discard the changes made before, you can exit fdisk by entering q and press Enter. Then, re-create the partitions by referring to step 1 and step 2.
w
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
The partition is created.
If error message -bash: partprobe: command not found is returned, the system cannot identify the command. In this case, run yum install -y parted to install the command. Then, run the command again.
partprobe
mkfs -t ext4 /dev/vdb1
mkfs -t ext4 /dev/vdb2
[root@ecs-test-0001 ~]# mkfs -t ext4 /dev/vdb1mke2fs 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 blocks2621440 inodes, 10485504 blocks524275 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=2157969408320 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, 7962624Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done
blkid /dev/vdb
[root@ecs-test-0001 ~]# blkid /dev/vdb/dev/vdb1: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"/dev/vdb2: UUID="0d6769k2-1745-9dsf-453d-hgd0b34267dj" TYPE="ext4"
mkdir -p /mnt/sdc
mount /dev/vdb1 /mnt/sdc
mkdir -p /mnt/sdd
mount /dev/vdb2 /mnt/sdd
lsblk
[root@ecs-test-0001 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTvda 253:0 0 40G 0 disk├vda1 253:1 0 40G 0 part /vdb 253:16 0 100G 0 disk├vdb1 253:17 0 40G 0 part /mnt/sdc├vdb2 253:18 0 60G 0 part /mnt/sdd
You should now see that partitions /dev/vdb1 and /dev/vdb2 are mounted on /mnt/sdc and /mnt/sdd.
UUIDs are the unique character strings for identifying partitions in Linux. Mounts become invalid after a system reboot. You can configure auto mount at startup by adding information of the new partitions into the /etc/fstab file. blkid /dev/vdb1 blkid /dev/vdb2 Take note of the partition UUIDs, which will be used in the next step. In this example, the partition UUIDs are 0b3040e2-1367-4abb-841d-ddb0b92693df and 0d6769k2-1745-9dsf-453d-hgd0b34267dj. vi /etc/fstab Press i to enter the editing mode, move the cursor to the end of the file, press Enter, and add the following content: Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor. Example Value Description UUID=0b3040e2-1367-4abb-841d-ddb0b92693df The UUID of the partition. /mnt/sdc The mount point of the partition. ext4 The file system format of the partition. defaults The partition mount option. Normally, this parameter is set to defaults. 0 The Linux dump backup option. 2 The fsck option, which means whether to use fsck to check the disk during startup.
You can restart the server to check whether auto mount takes effect. Alternatively, you can perform the following steps to simulate auto mount.
umount /dev/vdb1
umount /dev/vdb2
mount -a
mount | grep /mnt/sdc
mount | grep /mnt/sdd
If information similar to the following is displayed, auto mount has taken effect:
root@ecs-test-0001 ~]# mount | grep /mnt/sdc/dev/vdb1 on /mnt/sdc type ext4 (rw,relatime,data=ordered)root@ecs-test-0001 ~]# mount | grep /mnt/sdd/dev/vdb2 on /mnt/sdd type ext4 (rw,relatime,data=ordered)
You can use parted to create either MBR or GPT partitions. The only difference is that the command used to set the partition style is different. All other operations are the same. For the initialization instructions with parted, see Initializing a Data Disk Using parted.
Commands for setting partition styles:
MBR:
mklabel msdosunit sp
GPT:
mklabel gptunit sp