- 使用 fdisk 分割出來的 /dev/vda5 無法改變大小,若要變更只能重新分割。查詢目前 /dev/vda5 的 swap 大小為 10236 bytes (10M)。
[root@kvm7 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-0 partition 126972 0 -1
/dev/vda5 partition 10236 0 -2
- 先關閉 /dev/vda5 的 swap。
[root@kvm7 ~]# swapoff /dev/vda5
[root@kvm7 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-0 partition 126972 0 -1
- fdisk 硬碟 /dev/vda,刪除 /dev/vda5,再重新分割一個 30M 的 vda5,且格式為 swap (82)。
[root@kvm7 ~]# fdisk /dev/vda
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.
Command (m for help): p
Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 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: 0x00094fcc
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 411647 204800 83 Linux
/dev/vda2 411648 7579647 3584000 8e Linux LVM
/dev/vda3 7579648 7845887 133120 8e Linux LVM
/dev/vda4 7845888 8388607 271360 5 Extended
/dev/vda5 7847936 7868415 10240 82 Linux swap / Solaris
Command (m for help): d
Partition number (1-5, default 5):
Partition 5 is deleted
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (7847936-8388607, default 7847936):
Using default value 7847936
Last sector, +sectors or +size{K,M,G} (7847936-8388607, default 8388607): +30M
Partition 5 of type Linux and of size 30 MiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
- 重新偵測新的分割表。
[root@kvm7 ~]# partprobe
[root@kvm7 ~]# kpartx /dev/vda
vda1 : 0 409600 /dev/vda 2048
vda2 : 0 7168000 /dev/vda 411648
vda3 : 0 266240 /dev/vda 7579648
vda4 : 0 2 /dev/vda 7845888
vda5 : 0 61440 /dev/vda 7847936
- 將 /dev/vda5 格式化為 swap。
[root@kvm7 ~]# mkswap /dev/vda5
mkswap: /dev/vda5: warning: wiping old swap signature.
Setting up swapspace version 1, size = 30716 KiB
no label, UUID=e0cb3290-ecc4-488f-8b18-4a0f2235c9ea
- 再從 /etc/fstab 中的設定啟動所有的 swap。
[root@kvm7 ~]# swapon -a
- 查詢啟動的 swap,除了原有的 /dev/dm-0 外,/dev/vda5 有 30716 bytes (30M)。
[root@kvm7 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-0 partition 126972 0 -1
/dev/vda5 partition 30716 0 -2