RHEL6 学习: Swap 分区扩容

RedHat 企业版 6 默认安装会启用 LVM 管理方式,今天学习了给 swap 分区扩容,这里使用的是给已存在的 swap 逻辑分区扩容的方法,当然也可新建一个 swap 分区逻辑分区。本文采用的是前面的方法,下面是具体步骤。

一 环境信息

1.1 测试环境
平台:笔记本虚拟机
系统:Red Hat Enterprise Linux Server release 6.2

1.2 查看 swap 使用情况

1
2
3
4
5
[root@redhat6 ~]# free -m  
total used free shared buffers cached
Mem: 714 665 49 0 38 460
-/+ buffers/cache: 165 549
Swap: 1439 0 1439

备注:swap 分区目前为 1439 MB。

1.3 查看硬盘使用情况

1
2
3
4
5
6
[root@redhat6 ~]# df -hv  
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_redhat6-lv_root
13G 3.5G 8.8G 29% /
tmpfs 292M 100K 292M 1% /dev/shm
/dev/sda1 485M 31M 429M 7% /boot

1.4 查看系统 VG 信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@redhat6 ~]# vgdisplay  
--- Volume group ---
VG Name vg_redhat6 System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 14.51 GiB
PE Size 4.00 MiB
Total PE 3714
Alloc PE / Size 3714 / 14.51 GiB
Free PE / Size 0 / 0
VG UUID E6cA2U-TL1x-ScCV-UnGU-3Kq4-1u6V-WUb5L4

1.5 查看系统 lv 信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@redhat6 ~]# lvdisplay  
--- Logical volume ---
LV Name /dev/vg_redhat6/lv_root
VG Name vg_redhat6
LV UUID QFAl72-FSES-YKAH-Dax1-9FQH-kMmv-8vqju2
LV Write Access read/write
LV Status available
# open 1
LV Size 13.10 GiB
Current LE 3354
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/vg_redhat6/lv_swap
VG Name vg_redhat6
LV UUID H26wg0-bbW2-IfHa-j250-RFFh-O0ze-zTe3VU
LV Write Access read/write
LV Status available
# open 1
LV Size 1.41 GiB
Current LE 360
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

备注:根据上面信息,swap 使用的是逻辑卷 vg_redhat6,而且 vg_redhat6 空间都已分配完成,那么要扩 swap 分区,只要扩卷组 vg_redhat6,之后再扩 lv /dev/vg_redhat6/lv_swap 即可。

二 Swap 分区扩容

2.1 笔记本虚拟机加一块 4GB IDE 硬盘

此步略,硬盘加完重启系统后,硬盘信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@redhat6 ~]# fdisk -l
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn t contain a valid partition table
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d571a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1959 15215616 8e Linux LVM
Disk /dev/mapper/vg_redhat6-lv_root: 14.1 GB, 14067695616 bytes
255 heads, 63 sectors/track, 1710 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_redhat6-lv_root doesn t contain a valid partition table
Disk /dev/mapper/vg_redhat6-lv_swap: 1509 MB, 1509949440 bytes
255 heads, 63 sectors/track, 183 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_redhat6-lv_swap doesn t contain a valid partition table

备注:系统已经认出新加的盘 /dev/sdb, 容量为 4294 MB。

2.2 给VG vg_redhat6 扩容 4 GB

1
2
3
4
5
6
7
8
9
10
11
[root@redhat6 ~]# mkfs.ext4 -t ext4 -c /dev/sdbmke2fs 1.41.12 (17-May-2010)
[root@redhat6 ~]# pvcreate /dev/sdb
Writing physical volume data to disk "/dev/sdb"
Physical volume "/dev/sdb" successfully created

[root@redhat6 ~]# pvscan
PV /dev/sda2 VG vg_redhat6 lvm2 [14.51 GiB / 0 free]
PV /dev/sdb lvm2 [4.00 GiB]
Total: 2 [18.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 1 [4.00 GiB]

[root@redhat6 ~]# vgextend vg_redhat6 /dev/sdb Volume group "vg_redhat6" successfully extended

2.3 再次查看 vg_redhat6 信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@redhat6 ~]# vgdisplay  
--- Volume group ---
VG Name vg_redhat6
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 18.50 GiB
PE Size 4.00 MiB
Total PE 4737
Alloc PE / Size 3714 / 14.51 GiB
Free PE / Size 1023 / 4.00 GiB
VG UUID E6cA2U-TL1x-ScCV-UnGU-3Kq4-1u6V-WUb5L4

备注: VG vg_redhat6 扩容成功。

2.4 停用 swap

1
2
[root@redhat6 ~]# swapoff -v /dev/vg_redhat6/lv_swap  
swapoff on /dev/vg_redhat6/lv_swap

2.5 给 dev/vg_redhat6/lv_swap 扩容 512M

1
2
3
[root@redhat6 ~]# lvresize -L+512M /dev/vg_redhat6/lv_swap  
Extending logical volume lv_swap to 1.91 GiB
Logical volume lv_swap successfully resized

2.6 格式化 swap 分区

1
2
3
4
5
[root@redhat6 ~]# mkswap /dev/vg_redhat6/lv_swap  
mkswap: /dev/vg_redhat6/lv_swap: warning: dont erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1998844 KiB
no label, UUID=47f6e518-6189-4231-9aed-9f7ad01c29ca

2.7 启用 swap

1
2
3
4
[root@redhat6 ~]# swapon -v /dev/vg_redhat6/lv_swap  
swapon on /dev/vg_redhat6/lv_swap
swapon: /dev/mapper/vg_redhat6-lv_swap: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/mapper/vg_redhat6-lv_swap: pagesize=4096, swapsize=2046820352, devsize=2046820352

2.8 再次查看 swap 验证

1
2
3
4
5
[root@redhat6 ~]# free -m  
total used free shared buffers cached
Mem: 582 509 73 0 53 271
-/+ buffers/cache: 183 399
Swap: 1951 0 1951

备注: swap 分区成功扩容到 1951 MB。

最后推荐和张文升共同编写的《PostgreSQL实战》,本书基于PostgreSQL 10 编写,共18章,重点介绍SQL高级特性、并行查询、分区表、物理复制、逻辑复制、备份恢复、高可用、性能优化、PostGIS等,涵盖大量实战用例!

购买链接:https://item.jd.com/12405774.html

PostgreSQL实战
感谢支持!
0%