天天看點

利用LVS調整目錄空間

0、看有沒有lvs

#lvs

  LV      VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  lv_home vg_vhost -wi-ao----  5.40t                                                    

  lv_root vg_vhost -wi-ao---- 50.00g                                                    

  lv_swap vg_vhost -wi-ao----  7.80g

1、先來檢視一下系統的空間配置設定情況

#df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_vhost-lv_root

                       50G   40G  7.0G  86% /

tmpfs                 7.8G     0  7.8G   0% /dev/shm

/dev/sda1             477M   28M  425M   7% /boot

/dev/mapper/vg_vhost-lv_home

                      5.4T   15G  5.1T   1% /home

2、目标-》增加 /空間,減少 /home空間,縮減vg_vhost-lv_home到2T

#resize2fs -p /dev/mapper/vg_vhost-lv_home 2T

Filesystem at /dev/mapper/vg_vhost-lv_home is mounted on /home; on-line resizing required

On-line shrinking from 1449448448 to 536870912 not supported.

提示,線上不中

3、解除安裝目錄

#umount /home

4、縮減到2T

resize2fs 1.41.12 (17-May-2010)

請先運作 'e2fsck -f /dev/mapper/vg_vhost-lv_home'.

5、提示先檢查

#e2fsck -f /dev/mapper/vg_vhost-lv_home

e2fsck 1.41.12 (17-May-2010)

第一步: 檢查inode,塊,和大小

第二步: 檢查目錄結構

第3步: 檢查目錄連接配接性

Pass 4: Checking reference counts

第5步: 檢查簇概要資訊

/dev/mapper/vg_vhost-lv_home: 21/362364928 files (4.8% non-contiguous), 26516105/1449448448 blocks

6、縮減

Resizing the filesystem on /dev/mapper/vg_vhost-lv_home to 536870912 (4k) blocks.

Begin pass 2 (max = 32768)

正在重定位塊            XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Begin pass 3 (max = 44234)

正在掃描inode表          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The filesystem on /dev/mapper/vg_vhost-lv_home is now 536870912 blocks long.

7、重新加載目錄

#mount /home

# df -h

                      2.0T   15G  1.9T   1% /home

8、使生效,分出空間可用。注意如果有資料,要小于2T,否則丢人

#lvreduce -L 2T /dev/mapper/vg_vhost-lv_home

WARNING: Reducing active and open logical volume to 2.00 TiB.

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce vg_vhost/lv_home? [y/n]: y

  Size of logical volume vg_vhost/lv_home changed from 5.40 TiB (1415477 extents) to 2.00 TiB (524288 extents).

  Logical volume lv_home successfully resized.

9、查詢卷組的資訊:

Free PE / Size指定的應該是現在可在配置設定的空間

#vgdisplay

  --- Volume group ---

  VG Name               vg_vhost

  System ID             

  Format                lvm2

  Metadata Areas        2

  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                2

  Act PV                2

  VG Size               5.46 TiB

  PE Size               4.00 MiB

  Total PE              1430273

  Alloc PE / Size       539084 / 2.06 TiB

  Free  PE / Size       891189 / 3.40 TiB

  VG UUID               q9cgCG-rlm0-KGYo-Z7xq-6JyO-1hAT-E0ZWpf

10、将可用的空間添加到 /

#lvextend -L +3.4T /dev/mapper/vg_vhost-lv_root

 Rounding size to boundary between physical extents: 3.40 TiB.

  Insufficient free space: 891290 extents needed, but only 891189 available

#lvextend -L +3.39T /dev/mapper/vg_vhost-lv_root

  Rounding size to boundary between physical extents: 3.39 TiB.

  Size of logical volume vg_vhost/lv_root changed from 50.00 GiB (12800 extents) to 3.44 TiB (901469 extents).

  Logical volume lv_root successfully resized.

11、還是-l後面的參數好用,呵呵

#lvextend -l +100%FREE /dev/mapper/vg_vhost-lv_root

Size of logical volume vg_vhost/lv_root changed from 3.45 TiB (903986 extents) to 3.45 TiB (903989 extents).

12、檢視空間,納悶啊!!

13、使生效,這個過程可慢,線上啊……

#resize2fs -p /dev/mapper/vg_vhost-lv_root

Filesystem at /dev/mapper/vg_vhost-lv_root is mounted on /; on-line resizing required

old desc_blocks = 4, new_desc_blocks = 221

Performing an on-line resize of /dev/mapper/vg_vhost-lv_root to 925684736 (4k) blocks.

The filesystem on /dev/mapper/vg_vhost-lv_root is now 925684736 blocks long.

14、檢視空間,ok

                      3.4T   40G  3.2T   2% /

本文轉自 古老 51CTO部落格,原文連結:http://blog.51cto.com/yzmlinux/1928807,如需轉載請自行聯系原作者

繼續閱讀