因爲系統部署的時候,分區使用的默認分區管理,系統規劃不是很好,swap過於大,浪費了不少磁盤空間,這裏講將swap下線,進行縮容,而後將縮減出的容量補充到在線的根分區上。當然只有一個根分區很差,這樣規劃之後會出一些問題,這裏只討論操做的擴縮的操做步驟。web
下文中,紅色加粗字體的部分是操做的命令,藍色部分是須要特別注意的地方。經過這些藍色的輸出來肯定你的服務器該怎麼調整容量大小,而且檢查是否達到調整的預期。服務器
思路:首先查看swap的大小及分區,而後調整swap大小,使vg中有空餘的空間能夠給根分區的lv進行補充。而後重建swap,掛載swap,檢查vg的空餘容量顯示是否正常,而後給根分區的lv擴容,resize2fs,完成。app
此操做爲真實線上服務器的調整記錄,供朋友們參考,在真實上線操做以前,請務必在與你在的平臺徹底相同的實驗環境進行詳細的測試,而後方可實施操做。個人系統環境是:ide
操做系統: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 60
Swap: 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 62142
Swap: 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 62206
Swap: 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/LogVol01
Setting 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 62175
Swap: 65439 0 65439
[root@server10 ~]# free -g
total used free shared buffers cached
Mem: 62 62 0 0 0 60
-/+ buffers/cache: 2 60
Swap: 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 -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 ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 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 ~]# ui