Ubuntu 交换空间 swap分区的迁移
程序员文章站
2022-07-03 20:05:05
...
情况简介:
Disk /dev/sda: 3.7 TiB, 4000787030016 bytes, 7814037168 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: 0x9e74984a
Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: 0x081bd91f
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4095 2048 1M 83 Linux
/dev/sdb2 4096 2101247 2097152 1G 83 Linux
/dev/sdb3 2101248 270536703 268435456 128G 83 Linux
/dev/sdb4 270536704 480251903 209715200 100G 83 Linux
把/dev/sdb3的swap分区转移到/dev/sda上
步骤:
在/dev/sda上创建同等大小的分区。这一步使用fdisk /dev/sda,用n新建分区即可,建立好之后是这样的:
Disk /dev/sda: 3.7 TiB, 4000787030016 bytes, 7814037168 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: 0x9e74984a
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 270536703 270534656 129G 83 Linux
Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: 0x081bd91f
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4095 2048 1M 83 Linux
/dev/sdb2 4096 2101247 2097152 1G 83 Linux
/dev/sdb3 2101248 270536703 268435456 128G 83 Linux
/dev/sdb4 270536704 480251903 209715200 100G 83 Linux
mkswap /dev/sda1 -L sda1-swap
[email protected]:/# mkswap /dev/sda1 -L sda1-swap
Setting up swapspace version 1, size = 129 GiB (138513739776 bytes)
LABEL=sda1-swap, UUID=99090e64-564e-49d9-9ad5-c0e2743ea10c
[email protected]:/# blkid
/dev/sdb2: UUID="3f914361-4dc0-4c67-8440-cef9efb63640" TYPE="ext4" PARTUUID="081bd91f-02"
/dev/sdb3: UUID="52424035-bedb-4a81-8ef6-a90c3a60b189" TYPE="swap" PARTUUID="081bd91f-03"
/dev/sdb4: UUID="a211f762-a196-4d63-91c6-57b62a97d478" TYPE="ext4" PARTUUID="081bd91f-04"
/dev/sda1: LABEL="sda1-swap" UUID="99090e64-564e-49d9-9ad5-c0e2743ea10c" TYPE="swap" PARTUUID="9e74984a-01"
可以看到新的swap分区已经建立好了
swapon查看当前在使用的交换分区
[email protected]_10_176_50_25:/home/fnlp# swapon
NAME TYPE SIZE USED PRIO
/swap.img file 8G 0B -2
/dev/sdb3 partition 128G 0B -3
在/etc/fstab修改挂载
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/disk/by-uuid/99090e64-564e-49d9-9ad5-c0e2743ea10c none swap sw 0 0
# / was on /dev/sdb4 during curtin installation
/dev/disk/by-uuid/a211f762-a196-4d63-91c6-57b62a97d478 / ext4 defaults 0 0
# /boot was on /dev/sdb2 during curtin installation
/dev/disk/by-uuid/3f914361-4dc0-4c67-8440-cef9efb63640 /boot ext4 defaults 0 0
/swap.img none swap sw 0 0
重启,swapon查看目前正在使用的swap分区
[email protected]_10_176_50_25:/home/fnlp# swapon
NAME TYPE SIZE USED PRIO
/swap.img file 8G 0B -2
/dev/sda1 partition 129G 0B -3
发现原来的swap分区目前已弃用。利用fdisk /dev/sdb的d命令,删除原来的swap分区