linux动态调整LV磁盘大小

之前曾经发过教程:

今天发现http://blog.csdn.net/a921122/article/details/51955764这里一个教程比较适合我今天机器具体情况。

机器分区具体信息:

[root@mx-42 /]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   50G  1.9G   45G   5% /
tmpfs                          32G     0   32G   0% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot
/dev/mapper/VolGroup-lv_home  389G  199M  369G   1% /home
客户一再强调,所有分区都给/,也就是磁盘挂载到/下,但是机房装机人员,有时候会按照他自己的想法和习惯,给客户提供机器。没办法,老易拿到机器后,还要根据客户具体要求,对磁盘分区做出调整。目标就是把/的50G空间,搞到最大。一看/home下有369G空间可用,那就总体思路是减小/home的空间,然后把这部分空间扩展到/去。

[root@mx-42 /]# pvdisplay
— Physical volume —
PV Name               /dev/sda2
VG Name               VolGroup
PV Size               476.45 GiB / not usable 0
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              121971
Free PE               0
Allocated PE          121971
PV UUID               FPGB3H-LS5O-Jhh2-66Jp-G1FC-C6QJ-CTqnCk

[root@mx-42 /]#  vgdisplay
— Volume group —
VG Name               VolGroup
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  4
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               476.45 GiB
PE Size               4.00 MiB
Total PE              121971
Alloc PE / Size       121971 / 476.45 GiB
Free  PE / Size       0 / 0
VG UUID               guDukn-EeCl-JMxR-usgg-4HTb-Kqp6-ppZGCA

以下是照葫芦画瓢,操作过程:

umount /home,先卸载/home,然后把/home变成1G

[root@mx-42 /]# resize2fs -p /dev/mapper/VolGroup-lv_home  1G
resize2fs 1.41.12 (17-May-2010)
Please run ‘e2fsck -f /dev/mapper/VolGroup-lv_home’ first.

提示:先进行磁盘检查。

[root@mx-42 /]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup-lv_home: 11/25886720 files (0.0% non-contiguous), 1675464/103529472 blocks

重新规划/home大小是1G:
[root@mx-42 /]# resize2fs -p /dev/mapper/VolGroup-lv_home  1G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 262144 (4k) blocks.
Begin pass 2 (max = 32768)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 3160)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 262144 blocks long.

[root@mx-42 /]# mount /home/
[root@mx-42 /]# mount -l
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/VolGroup-lv_home on /home type ext4 (rw)
[root@mx-42 /]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   50G  1.9G   45G   5% /
tmpfs                          32G     0   32G   0% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot
/dev/mapper/VolGroup-lv_home 1008M  149M  809M  16% /home

释放/home空间:
[root@mx-42 /]# lvreduce -L 1G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 1.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 1.00 GiB
Logical volume lv_home successfully resized

[root@mx-42 /]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   50G  1.9G   45G   5% /
tmpfs                          32G     0   32G   0% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot
/dev/mapper/VolGroup-lv_home 1008M  149M  809M  16% /home

[root@mx-42 /]# 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               476.45 GiB
PE Size               4.00 MiB
Total PE              121971
Alloc PE / Size       21124 / 82.52 GiB
Free  PE / Size       100847 / 393.93 GiB
VG UUID               guDukn-EeCl-JMxR-usgg-4HTb-Kqp6-ppZGCA
空闲空间加入到lv_root:
[root@mx-42 /]# lvextend -L +393.93G /dev/mapper/VolGroup-lv_root
Rounding size to boundary between physical extents: 393.93 GiB
Extending logical volume lv_root to 443.93 GiB
Logical volume lv_root successfully resized

最后一步要耐心等待,扩大越多,时间越长 :

[root@mx-42 /]# 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 = 28
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 116374528 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 116374528 blocks long.

[root@mx-42 /]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  437G  2.0G  413G   1% /
tmpfs                          32G     0   32G   0% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot
/dev/mapper/VolGroup-lv_home 1008M  149M  809M  16% /home

发表评论

邮箱地址不会被公开。 必填项已用*标注