CentOS/RHEL系统中swap空间扩容

在虚拟机中装ORACLE 11gR2的时候,环境检查是遇到swap空间不足的情况。

用这个网友的方法来解决了,转载下,原文地址http://francs3.blog.163.com/blog/static/40576727201221424642301/

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

一 环境信息

–1.1 测试环境

平台:笔记本虚拟机
系统:Red Hat Enterprise Linux Server release 6.2

–1.2 查看 swap 使用情况

[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 查看硬盘使用情况

[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 信息

[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 信息

[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 硬盘

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

[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

[root@redhat6 ~]# mkfs.ext4 -t ext4 -c /dev/sdb
mke2fs 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 信息

[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

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

–2.5 给 dev/vg_redhat6/lv_swap 扩容 512M

[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 分区

[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

[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 验证

[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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值