日度归档:2017年3月14日

阿里云LVM 真·原地扩容 加硬盘 换硬盘 释放硬盘

阿里云原地扩容方案:添加一个新的云盘替换旧的硬盘

第一步:扩容pv(物理卷)

创建物理卷(直接使用整个硬盘)

pvcreate /dev/vdc

将新物理卷(新硬盘)添加到卷组vg1

vgextend vg1 /dev/vdc

设置旧物理卷(旧硬盘)为不可分配

pvchange -x n /dev/vdb

将旧硬盘上的数据移走(热处理 无损移动到其他硬盘 确保其他硬盘空间充足)

pvmove /dev/vdb

可以将旧物理卷(旧硬盘)从vg1移除

vgreduce vg1 /dev/vdb

将旧物理卷(旧硬盘)从LVM移除

pvremove /dev/vdb

完成,可以拔除/dev/vdb了,此时可以使用pvs命令看到PFree列即为空闲空间

第二步:扩容lv(逻辑卷)

给lv +1GB容量

lvextend -L +1G /dev/vg1/lv1

使新加的容量生效(ext4)

resize2fs /dev/mapper/vg1-lv1

或者 使新加的容量生效(xfs)

xfs_growfs /dev/mapper/vg1-lv1

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 ~]#