gdisk – добавить swap

Есть диск, определившийся как sdb, нужно создать раздел swap и добавить в систему

# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdb: 16777216 sectors, 8.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 64C6223A-4B99-4F15-8D57-86A4E7736142
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 16777182
Partitions will be aligned on 2048-sector boundaries
Total free space is 16142269 sectors (7.7 GiB)

Number Start (sector) End (sector) Size Code Name
1 2048 227327 110.0 MiB 8300 Linux filesystem
2 227328 636927 200.0 MiB 8300 Linux filesystem

Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-16777182, default = 636928) or {+-}size{KMGTP}:
Last sector (636928-16777182, default = 16777182) or {+-}size{KMGTP}: +220M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap
a902 NetBSD FFS a903 NetBSD LFS a904 NetBSD concatenated
a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot
af00 Apple HFS/HFS+ af01 Apple RAID af02 Apple RAID offline
af03 Apple label af04 AppleTV recovery af05 Apple Core Storage
be00 Solaris boot bf00 Solaris root bf01 Solaris /usr & Mac Z
bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var
bf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1
bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4
bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service
ed00 Sony system partitio ef00 EFI System ef01 MBR partition scheme
ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved
fc00 VMWare kcore crash p fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'

Command (? for help): p
Disk /dev/sdb: 16777216 sectors, 8.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 64C6223A-4B99-4F15-8D57-86A4E7736142
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 16777182
Partitions will be aligned on 2048-sector boundaries
Total free space is 15691709 sectors (7.5 GiB)

Number Start (sector) End (sector) Size Code Name
1 2048 227327 110.0 MiB 8300 Linux filesystem
2 227328 636927 200.0 MiB 8300 Linux filesystem
3 636928 1087487 220.0 MiB 8200 Linux swap

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

Проинициализируем изменения:

[root@cen758 /]# partprobe /dev/sdb

Создаем swap-раздел:

[root@cen758 /]# mkswap /dev/sdb3
Setting up swapspace version 1, size = 225276 KiB
no label, UUID=1c14ecfc-0ea2-457b-bcba-5446d0c25dbc

Было:

[root@cen758 /]# free -h
total used free shared buff/cache available
Mem: 991M 133M 687M 6.9M 170M 692M
Swap: 1.2G 0B 1.2G

Включаем:

[root@cen758 /]# swapon /dev/sdb3

Стало:

[root@cen758 /]# free -h
total used free shared buff/cache available
Mem: 991M 134M 687M 6.9M 170M 692M
Swap: 1.4G 0B 1.4G

Выключим и проверим:

[root@cen758 /]# swapoff /dev/sdb3
[root@cen758 /]# free -h
total used free shared buff/cache available
Mem: 991M 133M 686M 6.9M 171M 692M
Swap: 1.2G 0B 1.2G

Все верно. Возвращаем:

[root@cen758 /]# swapon /dev/sdb3
[root@cen758 /]# free -h
total used free shared buff/cache available
Mem: 991M 134M 686M 6.9M 171M 692M
Swap: 1.4G 0B 1.4G

Узнаем UUID:

[root@cen758 ~]# blkid /dev/sdb3
/dev/sdb3: UUID="1c14ecfc-0ea2-457b-bcba-5446d0c25dbc" TYPE="swap" PARTLABEL="Linux swap" PARTUUID="24216d0c-870a-4e9d-83a7-f6ae372ee792"

Прописываем в системе:

[root@cen758 /]# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Oct 1 03:29:38 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=56143509-9aae-451d-bd18-1f8603871dff /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=dd074549-24aa-432b-8b2b-6f0c84ff43bc /archive xfs defaults 0 2
UUID=1c14ecfc-0ea2-457b-bcba-5446d0c25dbc swap swap default 0 0

Проверяем:

[root@cen758 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 12.3G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 11.3G 0 part
  ├─centos-root 253:0 0 10G 0 lvm /
  └─centos-swap 253:1 0 1.2G 0 lvm [SWAP]
sdb 8:16 0 8G 0 disk
├─sdb1 8:17 0 110M 0 part /archive
├─sdb2 8:18 0 200M 0 part
└─sdb3 8:19 0 220M 0 part [SWAP]
sr0 11:0 1 1024M 0 rom

Перезагружаем, что бы проверить окончательно.