初始化Linux数据盘(fdisk) fdisk l Disk /dev/vda: 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: 0x000bcb4e Device Boot Start End Blocks Id System /dev/vda1 2048 83886079 41942016 83 Linux Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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 表示当前的云主机有两块磁盘,“/dev/vda”是系统盘,“/dev/vdb”是新增数据盘。 2.执行以下命令,进入fdisk分区工具,开始对新增数据盘执行分区操作。 fdisk 新增数据盘 以新挂载的数据盘“/dev/vdb”为例: fdisk /dev/vdb 回显类似如下信息: [root@ecstest0001 ~] fdisk /dev/vdb Welcome to fdisk (utillinux 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 0x38717fc1. Command (m for help): 3.输入“n”,按“Enter”,开始新建分区。 回显类似如下信息: Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended 表示磁盘有两种分区类型: “p”表示主分区。 “e”表示扩展分区。 说明 磁盘使用MBR分区形式,最多可以创建4个主分区,或者3个主分区加1个扩展分区,扩展分区不可以直接使用,需要划分成若干个逻辑分区才可以使用。 磁盘使用GPT分区形式时,没有主分区、扩展分区以及逻辑分区之分。 4.以创建一个主要分区为例,输入“p”,按“Enter”,开始创建一个主分区。 回显类似如下信息: Select (default p): p Partition number (14, default 1): “Partition number”表示主分区编号,可以选择14。 5.以分区编号选择“1”为例,输入主分区编号“1”,按“Enter”。 回显类似如下信息: Partition number (14, default 1): 1 First sector (2048209715199, default 2048): “First sector”表示起始磁柱值,可以选择2048209715199,默认为2048。 6.以选择默认起始磁柱值2048为例,按“Enter”。 系统会自动提示分区可用空间的起始磁柱值和截止磁柱值,可以在该区间内自定义,或者使用默认值。起始磁柱值必须小于分区的截止磁柱值。 回显类似如下信息: First sector (2048209715199, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048209715199, default 209715199): “Last sector”表示截止磁柱值,可以选择2048209715199,默认为209715199。 7.以选择默认截止磁柱值209715199为例,按“Enter”。 系统会自动提示分区可用空间的起始磁柱值和截止磁柱值,可以在该区间内自定义,或者使用默认值。起始磁柱值必须小于分区的截止磁柱值。 回显类似如下信息: Last sector, +sectors or +size{K,M,G} (2048209715199, default 209715199): Using default value 209715199 Partition 1 of type Linux and of size 100 GiB is set Command (m for help): 表示分区完成,即为数据盘新建了1个分区。 8.输入“p”,按“Enter”,查看新建分区的详细信息。 回显类似如下信息: Command (m for help): p Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x38717fc1 Device Boot Start End Blocks Id System /dev/vdb1 2048 209715199 104856576 83 Linux Command (m for help): 表示新建分区“/dev/vdb1”的详细信息。 9.输入“w”,按“Enter”,将分区结果写入分区表中。 回显类似如下信息: Command (m for help): w The partition table has been altered! Calling ioctl() to reread partition table. Syncing disks. 表示分区创建完成。 说明 如果之前分区操作有误,请输入“q”,则会退出fdisk分区工具,之前的分区结果将不会被保留。 10.执行以下命令,将新的分区表变更同步至操作系统。 partprobe 11.执行以下命令,将新建分区文件系统设为系统所需格式。 mkfs t 文件系统格式 /dev/vdb1 以设置文件系统为“ext4”为例: mkfs t ext4 /dev/vdb1 回显类似如下信息: [root@ecstest0001 ~]