linux系統lvm中lv使用空間的調整
阿新 • • 發佈:2018-11-06
ssl 格式 min df -h x64 3.5 begin fsck linu 前言:最近部署一個項目,甲方使用虛擬化平臺,給的服務器都是虛擬化克隆的機器,操作系統安裝時默認的分區,現狀是根分區只有50G,部署的時候使用軟連接創建的部署目錄,但是後續升級的同事沒有註意,就把部署直接放在根分區,導致近期數據同步時log文件大,使用的log日誌刪除腳本任務計劃未到執行執行時間服務日誌文件就把磁盤占滿了,處理如下。
一、系統環境:
操作系統:Centos_x64 6.5
內核版本:2.6.32-431.el6.X86_64
磁盤格式:EXT4
二、現有分區情況與說明
df -h #查看當前分區 Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 50G 17G 31G 36% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/sda1 485M 33M 427M 8% /boot /dev/mapper/VolGroup-lv_home 435G 9.7G 404G 3% /home
說明:可以清楚的看到兩個lv卷的分區VolGroup-lv_root掛載為了根分區50G,VolGroup-lv_home掛載為了/home分區,home分區比較大,卻沒有被使用。
三、釋放/home分區的占用並卸載/home分區
1、以為使用fuser -m /home就可以完成但是執行後卸載仍提示/home有占用。情況如下:
# fuser -m /home
/home: 24033ce
# umount /home umount: /home: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
2、檢查占用的文件,發現甲方提供的系統裏有金山的防護軟件,將軟件進程殺掉後卸載/home分區正常:
# lsof | grep /home --檢查發現占用的是金山的防護軟件直接運行了kiil -9 24033 KANLinuxC 24033 root cwd DIR 253,2 4096 5636103 /home/kingsoft/kavnet KANLinuxC 24033 root txt REG 253,2 1645332 5636130 /home/kingsoft/kavnet/KANMainModule KANLinuxC 24033 root mem REG 253,2 1369600 5636263 /home/kingsoft/kavnet/libcrypto.so.6 KANLinuxC 24033 root mem REG 253,2 323320 5636276 /home/kingsoft/kavnet/libssl.so.6 KANLinuxC 24033 root mem REG 253,2 34487 5636129 /home/kingsoft/kavnet/KANLocalComm.so KANLinuxC 24033 root mem REG 253,2 626402 5636131 /home/kingsoft/kavnet/KANNetComm.so KANLinuxC 24033 root mem REG 253,2 163342 5636265 /home/kingsoft/kavnet/libjson.so KANLinuxC 24033 root 3w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 10w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 11w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 13w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 20w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log
# umount /home --重新卸載未在報錯
未在報錯。
三、縮減VolGroup-lv_home這個LV的空間
1、檢查這個LV分區的信息是否正常;
# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結構
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
/dev/mapper/VolGroup-lv_home: 5779/28950528 files (2.2% non-contiguous), 4334183/115775488 blocks
2、調整VolGroup-lv_home分區大小;
#resize2fs -p /dev/mapper/VolGroup-lv_home 80G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 20971520 (4k) blocks.
Begin pass 2 (max = 50904)
正在重定位塊 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 3534)
正在掃描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 838)
正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 20971520 blocks long.
3、重新掛載home分區並檢查空間大小,可以發現/home的空間已經變小;
# mount /home
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 17G 31G 36% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/VolGroup-lv_home 79G 9.6G 66G 13% /home
4、將VolGroup-lv_home縮減出來的分區設置為空閑分區;
# lvreduce -L 80G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 80.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 80.00 GiB
Logical volume lv_home successfully resized
5、檢查空閑出的空間Free PE已經空出了361G;
# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 499.51 GiB
PE Size 4.00 MiB
Total PE 127874
Alloc PE / Size 35292 / 137.86 GiB
Free PE / Size 92582 / 361.65 GiB
VG UUID Ur7bJ4-hQKi-xx4R-f9Qt-INvG-fjBf-zcvJ4n
四、將縮減出的空間增加給VolGroup-lv_root這個LV
1、給VolGroup-lv_root增加空間;
# lvresize --size +361G /dev/VolGroup/lv_root
Extending logical volume lv_root to 410.71 GiB
Logical volume lv_root successfully resized
2、讓系統重新識別VolGroup-lv_root增加的空間;
# resize2fs -p /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 26
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 107665408 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 107665408 blocks long.
3、檢查最終結果,確認操作成功;
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 405G 23G 362G 6% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/VolGroup-lv_home 79G 3.5G 72G 5% /home
linux系統lvm中lv使用空間的調整