逻辑卷管理器LVM扩展,缩减,快照,删除

来源:互联网 发布:爱奇艺视频下载软件 编辑:程序博客网 时间:2024/05/23 13:24

扩展:
[root@localhost ~]# pvcreate /dev/vdb2 ##新建新的PV
[root@localhost ~]# lvextend -L 900M /dev/vg0/lv0 ##-L表示扩展到 ,LV扩展到900M
[root@localhost ~]# vgextend vg0 /dev/vdb2 ##加大VG 将/dev/vdb2添加到VG
[root@localhost ~]# resize2fs /dev/vg0/lv0 ##完整的将LV的容量扩充到整个文件系统
[root@localhost ~]# xfs_growfs /dev/vg0/lv0    ##同步
[root@localhost ~]# umount /weixindata/
[root@localhost ~]# mkfs.ext4 /dev/vg0/lv0   ##格式化为ext4文件系统
[root@localhost ~]# mount /dev/vg0/lv0 /weixindata/
[root@localhost ~]# df
缩减:
[root@localhost ~]# umount /weixindata/
[root@localhost ~]# e2fsck -f /dev/vg0/lv0 ##扫描
[root@localhost ~]# resize2fs /dev/vg0/lv0 300M ##文件系统缩减300M
[root@localhost ~]# mount /dev/vg0/lv0 /weixindata/
[root@localhost ~]# lvreduce -L 300 /dev/vg0/lv0 缩减lV到300M
[root@localhost ~]# pvmove /dev/vdb1 /dev/vdb2 数据移动
[root@localhost ~]# vgreduce vg0 /dev/vdb1 ##删除
[root@localhost ~]# pvremove /dev/vdb1      ##删除
快照
[root@localhost ~]# touch /weixindata/file{1..10}
[root@localhost ~]# ls /weixindata/
[root@localhost ~]# lvcreate -L 50M -n lv0backup -s /dev/vg0/lv0 ##建立快照 大小一般为文件的大小
[root@localhost ~]# umount /weixindata/
[root@localhost ~]# mount /dev/vg0/lv0backup /weixindata/
[root@localhost ~]# ls /weixindata/
[root@localhost ~]# umount /weixindata/
[root@localhost ~]# lvremove /dev/vg0/lv0backup
  ##快照删除
[root@localhost ~]# lvcreate -L 50M -n lv0backup -s /dev/vg0/lv0
[root@localhost ~]# mount /dev/vg0/lv0backup /weixindata/
[root@localhost ~]# ls /weixindata/
删除
[root@localhost ~]# umount /weixindata/
[root@localhost ~]# lvremove /dev/vg0/lv0backup
  ##删除快照
[root@localhost ~]# lvremove /dev/vg0/lv0
     ##删除LV
[root@localhost ~]# vgremove vg0
         ##删除VG
[root@localhost ~]# pvremove /dev/vdb2
    ##去掉PV

监控[root@localhost ~]#  watch -n 1 'echo ==pvmessage==;pvs;echo ==vgmessage==;vgs;echo ==lvm message==;lvs;echo ====;df -h /weixindata'

操作

扩展[root@localhost ~]# lvextend -L 900M /dev/vg0/lv0    ##-L表示扩展到 ,LV扩展到900M     Extending logical volume lv0 to 900.00 MiB  Logical volume lv0 successfully resized[root@localhost ~]# xfs_growfs /dev/vg0/lv0     ##同步meta-data=/dev/mapper/vg0-lv0    isize=256    agcount=4, agsize=19200 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=0data     =                       bsize=4096   blocks=76800, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=0log      =internal               bsize=4096   blocks=853, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0data blocks changed from 76800 to 230400[root@localhost ~]# lvextend -L 1500M /dev/vg0/lv0  Extending logical volume lv0 to 1.46 GiB  Insufficient free space: 150 extents needed, but only 30 available[root@localhost ~]# pvcreate /dev/vdb2   ##新建新的PV  Physical volume /dev/vdb2 not foundWARNING: linux_raid_member signature detected on /dev/vdb2 at offset 4096. Wipe it? [y/n] y  Wiping linux_raid_member signature on /dev/vdb2.  Physical volume "/dev/vdb2" successfully created[root@localhost ~]# vgextend vg0 /dev/vdb2   ##加大VG 将/dev/vdb2添加到VG  Volume group "vg0" successfully extended[root@localhost ~]# lvextend -L 1500M /dev/vg0/lv0  ##扩展LV到1500M  Extending logical volume lv0 to 1.46 GiB  Logical volume lv0 successfully resized[root@localhost ~]# xfs_growfs /dev/vg0/lv0    ##同步meta-data=/dev/mapper/vg0-lv0    isize=256    agcount=12, agsize=19200 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=0data     =                       bsize=4096   blocks=230400, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=0log      =internal               bsize=4096   blocks=853, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0data blocks changed from 230400 to 384000[root@localhost ~]# umount /weixindata/[root@localhost ~]# mkfs.ext4 /dev/vg0/lv0   ##格式化为ext4文件系统mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks96000 inodes, 384000 blocks19200 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=39426457612 block groups32768 blocks per group, 32768 fragments per group8000 inodes per groupSuperblock backups stored on blocks:     32768, 98304, 163840, 229376, 294912Allocating group tables: done                            Writing inode tables: done                            Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: done [root@localhost ~]# mount /dev/vg0/lv0 /weixindata/[root@localhost ~]# dfFilesystem          1K-blocks    Used Available Use% Mounted on/dev/vda1            10473900 3151296   7322604  31% /devtmpfs               927072       0    927072   0% /devtmpfs                  942660      80    942580   1% /dev/shmtmpfs                  942660   17040    925620   2% /runtmpfs                  942660       0    942660   0% /sys/fs/cgroup/dev/mapper/vg0-lv0   1479088    4512   1381392   1% /weixindata
缩减 [root@localhost ~]# umount /weixindata/[root@localhost ~]# e2fsck -f /dev/vg0/lv0  ##扫描e2fsck 1.42.9 (28-Dec-2013)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/vg0/lv0: 11/96000 files (9.1% non-contiguous), 15356/384000 blocks[root@localhost ~]# resize2fs /dev/vg0/lv0 300M    缩减300Mresize2fs 1.42.9 (28-Dec-2013)Resizing the filesystem on /dev/vg0/lv0 to 76800 (4k) blocks.The filesystem on /dev/vg0/lv0 is now 76800 blocks long.[root@localhost ~]# mount /dev/vg0/lv0 /weixindata/[root@localhost ~]# lvreduce -L 300 /dev/vg0/lv0   缩减lV到300M  WARNING: Reducing active and open logical volume to 300.00 MiB  THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce lv0? [y/n]: y  Reducing logical volume lv0 to 300.00 MiB  Logical volume lv0 successfully resized[root@localhost ~]# pvmove /dev/vdb1 /dev/vdb2     数据移动  /dev/vdb1: Moved: 1.3%  /dev/vdb1: Moved: 100.0%[root@localhost ~]# vgreduce vg0 /dev/vdb1        ##删除  Removed "/dev/vdb1" from volume group "vg0"[root@localhost ~]# pvremove /dev/vdb1      ##删除  Labels on physical volume "/dev/vdb1" successfully wiped  
快照[root@localhost ~]# touch /weixindata/file{1..10}[root@localhost ~]# ls /weixindata/file1   file2  file4  file6  file8  lost+foundfile10  file3  file5  file7  file9[root@localhost ~]# lvcreate -L 50M -n lv0backup -s /dev/vg0/lv0   ##建立快照 大小一般为文件的大小  Rounding up size to full physical extent 52.00 MiB  Logical volume "lv0backup" created[root@localhost ~]# umount /weixindata/[root@localhost ~]# mount /dev/vg0/lv0backup /weixindata/[root@localhost ~]# ls /weixindata/file1   file2  file4  file6  file8  lost+foundfile10  file3  file5  file7  file9[root@localhost ~]# umount /weixindata/[root@localhost ~]# lvremove /dev/vg0/lv0backup   ##删除快照Do you really want to remove active logical volume lv0backup? [y/n]: y  Logical volume "lv0backup" successfully removed[root@localhost ~]# lvcreate -L 50M -n lv0backup -s /dev/vg0/lv0  ##重新建立快照  Rounding up size to full physical extent 52.00 MiB  Logical volume "lv0backup" created[root@localhost ~]# mount /dev/vg0/lv0backup /weixindata/[root@localhost ~]# ls /weixindata/    ##查看文件是否还在file1   file2  file4  file6  file8  lost+foundfile10  file3  file5  file7  file9删除[root@localhost ~]# umount /weixindata/[root@localhost ~]# lvremove /dev/vg0/lv0backup Do you really want to remove active logical volume lv0backup? [y/n]: y  Logical volume "lv0backup" successfully removed[root@localhost ~]# lvremove /dev/vg0/lv0Do you really want to remove active logical volume lv0? [y/n]: y  Logical volume "lv0" successfully removed[root@localhost ~]# vgremove vg0  Volume group "vg0" successfully removed[root@localhost ~]# pvremove /dev/vdb2  Labels on physical volume "/dev/vdb2" successfully wiped[root@localhost ~]# 
0 0
原创粉丝点击