Alibaba Cloud Service Formatting and Mounting Data Disks

Original path: https://help.aliyun.com/document_detail/25426.html?spm=5176.doc25446.2.6.VXEZ2R

If you have configured a data disk for an ECS instance, you need to format the data disk and mount the file system before you can use the data disk normally.

Note :

  • Disk partitioning and formatting are high-risk behaviors, please operate with caution. This document describes how to deal with a newly purchased data disk. If your data disk has data, be sure to create a snapshot of the data disk to avoid possible data loss.

  • The cloud server ECS only supports   partitioning  the data disk , but not the system disk  . If you forcibly use a third-party tool to partition the system disk, it may cause unknown risks, such as system crash and data loss .

This article describes how to create a single-partition data disk with a new data disk and mount the file system. This article only applies to using  fdisk commands to partition a data disk no larger than 2 TB. If the data disk that needs to be partitioned is larger than 2 TB, please refer to  32TB block storage partition .

You can also configure multiple partitions for data disks according to business needs. It is recommended to use the tools that come with the system to perform partition operations.

Operating Instructions

Data disks purchased separately   need to be  mounted before formatting.

Data disks purchased with the instance can be formatted directly without mounting.

 You need to know the device name of the data disk attached to the instance: You can find  the device name of the data disk through  ECS Management Console  >  Disk Details  >  Disk Mount Information . The device names of the data disks are allocated by the system by default, starting from  /dev/xvdb  and then in order, and the distribution range includes  /dev/xvdb/dev/xvdz .

Steps

In this example, we create a single partition data disk with a new 20 GB data disk (device name /dev/xvdb) and mount an ext3 file system. The instance used is an I/O optimized instance and the operating system is CentOS 6.8.

  1. Remote connection instance .

  2. Run  fdisk -l the command to check whether the instance has data disks. If /dev/vdb is not found after executing the command  , it means that your instance does not have a data disk and you do not need to format the data disk. Please ignore the rest of this article.

    • If your data disk shows  dev/xvd?, you are using a non-I/O optimized instance.

    • where  ?  is any letter from a−z.

  3. To create a single-partition data disk, execute the following commands in sequence:

    1. Run  fdisk /dev/vdb: Partition the data disk.

    2. Type  n and press Enter: Create a new partition.

    3. Type  p and press Enter: Select the primary partition. Because a single-partition data disk is created, only the primary partition needs to be created.

      Note: If you want to create more than 4 partitions, you should create at least one extended partition, ie select  e.

    4. Enter the partition number and press Enter. Because only one partition is created here, you can enter 1.

    5. Enter the first available sector number: Press Enter to take the default value of 1.

    6. Enter the last sector number: Since only one partition is created here, press Enter to take the default value.

    7. Type  wq and press Enter to start partitioning.

       
      1. [root@iXXXXXXX ~]# fdisk /dev/vdb
      2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
      3. Building a new DOS disklabel with disk identifier 0x5f46a8a2.
      4. Changes will remain in memory only, until you decide to write them.
      5. After that, of course, the previous content won't be recoverable.
      6. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
      7. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
      8. switch off the mode (command 'c') and change display units to
      9. sectors (command 'u').
      10. Command (m for help): n
      11. Command action
      12. e extended
      13. p primary partition (1-4)
      14. p
      15. Partition number (1-4): 1
      16. First cylinder (1-41610, default 1): 1
      17. Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610):
      18. Using default value 41610
      19. Command (m for help): wq
      20. The partition table has been altered!
      21. Calling ioctl() to re-read partition table.
      22. Syncing disks.
  4. View the new partition: run the command  fdisk -l. If the following message appears, the new partition /dev/vdb1 has been successfully created.

     
    1. [root@iXXXXXXX ~]# fdisk -l
    2. Disk /dev/vda: 42.9 GB, 42949672960 bytes
    3. 255 heads, 63 sectors/track, 5221 cylinders
    4. Units = cylinders of 16065 * 512 = 8225280 bytes
    5. Sector size (logical/physical): 512 bytes / 512 bytes
    6. I/O size (minimum/optimal): 512 bytes / 512 bytes
    7. Disk identifier: 0x00053156
    8. Device Boot Start End Blocks Id System
    9. /dev/vda1 * 1 5222 41942016 83 Linux
    10. Disk /dev/vdb: 21.5 GB, 21474836480 bytes
    11. 16 heads, 63 sectors/track, 41610 cylinders
    12. Units = cylinders of 1008 * 512 = 516096 bytes
    13. Sector size (logical/physical): 512 bytes / 512 bytes
    14. I/O size (minimum/optimal): 512 bytes / 512 bytes
    15. Disk identifier: 0x5f46a8a2
    16. Device Boot Start End Blocks Id System
    17. /dev/vdb1 1 41610 20971408+ 83 Linux
  5. Create a filesystem on the new partition: run the command  mkfs.ext3 /dev/vdb1.

    • This example creates an ext3 filesystem. You can also choose to create other file systems according to your needs, for example, if you need to share files between Linux, Windows and Mac systems, you can use  mkfs.vfat Create VFAT file system.

    • The time required to create a file system depends on the size of the data disk.

       
      1. [root@iXXXXXXX ~]# mkfs.ext3 /dev/vdb1
      2. mke2fs 1.41.12 (17-May-2010)
      3. Filesystem label=
      4. OS type: Linux
      5. Block size=4096 (log=2)
      6. Fragment size=4096 (log=2)
      7. Stride=0 blocks, Stripe width=0 blocks
      8. 1310720 inodes, 5242852 blocks
      9. 262142 blocks (5.00%) reserved for the super user
      10. First data block=0
      11. Maximum filesystem blocks=4294967296
      12. 160 block groups
      13. 32768 blocks per group, 32768 fragments per group
      14. 8192 inodes per group
      15. Superblock backups stored on blocks:
      16. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
      17. 4096000
      18. Writing inode tables: done
      19. Creating journal (32768 blocks): done
      20. Writing superblocks and filesystem accounting information: done
      21. This filesystem will be automatically checked every 37 mounts or
      22. 180 days, whichever comes first. Use tune2fs -c or -i to override.
  6. (Recommended) Backup  etc/fstab : run the command  cp /etc/fstab /etc/fstab.bak.

  7.  Write new partition information  to  /etc/fstabecho /dev/vdb1 /mnt ext3 defaults 0 0 >> /etc/fstab : run the command .

    Note : Ubuntu 12.04 does not support barriers, so the correct command for this system is: echo '/dev/vdb1 /mnt ext3 barrier=0 0 0' >> /etc/fstab.

    If you need to mount the data disk to a folder separately, for example, to store web pages, please replace the above command /mnt with the path of the desired mount point.

  8. View  new partition information in /etc/fstab  : run the command  cat /etc/fstab.

     
    1. [root@iXXXXXXX ~]# cat /etc/fstab
    2. #
    3. # /etc/fstab
    4. # Created by anaconda on Thu Feb 23 07:28:22 2017
    5. #
    6. # Accessible filesystems, by reference, are maintained under '/dev/disk'
    7. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    8. #
    9. UUID=3d083579-f5d9-4df5-9347-8d27925805d4 / ext4 defaults 1 1
    10. tmpfs /dev/shm tmpfs defaults 0 0
    11. devpts /dev/pts devpts gid=5,mode=620 0 0
    12. sysfs /sys sysfs defaults 0 0
    13. proc /proc proc defaults 0 0
    14. /dev/vdb1 /mnt ext3 defaults 0 0
  9. Mount the filesystem: run the command  mount /dev/vdb1 /mnt.

  10. View current disk space and usage: Run the command  df -h. If the message of creating a new file system appears, it means that the mount is successful and the new file system can be used.

    After the mount operation is complete, you do not need to restart the instance to start using the new file system.

     
    1. [root@iXXXXXXX ~]# mount /dev/vdb1 /mnt
    2. [root@iXXXXXXX ~]# df -h
    3. Filesystem Size Used Avail Use% Mounted on
    4. /dev/vda1 40G 6.6G 31G 18% /
    5. tmpfs 499M 0 499M 0% /dev/shm
    6. /dev/vdb1 20G 173M 19G 1% /mnt

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070818&siteId=291194637