一、题目要求
增加一个 512M 的 swap,实行启动挂载。(此主机上有三块磁盘 vda vdb vdc ,其中vda和vdb上都存在分区,根据需要计算使用哪一块磁盘.)
二、解题过程
1、分区,将vdc剩余空间分为一个区
[root@blue ~]# fdisk /dev/vdc
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.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2):
First sector (4196352-10485759, default 4196352):
Last sector, +sectors or +size{K,M,G,T,P} (4196352-10485759, default 10485759):
Created a new partition 2 of type 'Extended' and of size 3 GiB.
Command (m for help): p
Disk /dev/vdc: 5 GiB, 5368709120 bytes, 10485760 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: 0x9abafb02
Device Boot Start End Sectors Size Id Type
/dev/vdc1 2048 4196351 4194304 2G 8e Linux LVM
/dev/vdc2 4196352 10485759 6289408 3G 5 Extended
Command (m for help):
2、新建一个逻辑分区,用来创建swap
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (4198400-10485759, default 4198400):
Last sector, +sectors or +size{K,M,G,T,P} (4198400-10485759, default 10485759): +512M
Created a new partition 5 of type 'Linux' and of size 512 MiB.
Command (m for help): p
Disk /dev/vdc: 5 GiB, 5368709120 bytes, 10485760 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: 0x9abafb02
Device Boot Start End Sectors Size Id Type
/dev/vdc1 2048 4196351 4194304 2G 8e Linux LVM
/dev/vdc2 4196352 10485759 6289408 3G 5 Extended
/dev/vdc5 4198400 5246975 1048576 512M 83 Linux
Command (m for help): w
The partition table has been altered.
Failed to add partition 5 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
[root@blue ~]#
3、重启
reboot
4、为分区5选择格式
[root@blue ~]# fdisk /dev/vdc
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.
Command (m for help): p
Disk /dev/vdc: 5 GiB, 5368709120 bytes, 10485760 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: 0x9abafb02
Device Boot Start End Sectors Size Id Type
/dev/vdc1 2048 4196351 4194304 2G 8e Linux LVM
/dev/vdc2 4196352 10485759 6289408 3G 5 Extended
/dev/vdc5 4198400 5246975 1048576 512M 83 Linux
Command (m for help): t
Partition number (1,2,5, default 5): 5
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.
Command (m for help): p
Disk /dev/vdc: 5 GiB, 5368709120 bytes, 10485760 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: 0x9abafb02
Device Boot Start End Sectors Size Id Type
/dev/vdc1 2048 4196351 4194304 2G 8e Linux LVM
/dev/vdc2 4196352 10485759 6289408 3G 5 Extended
/dev/vdc5 4198400 5246975 1048576 512M 82 Linux swap / Solaris
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@blue ~]#
5、格式化分区5
[root@blue ~]# mkswap /dev/vdc5
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=cb3c1415-8666-42e9-9c8c-4525a6bcf7bb
6、开机自动挂载
[root@blue ~]# vim /etc/fstab
[root@blue ~]# tail -1 /etc/fstab
UUID=cb3c1415-8666-42e9-9c8c-4525a6bcf7bb swap swap defaults 0 0
[root@blue ~]#
7、验证
[root@blue ~]# swapon -a
[root@blue ~]# swapon -s
Filename Type Size Used Priority
/dev/vdc5 partition 524284 0 -2
[root@blue ~]#