• Elastic Volume Service

evs
  1. Help Center
  2. Elastic Volume Service
  3. User Guide
  4. Getting Started
  5. Initializing an EVS Data Disk
  6. Initializing a Linux Data Disk (fdisk)

Initializing a Linux Data Disk (fdisk)

Scenarios

This topic uses CentOS 7.0 64bit to describe how to initialize a data disk attached to a server running Linux and use fdisk to partition the data disk.

The maximum disk capacity supported by MBR is 2 TB, and that supported by GPT is 18 EB. Therefore, use the GPT partition style if your disk capacity that needs to be initialized exceeds 2 TB. In Linux OSs, if the GPT partition style is used, the fdisk partitioning tool cannot be used. The parted partitioning tool must be used. For details about disk partition styles, see Introduction to Data Disk Initialization Scenarios and Partition Styles.

The method for initializing an EVS disk varies depending on the OS running on the server. This document is used for reference only. For the detailed operations and differences, see the product documents of the OSs running on the corresponding servers.

Prerequisites

  • You have logged in to the server.
    • For how to log in to an ECS, see the Elastic Cloud Server User Guide.
    • For how to log in to a BMS, see the Bare Metal Server User Guide.
  • A data disk has been attached to the server and has not been initialized.

Creating Partitions and Mounting a Disk

The following example shows you how a new primary partition can be created on a new data disk that has been attached to a server. The primary partition will be created using fdisk, and MBR is the default partition style. Furthermore, the partition will be formatted using the ext4 file system, mounted on /mnt/sdc, and configured automatic mounting upon system start.

  1. Run the following command to query information about the added data disk:

    fdisk -l

    Information similar to the following is displayed:

    [root@ecs-b656 test]# fdisk -l
    
    Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000cc4ad
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *        2048     2050047     1024000   83  Linux
    /dev/xvda2         2050048    22530047    10240000   83  Linux
    /dev/xvda3        22530048    24578047     1024000   83  Linux
    /dev/xvda4        24578048    83886079    29654016    5  Extended
    /dev/xvda5        24580096    26628095     1024000   82  Linux swap / Solaris
    
    Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 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

    In the command output, the server contains two disks. /dev/xvda is the system disk, and /dev/xvdb is the added data disk.

  2. Run the following command to enter fdisk to partition the added data:

    fdisk Newly added data disk

    In this example, /dev/xvdb is the added data disk.

    fdisk /dev/xvdb

    Information similar to the following is displayed:

    [root@ecs-b656 test]# fdisk /dev/xvdb
    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 0xb00005bd.
    Command (m for help): 

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

    Information similar to the following is displayed:

    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    There are two types of disk partitions:
    • Choosing p creates a primary partition.
    • Choosing e creates an extended partition.

  4. Enter p and press Enter to create a primary partition.

    Information similar to the following is displayed:

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

    Partition number indicates the serial number of the primary partition. The value can be 1 to 4.

  5. Enter the serial number of the primary partition and press Enter. Primary partition number 1 is used in this example. One usually starts with partition number 1 when partitioning an empty disk.

    Information similar to the following is displayed:

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

    First sector indicates the first sector. The value can be 2048 to 20971519, and the default value is 2048.

  6. Select the default first sector 2048 and press Enter.

    Information similar to the following is displayed:

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

    Last sector indicates the last sector. The value can be 2048 to 20971519, and the default value is 20971519.

  7. Select the default last sector 20971519 and press Enter.

    Information similar to the following is displayed:

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

    A primary partition has been created for a 10-GB data disk.

  8. Enter p and press Enter to view the details about the created partition.

    Information similar to the following is displayed:

    Command (m for help): p
    
    Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xb00005bd
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/xvdb1            2048    20971519    10484736   83  Linux
    
    Command (m for help): 

    Details about the /dev/xvdb1 partition are displayed.

  9. Enter w and press Enter to write the changes into the partition table.

    Information similar to the following is displayed:

    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    The partition is successfully created.

    NOTE:

    In case that you want to discard the changes made before, you can exit fdisk by entering q.

  10. Run the following command to synchronize the new partition table to the OS:

    partprobe

  11. Run the following command to set the format for the file system of the newly created partition:

    mkfs -t File system format /dev/xvdb1

    For example, run the following command to set the ext4 file system for the /dev/xvdb1 partition:

    mkfs -t ext4 /dev/xvdb1

    Information similar to the following is displayed:

    [root@ecs-b656 test]# mkfs -t ext4 /dev/xvdb1
    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
    655360 inodes, 2621184 blocks
    131059 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2151677952
    80 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
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done

    The formatting takes a period of time. Observe the system running status and do not exit.

    The partition sizes supported by file systems vary. Therefore, you are advised to choose an appropriate file system based on your service requirements.

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

    mkdir Mount point

    For example, run the following command to create the /mnt/sdc mount point:

    mkdir /mnt/sdc

  13. Run the following command to mount the new partition on the created mount point:

    mount /dev/xvdb1 Mount point

    For example, run the following command to mount the newly created partition on /mnt/sdc:

    mount /dev/xvdb1 /mnt/sdc

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

    df -TH

    Information similar to the following is displayed:

    [root@ecs-b656 test]# df -TH
    Filesystem     Type      Size  Used Avail Use% Mounted on
    /dev/xvda2     xfs        11G  7.4G  3.2G  71% /
    devtmpfs       devtmpfs  4.1G     0  4.1G   0% /dev
    tmpfs          tmpfs     4.1G   82k  4.1G   1% /dev/shm
    tmpfs          tmpfs     4.1G  9.2M  4.1G   1% /run
    tmpfs          tmpfs     4.1G     0  4.1G   0% /sys/fs/cgroup
    /dev/xvda3     xfs       1.1G   39M  1.1G   4% /home
    /dev/xvda1     xfs       1.1G  131M  915M  13% /boot
    /dev/xvdb1     ext4       11G   38M  9.9G   1% /mnt/sdc

    The newly created /dev/xvdb1 is mounted on /mnt/sdc.

Setting Automatic Disk Mounting at System Start

To automatically mount a disk when a server starts, you should not specify its partition, for example /dev/xvdb1, in /etc/fstab. Because the sequence of cloud devices, and therefore their names may change during the server stop and start. You are advised to use the universally unique identifier (UUID) in /etc/fstab to automatically mount a disk at system start.

NOTE:

The UUID is the unique character string for disk partitions in a Linux system.

  1. Run the following command to query the partition UUID:

    blkid Disk partition

    For example, run the following command to query the UUID of /dev/xvdb1:

    blkid /dev/xvdb1

    Information similar to the following is displayed:

    [root@ecs-b656 test]# blkid /dev/xvdb1
    /dev/xvdb1: UUID="1851e23f-1c57-40ab-86bb-5fc5fc606ffa" TYPE="ext4"

    The UUID of /dev/xvdb1 is displayed.

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

    vi /etc/fstab

  3. Press i to enter the editing mode.
  4. Move the cursor to the end of the file and press Enter. Then add the following information:

    UUID=1851e23f-1c57-40ab-86bb-5fc5fc606ffa /mnt/sdc      ext4 defaults     0   2

  5. Press Esc, enter :wq, and press Enter.

    The system saves the configurations and exits the vi editor.