赞
踩
[root@ecs-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
/dev/xvda”是系统盘,“/dev/xvdb”是本次新增的数据盘。
[root@ecs-test]# parted /dev/xvdb
GNU Parted 3.1
Using /dev/xvdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/xvdb: unrecognised disk label
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
“Partition Table”为“unknown”表示磁盘分区形式未知。
输入命令mklabel gpt,设置磁盘分区形式。磁盘分区形式有MBR和GPT两种,本示例中以GPT为例。
输入“p”,按“Enter”,设置分区形式后,再次查看确认磁盘分区形式。回显如下:
(parted) mklabel gpt
(parted) p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdb: 20971520s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
可以看到,“Partition Table”为“gpt”,表示磁盘分区形式已设置为GPT。
输入“unit s”,按“Enter”,设置磁盘的计量单位为磁柱。
输入“mkpart opt 2048s 100%”,按“Enter”。“2048s”表示磁盘起始容量,“100%”表示磁盘截止容量。参数仅供参考,此例中是为整个磁盘创建一个分区,您可以根据业务需要自行规划磁盘分区数量及容量。回显如下:
(parted) unit s
(parted) mkpart opt 2048s 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
若出现以上性能优化提醒,请输入“Ignore”,忽略即可。
(parted) p Model: Xen Virtual Block Device (xvd) Disk /dev/xvdb: 20971520s Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 2048s 20969471s 20967424s opt
输入“q”,按“”Enter”,退出parted分区工具。分区创建完成。
执行命令lsblk,确认分区已成功创建。回显如下:
[root@ecs-test]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 40G 0 disk
├─xvda1 202:1 0 4G 0 part [SWAP]
└─xvda2 202:2 0 36G 0 part /
xvdb 202:16 0 100G 0 disk
└─xvdb1 202:17 0 100G 0 part
[root@ecs-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):
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
其中,磁盘有两种分区类型:“p”表示主要分区,“e”表示延伸分区。
Select (default p): p
Partition number (1-4, default 1):
“Partition number”表示主分区编号,可以选择1到4之间的数字。
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
“First sector”表示初始磁柱区域,可以选择2048-20971519,默认为2048。
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
“Last sector”表示截止磁柱区域,可以选择2048-20971519,默认为20971519。
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):
表示分区完成,即为10GB的数据盘新建了1个分区。
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):
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
表示分区创建完成。
如果之前分区操作有误,请输入“q”,则会退出fdisk分区工具,之前的分区结果将不会被保留。
[root@ecs-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
格式化需要等待一段时间,请观察系统运行状态,不要退出,直到显示格式化完成。
执行命令mkdir /mnt/sdc,新建挂载点。本示例中“/mnt/sdc”为挂载点。
执行命令mount /dev/xvdb1 /mnt/sdc,将新建分区挂载到新建的挂载点下。
执行命令df -TH,查看挂载结果。回显如下:
[root@ecs-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
表示新建分区“/dev/xvdb1”已挂载至“/mnt/sdc”。
如果您需要在云主机系统启动时自动挂载磁盘,不能采用在 /etc/fstab直接指定 /dev/xvdb1的方法,因为云中设备的顺序编码在关闭或者开启云主机过程中可能发生改变,例如/dev/xvdb1可能会变成/dev/xvdb2。推荐使用UUID来配置自动挂载数据盘。磁盘的UUID(universally unique identifier)是Linux系统为磁盘分区提供的唯一的标识字符串。
[root@ecs-test]# blkid /dev/xvdb1
/dev/xvdb1: UUID="******-****-****-****-******" TYPE="ext4"
UUID=******-****-****-****-****** /mnt/sdc ext4 defaults 0 2
按“ESC”后,输入“:wq”,按“Enter”“Enter”。保存设置并退出编辑器。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。