1.查看磁盘
fdisk -l
[root@ecs-75625 ~]# fdisk -l
Disk /dev/vda: 40 GiB, 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
Disklabel type: dos
Disk identifier: 0x70b978ed
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 83886079 83884032 40G 83 Linux
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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.开始分配磁盘大小
fdisk /dev/vdb
示例代码分为3个分区(300G、100G、100G)
Command (m for help): 提示时输入 n
Select (default p): 直接回车
Partition number (1-4, default 1):直接回车
First sector (2048-1048575999, default 2048): 直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999): +300G 表示分配300G
其他类似,执行到最后一个分区时
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999):直接回车 表示使用磁盘最后所有未分配容量
分配完后记得按 w 保存退出
[root@ecs-75625 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x5ef235e6.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-1048575999, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999): +300G
Created a new partition 1 of type 'Linux' and of size 300 GiB.
Command (m for help):
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (629147648-1048575999, default 629147648):
Last sector, +sectors or +size{K,M,G,T,P} (629147648-1048575999, default 1048575999): +100G
Created a new partition 2 of type 'Linux' and of size 100 GiB.
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (3,4, default 3):
First sector (838862848-1048575999, default 838862848):
Last sector, +sectors or +size{K,M,G,T,P} (838862848-1048575999, default 1048575999): +100G
Value out of range.
Last sector, +sectors or +size{K,M,G,T,P} (838862848-1048575999, default 1048575999):
Created a new partition 3 of type 'Linux' and of size 100 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
3.将新的分区表变更同步至操作系统
partprobe
此时查看分区是否生效
[root@ecs-75625 ~]# fdisk -l
Disk /dev/vda: 40 GiB, 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
Disklabel type: dos
Disk identifier: 0x70b978ed
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 83886079 83884032 40G 83 Linux
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x5ef235e6
Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 629147647 629145600 300G 83 Linux
/dev/vdb2 629147648 838862847 209715200 100G 83 Linux
/dev/vdb3 838862848 1048575999 209713152 100G 83 Linux
4.创建需要挂载的目录
mkdir -p workspace log soft
5.格式化分区
mkfs.ext4 /dev/vdb1
mkfs.ext4 /dev/vdb2
mkfs.ext4 /dev/vdb3
[root@ecs-75625 ~]# mkfs.ext4 /dev/vdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 78643200 4k blocks and 19660800 inodes
Filesystem UUID: d452b131-58a4-4ab9-a95f-940239d4576b
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
6.挂载到目录
mount /dev/vdb1 workspace
mount /dev/vdb2 soft
mount /dev/vdb3 log
查看是否生效
[root@ecs-75625 /]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.1G 0 4.1G 0% /dev/shm
tmpfs tmpfs 4.1G 9.0M 4.1G 1% /run
tmpfs tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/vda1 ext4 43G 2.6G 38G 7% /
tmpfs tmpfs 815M 0 815M 0% /run/user/0
/dev/vdb1 ext4 316G 68M 300G 1% /workspace
/dev/vdb2 ext4 106G 63M 100G 1% /soft
/dev/vdb3 ext4 106G 63M 100G 1% /log
7.设置开机自动挂载磁盘分区
7.1 查看分区uuid
blkid /dev/vdb1
记录下UUID后面需要使用
[root@ecs-75625 /]# blkid /dev/vdb1
/dev/vdb1: UUID="d452b131-58a4-4ab9-a95f-940239d4576b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5ef235e6-01"
7.2 配置fstab文件
vim /etc/fstab
内容
UUID=61c45d45-61a2-40d7-b27e-31e4050c1ff8 / ext4 defaults 1 1
UUID=d452b131-58a4-4ab9-a95f-940239d4576b /workspace ext4 defaults 0 2
UUID=473616f7-dcd2-472d-b60e-74f9fa356bc6 /soft ext4 defaults 0 3
UUID=2966cd30-90f9-4c4c-b555-b47e97f7ee7e /log ext4 defaults 0 4
- 第一列为UUID,此处填写1中查询到的磁盘分区的UUID。
- 第二列为磁盘分区的挂载目录,可以通过df -TH命令查询。
- 第三列为磁盘分区的文件系统格式, 可以通过df -TH命令查询。
- 第四列为磁盘分区的挂载选项,此处通常设置为defaults即可。
- 第五列为Linux dump备份选项。
- 0表示不使用Linux dump备份。现在通常不使用dump备份,此处设置为0即可。
- 1表示使用Linux dump备份。
- 第六列为fsck选项,即开机时是否使用fsck检查磁盘。
- 0表示不检验。
- 挂载点为(/)根目录的分区,此处必须填写1。根分区设置为1,其他分区只能从2开始,系统会按照数字从小到大依次检查下去。
7.3 测试开机挂载
卸载分区
umount /dev/vdb1
umount /dev/vdb2
umount /dev/vdb3
查看
[root@ecs-75625 /]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.1G 0 4.1G 0% /dev/shm
tmpfs tmpfs 4.1G 9.0M 4.1G 1% /run
tmpfs tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/vda1 ext4 43G 2.6G 38G 7% /
tmpfs tmpfs 815M 0 815M 0% /run/user/0
重新挂载
mount -a
查看
[root@ecs-75625 /]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.1G 0 4.1G 0% /dev/shm
tmpfs tmpfs 4.1G 9.0M 4.1G 1% /run
tmpfs tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/vda1 ext4 43G 2.6G 38G 7% /
tmpfs tmpfs 815M 0 815M 0% /run/user/0
/dev/vdb1 ext4 316G 68M 300G 1% /workspace
/dev/vdb2 ext4 106G 63M 100G 1% /soft
/dev/vdb3 ext4 106G 63M 100G 1% /log