0.版本說(shuō)明
環(huán)境:centos7.9
設(shè)備名:/dev/vdb
數(shù)據(jù)盤:容量:200 GiB
1.查看數(shù)據(jù)盤
運(yùn)行以下命令,獲取數(shù)據(jù)盤的設(shè)備名稱
fdisk -lu
運(yùn)行結(jié)果如下所示,表示當(dāng)前ECS實(shí)例有兩塊云盤,/dev/vda是系統(tǒng)盤,/dev/vdb是新增數(shù)據(jù)盤。
[root@host-10-10-10-14 /]# fdisk -lu
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: 0x00019db9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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
2.為數(shù)據(jù)盤創(chuàng)建MBR分區(qū)
運(yùn)行以下命令,對(duì)數(shù)據(jù)盤進(jìn)行分區(qū)。其中,/dev/vdb是數(shù)據(jù)盤的設(shè)備名稱,根據(jù)實(shí)際環(huán)境替換。
fdisk -u /dev/vdb
運(yùn)行結(jié)果如下所示
[root@host-10-10-10-14 /]# fdisk -u /dev/vdb
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 0x76259292.
Command (m for help):
在fdisk交互命令行,輸入【p】并按Enter鍵,查看數(shù)據(jù)盤的分區(qū)情況。
運(yùn)行結(jié)果如下所示
Command (m for help): p
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0x76259292
Device Boot Start End Blocks Id System
Command (m for help):
在fdisk交互命令行,輸入【n】并按Enter鍵,開(kāi)始新建分區(qū)。
運(yùn)行結(jié)果如下所示
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
云盤有兩種分區(qū)類型:p表示主分區(qū)。e表示擴(kuò)展分區(qū)。
在fdisk交互命令行,輸入【p】并按Enter鍵,開(kāi)始創(chuàng)建一個(gè)主分區(qū)。
運(yùn)行結(jié)果如下所示
Select (default p): p
Partition number (1-4, default 1):
Partition number表示主分區(qū)編號(hào),可以選擇1-4。默認(rèn)1。
輸入分區(qū)編號(hào),按Enter鍵。如果創(chuàng)建一個(gè)主分區(qū),可以直接按Enter鍵。
運(yùn)行結(jié)果如下所示
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
輸入起始扇區(qū)編號(hào),按Enter鍵。不輸入直接按Enter鍵,表示選擇默認(rèn)值。
運(yùn)行結(jié)果如下所示
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
輸入最后一個(gè)扇區(qū)編號(hào),按Enter鍵。不輸入直接按Enter鍵,表示選擇默認(rèn)值。
運(yùn)行結(jié)果如下所示
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set
Command (m for help):
在fdisk交互命令行,輸入【p】并按Enter鍵,查看該數(shù)據(jù)盤的規(guī)劃分區(qū)情況。
運(yùn)行結(jié)果如下所示,表示新建分區(qū)/dev/vdb1的詳細(xì)信息。
Command (m for help): p
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0x76259292
Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 83 Linux
Command (m for help):
在fdisk交互命令行,輸入【w】并按Enter鍵,將分區(qū)結(jié)果寫(xiě)入分區(qū)表中。
運(yùn)行結(jié)果如下所示,表示分區(qū)創(chuàng)建完成。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
運(yùn)行以下命令,查看新分區(qū)信息。/dev/vdb是數(shù)據(jù)盤的設(shè)備名稱,根據(jù)實(shí)際環(huán)境替換。
fdisk -lu /dev/vdb
運(yùn)行結(jié)果如下所示,如果出現(xiàn)/dev/vdb1的相關(guān)信息,表示新分區(qū)已創(chuàng)建完成。
[root@host-10-10-10-14 /]# fdisk -lu /dev/vdb
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0x76259292
Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 83 Linux
3.為分區(qū)創(chuàng)建ext4文件系統(tǒng)
運(yùn)行以下命令,安裝e2fsprogs工具。
yum install -y e2fsprogs
運(yùn)行結(jié)果如下所示
[root@host-10-10-10-14 /]# yum install -y e2fsprogs
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#7 - "Failed to connect to 2600:1f16:c1:5e01:4180:6610:5482:c1c0: Network is unreachable"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#7 - "Failed to connect to 2600:1f16:c1:5e01:4180:6610:5482:c1c0: Network is unreachable"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#7 - "Failed to connect to 2600:1f16:c1:5e01:4180:6610:5482:c1c0: Network is unreachable"
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/5): epel/x86_64/group_gz | 99 kB 00:00:00
(2/5): extras/7/x86_64/primary_db | 249 kB 00:00:00
(3/5): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(4/5): epel/x86_64/primary_db | 7.0 MB 00:00:06
(5/5): updates/7/x86_64/primary_db | 21 MB 00:00:15
Package e2fsprogs-1.42.9-19.el7.x86_64 already installed and latest version
Nothing to do
運(yùn)行以下命令,創(chuàng)建ext4文件系統(tǒng)。其中,/dev/vdb1是數(shù)據(jù)盤的分區(qū)名稱,根據(jù)實(shí)際環(huán)境替換。
mkfs -t ext4 /dev/vdb1
運(yùn)行結(jié)果如下所示
[root@host-10-10-10-14 /]# mkfs -t ext4 /dev/vdb1
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
13107200 inodes, 52428544 blocks
2621427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2199912448
1600 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, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
4.配置/etc/fstab文件并掛載分區(qū)
設(shè)置開(kāi)機(jī)自動(dòng)掛載云盤,需要在/etc/fstab中寫(xiě)入新分區(qū)信息,啟動(dòng)開(kāi)機(jī)自動(dòng)掛載分區(qū)。
運(yùn)行以下命令,備份/etc/fstab文件。
cp /etc/fstab /etc/fstab.bak
在/etc/fstab里寫(xiě)入新分區(qū)信息,運(yùn)行以下命令修改/etc/fstab文件。
其中:
/dev/vdb1:數(shù)據(jù)盤的分區(qū)名稱,需要根據(jù)實(shí)際環(huán)境進(jìn)行替換。
/opt:分區(qū)的掛載點(diǎn),需要根據(jù)實(shí)際環(huán)境進(jìn)行替換??梢詫⒎謪^(qū)掛載至環(huán)境已有目錄下,也可以先通過(guò)mkdir命令創(chuàng)建新的掛載目錄,然后再掛載。
ext4:分區(qū)的文件系統(tǒng)類型,需要根據(jù)已創(chuàng)建的文件系統(tǒng)類型修改。
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"http://g'` /opt ext4 defaults 0 0 >> /etc/fstab
運(yùn)行以下命令,查看/etc/fstab中的新分區(qū)信息。
cat /etc/fstab
運(yùn)行結(jié)果如下所示
[root@host-10-10-10-14 /]# cp /etc/fstab /etc/fstab.bak
[root@host-10-10-10-14 /]# echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"http://g'` /opt ext4 defaults 0 0 >> /etc/fstab
[root@host-10-10-10-14 /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Aug 17 15:16:23 2015
#
# 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=f1640169-9ac8-4729-ac36-2ebea6b99120 / ext4 defaults 1 1
UUID=434e44fe-a678-4aa1-9f46-fef4bbaf2bc6 /opt ext4 defaults 0 0
運(yùn)行以下命令,掛載/etc/fstab配置的文件系統(tǒng)。如果無(wú)報(bào)錯(cuò)輸出,表示您的/etc/fstab配置無(wú)誤。
mount -a
運(yùn)行以下命令,檢查掛載結(jié)果是否符合您的預(yù)期。
df -h
運(yùn)行結(jié)果如下所示,如果出現(xiàn)新建文件系統(tǒng)/dev/vdb1的信息,表示文件系統(tǒng)掛載成功
[root@host-10-10-10-14 /]# mount -a
[root@host-10-10-10-14 /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 9.3M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 40G 2.1G 36G 6% /
tmpfs 798M 0 798M 0% /run/user/0
/dev/vdb1 197G 61M 187G 1% /opt
5.結(jié)束語(yǔ)
本篇只記錄自己的學(xué)習(xí)過(guò)程,更好的提升自己