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.
-
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.
-
-
To create a single-partition data disk, execute the following commands in sequence:
-
Run
fdisk /dev/vdb
: Partition the data disk. -
Type
n
and press Enter: Create a new partition. -
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
. -
Enter the partition number and press Enter. Because only one partition is created here, you can enter 1.
-
Enter the first available sector number: Press Enter to take the default value of 1.
-
Enter the last sector number: Since only one partition is created here, press Enter to take the default value.
-
Type
wq
and press Enter to start partitioning.[root@iXXXXXXX ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5f46a8a2.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-41610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610):
Using default value 41610
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
-
-
View the new partition: run the command
fdisk -l
. If the following message appears, the new partition /dev/vdb1 has been successfully created.[root@iXXXXXXX ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00053156
Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41942016 83 Linux
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5f46a8a2
Device Boot Start End Blocks Id System
/dev/vdb1 1 41610 20971408+ 83 Linux
-
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.
[root@iXXXXXXX ~]# mkfs.ext3 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242852 blocks
262142 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
-
-
(Recommended) Backup etc/fstab : run the command
cp /etc/fstab /etc/fstab.bak
. -
Write new partition information to /etc/fstab
echo /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.
-
View new partition information in /etc/fstab : run the command
cat /etc/fstab
.[root@iXXXXXXX ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Feb 23 07:28:22 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=3d083579-f5d9-4df5-9347-8d27925805d4 / ext4 defaults 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/vdb1 /mnt ext3 defaults 0 0
-
Mount the filesystem: run the command
mount /dev/vdb1 /mnt
. -
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.
[root@iXXXXXXX ~]# mount /dev/vdb1 /mnt
[root@iXXXXXXX ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 6.6G 31G 18% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/vdb1 20G 173M 19G 1% /mnt