• Bare Metal Server

bms
  1. Help Center
  2. Bare Metal Server
  3. User Guide
  4. Getting Started
  5. Initializing Data Disks

Initializing Data Disks

Scenarios

In the following scenarios, EVS disks can be used only after being initialized:

  • A data disk is created when you create a BMS on the management console.
  • An EVS disk is created on the EVS console, then attached to a BMS to be used as a data disk.

This document uses CentOS 7.0 64-bit as an example. The method for formatting BMSs varies depending on the OS. This section only provides reference. For information about how to format BMSs running other types of OSs, see the corresponding OS product documentation.

When using an EVS disk for the first time, if you have not initialized the disk, including creating partitions and file systems, the additional capacity added to the disk in a later expansion operation may not be normally used.

Prerequisites

  • You have logged in to the BMS as user root.
  • A data disk has been attached to the BMS and has not been initialized.

Creating Partitions and Attaching a Disk

The following operations are used as an example. When a new data disk is attached to the BMS, the disk must be set as the primary partition in ext4 format and be automatically attached to the /mnt/sdc directory upon 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/sda: : 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/sda1   *        2048     2050047 1024000   83  Linux
    /dev/sda2         2050048    22530047    10240000   83  Linux
    /dev/sda3        22530048    24578047     1024000   83  Linux
    /dev/sda4        24578048    83886079    29654016    5  Extended
    /dev/sda5        24580096    26628095     1024000   82  Linux swap / Solaris
    
    Disk /dev/sdb: : 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

    The preceding information indicates that the BMS contains two disks. /dev/sda is the system disk, and /dev/sdb is the newly added data disk.

  2. Run the following command to use fdisk to perform the partitioning operations for the added data disk:

    fdisk Newly added data disk

    For example, run the following command to use fdisk to perform the partitioning operations for the /dev/sdb data disk:

    fdisk /dev/sdb

    Information similar to the following is displayed:

    [root@ecs-b656 test]# fdisk /dev/sdb
    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. Recreate the partition with the same partition type as before. In this example a primary partition is used. Therefore, 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 same partition number as the partition had before and press Enter. Primary partition number 1 is used in this example.

    Information similar to the following is displayed:

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

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

  6. Ensure that you enter the same first cylinder as the partition had before. In this example, we previously noted down 2048, so we type in 2048 here 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 end cylinder number. The value can be 2048 to 20971519, and the default value is 20971519.

  7. In this example, select the default end cylinder number 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/sdb: 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/sdb1            2048    20971519    10484736   83  Linux
    
    Command (m for help): 

    Details about the /dev/sdb1 partition are displayed.

  9. Enter w and press Enter to write the partition result 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.

  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/sdb1

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

    mkfs -t ext4 /dev/sdb1

    Information similar to the following is displayed:

    [root@ecs-b656 test]# mkfs -t ext4 /dev/sdb1
    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 quantity and size supported by different 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 mount point created in 12:

    mount /dev/sdb1 Mount point

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

    mount /dev/sdb1 /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/sda2     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/sda3     xfs       1.1G   39M  1.1G   4% /home
    /dev/sda1     xfs       1.1G  131M  915M  13% /boot
    /dev/sdb1     ext4       11G   38M  9.9G   1% /mnt/sdc

    The newly created partition /dev/sdb1 is mounted to /mnt/sdc.

Setting Automatic Disk Attachment Upon BMS Start

To automatically attach a disk when a BMS starts, you should not specify its partition, for example /dev/sdb1, in /etc/fstab. This is because the sequence of cloud devices may change during the BMS stop and start, for example, /dev/sdb1 may change to /dev/sdb2. You are advised to use the universally unique identifier (UUID) in /etc/fstab to automatically attach a disk at system start.

  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/sdb1:

    blkid /dev/sdb1

    Information similar to the following is displayed:

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

    The UUID of /dev/sdb1 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.