首页 > 代码库 > 利用LVS调整目录空间

利用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 -p /dev/mapper/vg_vhost-lv_home 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、缩减
#resize2fs -p /dev/mapper/vg_vhost-lv_home 2T
resize2fs 1.41.12 (17-May-2010)
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
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
                      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).
  Logical volume lv_root successfully resized.
12、查看空间,纳闷啊!!
#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
                      2.0T   15G  1.9T   1% /home
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
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_vhost-lv_root
                      3.4T   40G  3.2T   2% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/sda1             477M   28M  425M   7% /boot
/dev/mapper/vg_vhost-lv_home
                      2.0T   15G  1.9T   1% /home


本文出自 “网络你我” 博客,谢绝转载!

利用LVS调整目录空间