centos 擴充套件root根分割槽的大小

weixin_34162629發表於2015-07-05

目標:將VolGroup-lv_home縮小到125G,並將剩餘的空間新增給VolGroup-lv_root
 
1.首先檢視磁碟使用情況
[root@localhost ~]# df -h
檔案系統    容量  已用 可用  已用% 掛載點    
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hostname-lv_root
                       20G  8.7G  9.6G  48% /
tmpfs                 6.9G   72K  6.9G   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/vg_hostname-lv_home
                      171G  110G   53G  68% /home
/dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
/dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5

 
2、解除安裝/home
[root@localhost ~]# 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))

umount /home 如果提示無法解除安裝,則是有程式佔用/home,使用如下命令來終止佔用程式:
[root@localhost ~]# fuser -m /home  
/home:               31112m
top
kill -9 31112
 
3、調整分割槽大小
[root@localhost ~]# resize2fs -p /dev/mapper/vg_hostname-lv_home 125G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/vg_hostname-lv_home' first.

如果提示執行“e2fsck -f /dev/mapper/VolGroup-lv_home”,則執行相關命令:
[root@localhost ~]# e2fsck -f /dev/mapper/vg_hostname-lv_home 然後重新執行命令:
[root@localhost ~]# resize2fs -p /dev/mapper/vg_hostname-lv_home 125G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_hostname-lv_home to 32768000 (4k) blocks.
Begin pass 2 (max = 7110485)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1385)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 3237)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_hostname-lv_home is now 32768000 blocks long.

注:resize2fs 為重新設定磁碟大小,只是重新指定一下大小,並不對結果有影響,需要下面lvreduce的配合
 
4、掛載上/home,檢視磁碟使用情況
[root@localhost ~]# mount /home
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hostname-lv_root
                       20G  8.7G  9.6G  48% /
tmpfs                 6.9G   72K  6.9G   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
/dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5
/dev/mapper/vg_hostname-lv_home
                      124G  110G  7.4G  94% /home

 
5、設定空閒空間
使用lvreduce指令用於減少LVM邏輯卷佔用的空間大小。可能會刪除邏輯捲上已有的資料,所以在操作前必須進行確認。記得輸入 “y”
[root@localhost ~]# lvreduce -L 125G /dev/mapper/vg_hostname-lv_home
  WARNING: Reducing active and open logical volume to 125.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 125.00 GiB
  Logical volume lv_home successfully resized

注:lvreduce -L 125G的意思為設定當前檔案系統為125G,如果lvreduce -l 125G是指從當前檔案系統上減少125G
使用lvreduce減小邏輯卷的大小。注意:減小後的大小不能小於檔案的大小,否則會丟失資料。
 
可以使用vgdisplay命令等檢視一下可以操作的大小。也可以是用fdisk -l命令檢視詳細資訊。
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_hostname
  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               199.51 GiB
  PE Size               4.00 MiB
  Total PE              51074
  Alloc PE / Size       38758 / 151.40 GiB
  Free  PE / Size       12316 / 48.11 GiB
  VG UUID               zk1eHH-QXe8-sdm8-cKfF-StSl-yffz-Dfe9sF
注:vgdisplay為顯示LVM卷組的後設資料資訊
 
6.把閒置空間掛在到根目錄下
[root@localhost ~]# lvextend -L +48G /dev/mapper/vg_hostname-lv_root
  Extending logical volume lv_root to 67.53 GiB
  Logical volume lv_root successfully resized
注:lvextend -L +48G為在檔案系統上增加48G
[root@localhost ~]# resize2fs -p /dev/mapper/vg_hostname-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_hostname-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 5
Performing an on-line resize of /dev/mapper/vg_hostname-lv_root to 17702912 (4k) blocks.
The filesystem on /dev/mapper/vg_hostname-lv_root is now 17702912 blocks long.

7、檢查調整結果
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hostname-lv_root
                       67G  8.7G   55G  14% /
tmpfs                 6.9G   72K  6.9G   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
/dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5
/dev/mapper/vg_hostname-lv_home
                      124G  110G  7.4G  94% /home

相關文章