Help Center/ Elastic Cloud Server/ User Guide/ Disks/ Initializing Data Disks/ Initializing a Linux Data Disk (Greater Than 2 TiB)
Updated on 2024-10-25 GMT+08:00

Initializing a Linux Data Disk (Greater Than 2 TiB)

Scenarios

When the size of a disk is greater than 2 TiB, you can only use parted to create GPT partitions. The initialization operations may vary depending on the server OS.

Partition Style

OS

File System Format

Partitioning Tool

Example Configuration

GPT

Not limited

ext* (such as ext2, ext3, and ext4), xfs, and btrfs

parted

  • Device name: /dev/vdb
  • File system format: ext4
  • Mount point: /mnt/sdc
  • Partition name: /dev/vdb1
  • Partition style: GPT
  • Size: 3 TiB

Prerequisites

You have attached the disk to a server.

Notes and Constraints

  • A disk created from a data source does not need to be initialized. Such a disk contains the source data in the beginning. Initializing the disk may clear the initial data on it. If you need to re-initialize the disk, you are advised to back up the disk data first.
  • Initializing a disk does not delete the snapshots created for the disk, so you can still use snapshots to roll back data to the source disk after the disk is initialized.

Procedure

The following example shows you how to use parted to create a GPT partition on the /dev/vdb data disk.

  1. Log in to the server.

    For how to log in to an ECS, see Logging In to an ECS.

    For how to log in to a BMS, see Logging In to a BMS.

  2. Create the /dev/vdb1 partition on data disk /dev/vdb.

    1. Check that the capacity of the /dev/vdb data disk is 3 TiB.
      lsblk
      [root@ecs-centos76 ~]# lsblk
      NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
      vda    253:0    0  40G  0 disk
      ├vda1 253:1    0  40G  0 part /
      vdb    253:16   0   3T  0 disk
    1. Create the /dev/vdb1 partition.

      parted /dev/vdb

      p
      [root@ecs-centos74 ~]# parted /dev/vdb
      GNU Parted 3.1
      Using /dev/vdb
      Welcome to GNU Parted! Type 'help' to view a list of commands.
      (parted) p
      Error: /dev/vdb: unrecognised disk label
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 3299GB
      Sector size (logical/physical): 512B/512B
      Partition Table: unknown
      Disk Flags:
      (parted)

      Partition Table: unknown means that no partition style is set for the new disk.

      If error message -bash: parted: 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.

    1. Set the partition style of the /dev/vdb1 partition to GPT.

      mklabel gpt

      unit s

      p

      (parted) mklabel gpt
      (parted) unit s
      (parted) p
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 6442450944s
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:
       
      Number  Start  End  Size  File system  Name  Flags
       
      (parted)
      • If your disk size is smaller than 2 TiB and you want to use parted to create an MBR partition, run mklabel msdos.
      • If you change the partition style of a disk, data on the disk will be erased. Select an appropriate partition style when initializing disks.
      • The partition style (MBR or GPT) set here will apply to all subsequent partitions created on this EVS disk. When you create partitions on this disk later, you do not need to perform this step again.
    1. Set the name and size of the /dev/vdb1 partition.

      mkpart /dev/vdb1 2048s 100%

      p

      • Partition /dev/vdb1 is created, starting on 2048 and using 100% of the rest of the disk.
      • If you want to create two or more partitions, calculate the first and last sectors of the partitions based on the method provided in 2.
      (parted) mkpart /dev/vdb1 2048s 100%
      (parted) p
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 6442450944s
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:
       
      Number  Start        End          Size         File system  Name          Flags
       1      2048s        6442448895s  6442446848s               /dev/vdb1

      Enter q and press Enter. Then run lsblk to view the new partition /dev/vdb1.

      [root@ecs-centos74 ~]# lsblk
      NAME     MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
      vda      253:0    0    40G  0 disk
      ├─vda1 253:1    0    40G  0 part /
      vdb      253:16   0     3T  0 disk
      └─vdb1 253:17   0     3T  0 part

  3. Create an ext4 file system on the /dev/vdb1 partition.

    mkfs -t ext4 /dev/vdb1

    It takes some time to create a file system. Observe the system running status and do not exit.

    [root@ecs-test-0001 ~]# 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
    201326592 inodes, 805305856 blocks
    40265292 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2952790016
    24576 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
            102400000, 214990848, 512000000, 550731776, 644972544
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    [root@ecs-test-0001 ~]#

    Run parted /dev/vdb and enter p to check the file system format.

    [root@ecs-test-0001 ~]# parted /dev/vdb
    GNU Parted 3.1
    Using /dev/vdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 3299GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags:
    
    Number  Start   End      Size     File system  Name        Flags
     1      1049kB  3299GB   3299GB   ext4         /dev/vdb1           
    
    (parted) q
    [root@ecs-test-0001 ~]#

    Enter q and press Enter to exit parted.

  4. Create a directory (mount point) and mount the new partition on the created mount point.

    mkdir -p /mnt/sdc

    mount /dev/vdb1 /mnt/sdc

    lsblk

    [root@ecs-test-0001 ~]# lsblk
    NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vda    253:0    0  40G  0 disk
    ├vda1 253:1    0  40G  0 part /
    vdb    253:16   0   3T 0 disk
    ├vdb1 253:17   0   3T 0 part /mnt/sdc

    You should now see that partition /dev/vdb1 is mounted on /mnt/sdc.

  5. Use the partition UUID to configure auto mount at startup.

    • Mounts become invalid after a system reboot. You can configure auto mount at startup by adding information of the new partition into the /etc/fstab file.
    • You are advised not to use device names to identify disks in the /etc/fstab file because device names are assigned dynamically and may change (for example, from /dev/vdb1 to /dev/vdb2) after a stop or start. This can even prevent your server from booting up.
    • UUIDs are the unique character strings for identifying partitions in Linux.
    • This operation will not affect the existing data on the ECS.
    1. Query the partition UUID.

      blkid /dev/vdb1

      [root@ecs-test-0001 ~]# blkid /dev/vdb1
      /dev/vdb1: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"

      The UUID of the /dev/vdb1 partition is 0b3040e2-1367-4abb-841d-ddb0b92693df.

    1. Configure auto mount at startup.

      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:

      UUID=0b3040e2-1367-4abb-841d-ddb0b92693df    /mnt/sdc     ext4    defaults     0    2

      Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.

      Table 1 Parameter description

      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.
        • 0: Linux dump backup is not used. Usually, dump backup is not used, and you can set this parameter to 0.
        • 1: Linux dump backup is used.

      2

      • The fsck option, which means whether to use fsck to check the disk during startup.
        • 2: The check starts from the partitions whose mount points are non-root directories. / is the root directory.
        • 1: The check starts from the partitions whose mount points are root directories.
        • 0: The fsck option is not used.

  6. Verify that auto mount takes effect.

    umount /dev/vdb1

    mount -a

    The system reloads all the content in the /etc/fstab file.

    Query file system mounting information.

    mount | grep /mnt/sdc

    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)