代码语言:javascript复制
free -h命令查看内存使用空间。
total used free shared buff/cache available
总大小 使用的大小 空闲 共享 缓冲区/缓存 真正可用内存
yum install gdisk -y
gdisk /dev/sdb
1、分一个新区,给swap
n 添加新的分区
p 显示分区表
2、mkswap /dev/vdb3 (格式化成swap格式)
3、swapon /dev/vdb3(激活/swap,加入到swap分区中,临时生效)
4、vim /etc/fstab (写入自动挂载)
/dev/vdb3 swap swap defaults 0 0
注:ID为8200
具体操作过程:
[root@gz ~]# gdisk /dev/vdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-20971486, default = 12584960) or { -}size{KMGTP}:
Last sector (12584960-20971486, default = 20971486) or { -}size{KMGTP}:
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
3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot
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
8302 Linux /home 8400 Intel Rapid Start 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 ea00 Freedesktop $BOOT
eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
Press the <Enter> key to see more codes: 82
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/vdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 1BB19CCA-7D82-4584-87E1-D19F495E47C4
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 6293503 3.0 GiB 8300 Linux filesystem
2 6293504 12584959 3.0 GiB 8300 Linux filesystem
3 12584960 20971486 4.0 GiB 8200 Linux swap
Command (? for help): w
mkswap /dev/vdb3
swapon /dev/vdb3
vim /etc/fstab
重启实例后
Welcome!
-------------------------------------------------------------------------------------------------------------------------
[root@gz ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 240M 1.2G 588K 339M 1.4G
Swap: 5.0G 0B 5.0G