Linux格式化数据盘
一. 运行fdisk -l命令查看实例上的数据盘
注:执行命令后,如果不存在/dev/vdb,表示您的实例没有数据盘。确认数据盘是否已挂载。
二.依次运行以下命令,创建一个分区
[root@ecshost~ ]# 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 0x3e60020e.
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x3e60020e
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x3e60020e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
三. 运行fdisk -lu /dev/vdb命令查看新分区
如果出现/dev/vdb1的相关信息,表示新分区已创建完成
[root@ecshost~ ]# fdisk -lu /dev/vdb Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x3e60020e Device Boot Start End Blocks Id System /dev/vdb1 2048 41943039 20970496 83 Linux
四.在新分区上创建一个文件系统
创建一个ext4文件系统
mkfs -t ext4 /dev/vdb1
[root@ecshost~ ]# mkfs -t ext4 /dev/vdb1
mke2fs 1.43.5 (04-Aug-2017)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 884e1a06-1481-43d6-b1a3-8bccaa03****
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
五.向/etc/fstab写入新分区信息,启动开机自动挂载分区
- 运行命令
cp /etc/fstab /etc/fstab.bak,备份etc/fstab。
运行命令echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab,向/etc/fstab里写入新分区信息。
2.如果要把数据盘单独挂载到某个文件夹,例如单独用来存放网页,则将命令中/mnt替换成所需的挂载点路径。
说明
- 建议在/etc/fstab中使用全局唯一标识符UUID来引用新分区。您可以使用blkid命令获得新分区的UUID。
- Ubuntu 12.04系统不支持barrier,您需要运行
echo '`blkid /dev/vdb1 | awk '{print $3}' | sed 's/\"//g'` /mnt ext4 barrier=0 0 0' >> /etc/fstab命令。
六.运行cat /etc/fstab命令查看/etc/fstab中的新分区信息
[root@ecshost~ ]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed Dec 12 07:53:08 2018 # # 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=d67c3b17-255b-4687-be04-f29190d4**** / ext4 defaults 1 1 UUID=a4c73111-3a33-4569-a90c-b6d2e953**** /mnt ext4 defaults 0 0
七.运行mount /dev/vdb1 /mnt命令挂载文件系统
[root@ecshost~ ]# mount /dev/vdb1 /mnt [root@ecshost~ ]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 1.6G 36G 5% / devtmpfs 234M 0 234M 0% /dev tmpfs 244M 0 244M 0% /dev/shm tmpfs 244M 484K 244M 1% /run tmpfs 244M 0 244M 0% /sys/fs/cgroup tmpfs 49M 0 49M 0% /run/user/0 /dev/vdb1 20G 45M 19G 1% /mnt
转自阿里云:https://help.aliyun.com/document_detail/25426.html?spm=a2c4g.11186623.2.27.7ca944e6GRHwKX#concept-jl1-qzd-wdb

浙公网安备 33010602011771号