LVM新加磁盘

新加磁盘为: /dev/vdc
LVM vg名称为: vg1

vgextend vg1 /dev/vdc

 

一次无损减小磁盘空间

[root@i ~]#
[root@i ~]# vgex
vgexport vgextend
[root@i ~]# vgex
vgexport vgextend
[root@i ~]# vgextend vg1 /dev/xvdb
Physical volume “/dev/xvdb” successfully created.
Volume group “vg1” successfully extended
[root@i ~]#
[root@i ~]#
[root@i ~]# ll
total 0
[root@i ~]# vg
vgcfgbackup vgchange vgconvert vgdisplay vgextend vgimportclone vgmknodes vgremove vgs vgsplit
vgcfgrestore vgck vgcreate vgexport vgimport vgmerge vgreduce vgrename vgscan
[root@i ~]# lv
lvchange lvcreate lvextend lvmchange lvmconfig lvmdump lvmpolld lvmsar lvremove lvresize lvscan
lvconvert lvdisplay lvm lvmconf lvmdiskscan lvmetad lvmsadc lvreduce lvrename lvs
[root@i ~]# pv
pvchange pvck pvcreate pvdisplay pvmove pvremove pvresize pvs pvscan
[root@i ~]# pvmove /dev/xvdb
No data to move for vg1
[root@i ~]# pvmove /dev/xvdi
Insufficient free space: 2292 extents needed, but only 1279 available
Unable to allocate mirror extents for pvmove0.
Failed to convert pvmove LV to mirrored
[root@i ~]#
[root@i ~]#
[root@i ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 41152832 2672832 36366516 7% /
devtmpfs 931496 0 931496 0% /dev
tmpfs 941156 0 941156 0% /dev/shm
tmpfs 941156 332 940824 1% /run
tmpfs 941156 0 941156 0% /sys/fs/cgroup
/dev/mapper/vg1-lvLog 3948224 16412 3708176 1% /mnt/log
/dev/mapper/vg1-lvData 5029504 453948 4297028 10% /mnt/data
tmpfs 188232 0 188232 0% /run/user/0
[root@i ~]#
[root@i ~]#
[root@i ~]# umount /mnt/log
[root@i ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 41152832 2672832 36366516 7% /
devtmpfs 931496 0 931496 0% /dev
tmpfs 941156 0 941156 0% /dev/shm
tmpfs 941156 332 940824 1% /run
tmpfs 941156 0 941156 0% /sys/fs/cgroup
/dev/mapper/vg1-lvData 5029504 453948 4297028 10% /mnt/data
tmpfs 188232 0 188232 0% /run/user/0
[root@i ~]# e2fsck -f /dev/vg
vg1/ vga_arbiter
[root@i ~]# e2fsck -f /dev/vg
vg1/ vga_arbiter
[root@i ~]# e2fsck -f /dev/vg1/lvLog
e2fsck 1.42.9 (28-Dec-2013)
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/vg1/lvLog: 14/262144 files (0.0% non-contiguous), 53335/1036288 blocks
[root@i ~]# resize -f /dev/vg1/lvLog
resize2fs resizecons resizepart
[root@i ~]# resize2fs -f /dev/vg1/lvLog 500M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lvLog to 128000 (4k) blocks.
The filesystem on /dev/vg1/lvLog is now 128000 blocks long.

[root@i ~]# lvresize -L 500M /dev/vg1/lvLog 500M
Physical Volume “500M” not found in Volume Group “vg1”.
[root@i ~]# lvresize -L 500M /dev/vg1/lvLog
WARNING: Reducing active logical volume to 500.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lvLog? [y/n]: Y
Size of logical volume vg1/lvLog changed from 3.95 GiB (1012 extents) to 500.00 MiB (125 extents).
Logical volume vg1/lvLog successfully resized.
[root@i ~]# mount -a
[root@i ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 40G 2.6G 35G 7% /
devtmpfs 910M 0 910M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 332K 919M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/mapper/vg1-lvData 4.8G 444M 4.1G 10% /mnt/data
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg1-lvLog 364M 6.1M 323M 2% /mnt/log
[root@i ~]# ll
total 0
[root@i ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 41152832 2672836 36366512 7% /
devtmpfs 931496 0 931496 0% /dev
tmpfs 941156 0 941156 0% /dev/shm
tmpfs 941156 332 940824 1% /run
tmpfs 941156 0 941156 0% /sys/fs/cgroup
/dev/mapper/vg1-lvData 5029504 453948 4297028 10% /mnt/data
tmpfs 188232 0 188232 0% /run/user/0
/dev/mapper/vg1-lvLog 372680 6192 330652 2% /mnt/log
[root@i ~]# cd /mnt/log/
[root@i log]# ll
total 24
drwx—— 2 root root 16384 Nov 7 02:59 lost+found
drwxr-xr-x 2 redis redis 4096 Jan 13 20:10 mongodb
-rw-r–r– 1 root root 194 Mar 9 21:56 php_errors.log
[root@i log]#
[root@i log]#
[root@i log]#
[root@i log]# cd
[root@i ~]#
[root@i ~]#
[root@i ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 41152832 2672836 36366512 7% /
devtmpfs 931496 0 931496 0% /dev
tmpfs 941156 0 941156 0% /dev/shm
tmpfs 941156 332 940824 1% /run
tmpfs 941156 0 941156 0% /sys/fs/cgroup
/dev/mapper/vg1-lvData 5029504 453948 4297028 10% /mnt/data
tmpfs 188232 0 188232 0% /run/user/0
/dev/mapper/vg1-lvLog 372680 6192 330652 2% /mnt/log
[root@i ~]#