由于系统部署的时候,分区使用的默认分区管理,系统规划不是很好,swap过于大,浪费了很多磁盘空间,这里讲将swap下线,进行缩容,然后将缩减出的容量补充到在线的根分区上。固然只有一个根分区不好,这样规划以后会出一些问题,这里只讨论操作的扩缩的操作步骤。
下文中,红色加粗字体的部分是操作的命令,蓝色部分是需要特别注意的地方。通过这些蓝色的输出来确定你的服务器该怎么调整容量大小,并且检查是否达到调整的预期。
思路:首先查看swap的大小及分区,然后调整swap大小,使vg中有空余的空间可以给根分区的lv进行补充。然后重建swap,挂载swap,检查vg的空余容量显示是否正常,然后给根分区的lv扩容,resize2fs,完成。
此操作为真实线上服务器的调整记录,供朋友们参考,在真实上线操作之前,请务必在与你在的平台完全相同的实验环境进行详细的测试,然后方可实施操作。我的系统环境是:
操作系统:RHEL 5u3 64bit
内核版本:2.6.18-128.el5
[root@server10 ~]# free -g total used free shared buffers cached Mem: 62 62 0 0 0 60 -/+ buffers/cache: 2 60Swap: 127 0 127 [root@server10 ~]# df -h Filesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 147G 74G 65G 54% / /dev/sda1 99M 13M 81M 14% /boot tmpfs 32G 0 32G 0% /dev/shm [root@server10 ~]# cat /etc/fstab/dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0/dev/VolGroup00/LogVol01 swap swap defaults 0 0 [root@server10 ~]# lvdisplay --- Logical volume --- LV Name /dev/VolGroup00/LogVol00 VG Name VolGroup00 LV UUID oZ7rEm-hphT-MsGk-fNaD-RC5X-INgZ-oCJdml LV Write Access read/write LV Status available # open 1 LV Size 150.84 GB Current LE 4827 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/LogVol01 VG Name VolGroup00 LV UUID pCpqVB-cwXV-MunF-OtBQ-usYA-hFxt-l07IJc LV Write Access read/write LV Status available # open 1 LV Size 127.91 GB Current LE 4093 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 [root@server10 ~]# vgdisplay --- Volume group --- VG Name VolGroup00 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 278.75 GB PE Size 32.00 MB Total PE 8920 Alloc PE / Size 8920 / 278.75 GB Free PE / Size 0 / 0 VG UUID 9hHRZZ-VUd4-bMwc-rnhK-wiyq-sPZw-dtJREo [root@server10 ~]# free -m total used free shared buffers cached Mem: 64449 64129 320 0 327 61494 -/+ buffers/cache: 2307 62142Swap: 130975 0 130975 [root@server10 ~]# swapoff -a [root@server10 ~]# free -m total used free shared buffers cached Mem: 64449 64065 384 0 327 61494 -/+ buffers/cache: 2243 62206Swap: 0 0 0 [root@server10 ~]# lvreduce /dev/VolGroup00/LogVol01 -L -64G WARNING: Reducing active logical volume to 63.91 GB THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce LogVol01? [y/n]: y Reducing logical volume LogVol01 to 63.91 GB Logical volume LogVol01 successfully resized [root@server10 ~]# mkswap /dev/VolGroup00/LogVol01Setting up swapspace version 1, size = 68618809 kB [root@server10 ~]# swapon /dev/VolGroup00/LogVol01 [root@server10 ~]# free -m total used free shared buffers cached Mem: 64449 64150 299 0 327 61549 -/+ buffers/cache: 2273 62175Swap: 65439 0 65439 [root@server10 ~]# free -g total used free shared buffers cached Mem: 62 62 0 0 0 60 -/+ buffers/cache: 2 60Swap: 63 0 63 [root@server10 ~]# vgdisplay --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size 278.75 GB PE Size 32.00 MB Total PE 8920 Alloc PE / Size 6872 / 214.75 GB Free PE / Size 2048 / 64.00 GB VG UUID 9hHRZZ-VUd4-bMwc-rnhK-wiyq-sPZw-dtJREo [root@server10 ~]# df -h Filesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 147G 74G 65G 54% / /dev/sda1 99M 13M 81M 14% /boot tmpfs 32G 0 32G 0% /dev/shm [root@server10 ~]# mount/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda1 on /boot type ext3 (rw) tmpfs on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) [root@server10 ~]# lvextend /dev/VolGroup00/LogVol00 -l +100%FREE Extending logical volume LogVol00 to 214.84 GB Logical volume LogVol00 successfully resized [root@server10 ~]# df -hFilesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 147G 74G 65G 54% / /dev/sda1 99M 13M 81M 14% /boot tmpfs 32G 0 32G 0% /dev/shm [root@server10 ~]# resize2fs /dev/VolGroup00/LogVol00resize2fs 1.39 (29-May-2006) Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required Performing an on-line resize of /dev/VolGroup00/LogVol00 to 56320000 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol00 is now 56320000 blocks long. [root@server10 ~]# df -h Filesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 209G 74G 124G 38% / /dev/sda1 99M 13M 81M 14% /boot tmpfs 32G 0 32G 0% /dev/shm [root@server10 ~]#