fdisk /dev/vdb ##添加分区 n t 8e ##格式8e wq ###代码
[root@server11 Desktop]# fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xa30e1d11. Command (m for help): p Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xa30e1d11 Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M Partition 1 of type Linux and of size 100 MiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (206848-20971519, default 206848): Using default value 206848 Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M Partition 2 of type Linux and of size 100 MiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.pvcreate /dev/vdb1 ##创造pv(小容器) vgcreate vg0 /dev/vdb1 ##创造vg(大容器) lvcreate -L 100M -n lv0 vg0 #给自己喝的杯子添加 mkfs.xfs /dev/vg0/lv0 #同时给自己喝的杯子格式化文件系统 mount /dev/vg0/lv0 /mnt #挂载 ll /dev/mapper/vg0-lv0 #查看 ll /dev/vg0/lv0 #和上面同一个东西 lvextend -L 150M /dev/vg0/lv0 #lv扩充(扩充到150M) xfs_growfs /dev/vg0/lv0 #文件系统的扩充 fdisk /dev/vdb #pv不够了,添加,通过增加磁盘分区 pvcreate /dev/vdb2 #创造pv vgextend vg0 /dev/vg0/lv0 #扩充容器 lvextend -L 300M /dev/vg0/lv0 #扩充杯子 xfs_growfs /dev/vg0/lv0 #扩充文件系统
[root@server11 Desktop]# pvcreate /dev/vdb1 Physical volume "/dev/vdb1" successfully created [root@server11 Desktop]# pvcreate /dev/vdb2 Physical volume "/dev/vdb2" successfully created [root@server11 Desktop]# vgcreate vg0 /dev/vdb1 Volume group "vg0" successfully created [root@server11 Desktop]# vgextend vg0 /dev/vdb2 Volume group "vg0" successfully extended [root@server11 Desktop]# lvcreate -L 50M -n lv0 vg0 Rounding up size to full physical extent 52.00 MiB Logical volume "lv0" created [root@server11 Desktop]# mkfs.xfs /dev/vg0/lv0 meta-data=/dev/vg0/lv0 isize=256 agcount=2, agsize=6656 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=13312, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@server11 Desktop]# mount /dev/vg0/lv0 /mnt [root@server11 Desktop]# ll /dev/mapper/vg0-lv0 lrwxrwxrwx. 1 root root 7 Aug 5 01:44 /dev/mapper/vg0-lv0 -> ../dm-0 [root@server11 Desktop]# lvextend -L 80M /dev/vg0/lv0 Extending logical volume lv0 to 80.00 MiB Logical volume lv0 successfully resized [root@server11 Desktop]# xfs_growfs /dev/vg0/lv0 meta-data=/dev/mapper/vg0-lv0 isize=256 agcount=2, agsize=6656 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=13312, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 13312 to 20480换文件系统 umount /mnt/ #取消挂载 mkfs.ext4 /dev/vg0/lv0 #换成ext4 lvextend -L 400M /dev/vg0/lv0 #扩充lv resize2fs /dev/vg0/lv0 #扩充文件系统 umount /mnt/ #取消挂载 e2fsck -f /dev/vg0/lv0 #检测是否可以缩减 resize2fs /dev/vg0/lv0 100M #先缩减文件系统 mount /dev/vg0/lv0 /mnt #挂载 lvreduce -L 100M /dev/vg0/lv0 #缩减硬件
[root@server11 Desktop]# umount /mnt [root@server11 Desktop]# mkfs.ext4 /dev/vg0/lv0 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 20480 inodes, 81920 blocks 4096 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=33685504 10 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done [root@server11 Desktop]# lvextend -L 150M /dev/vg0/lv0 Rounding size to boundary between physical extents: 152.00 MiB Extending logical volume lv0 to 152.00 MiB Logical volume lv0 successfully resized [root@server11 Desktop]# resize2fs /dev/vg0/lv0 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/vg0/lv0 to 155648 (1k) blocks. The filesystem on /dev/vg0/lv0 is now 155648 blocks long.缩减时,先缩文件系统,缩文件系统要取消挂载
[root@server11 Desktop]# umount /mnt/ umount: /mnt/: not mounted [root@server11 Desktop]# e2fsck -f /dev/vg0/lv0 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/vg0/lv0: 11/38912 files (9.1% non-contiguous), 10561/155648 blocks [root@server11 Desktop]# resize2fs /dev/vg0/lv0 80M resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/vg0/lv0 to 81920 (1k) blocks. The filesystem on /dev/vg0/lv0 is now 81920 blocks long. [root@server11 Desktop]# mount /dev/vg0/lv0 /mnt [root@server11 Desktop]# lvreduce -L 80M /dev/vg0/lv0 WARNING: Reducing active and open logical volume to 80.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv0? [y/n]: y Reducing logical volume lv0 to 80.00 MiB Logical volume lv0 successfully resized [root@server11 Desktop]#取出正在用的pv pvmove /dev/vdb1 /dev/vdb2 #将文件转移到 /dev/vdb2 vgreduce vg0 /dev/vdb1 #拔了 pvremove /dev/vdb2 #取了
[root@server11 Desktop]# pvmove /dev/vdb1 /dev/vdb2 /dev/vdb1: Moved: 15.0% /dev/vdb1: Moved: 100.0% [root@server11 Desktop]# vgreduce vg0 /dev/vdb1 Removed "/dev/vdb1" from volume group "vg0" [root@server11 Desktop]# pvremove /dev/vdb1 Labels on physical volume "/dev/vdb1" successfully wiped [root@server11 Desktop]#设备快照 touch /mnt/file{1..100} 建立文件 ls /mnt/ 查看 rm -rf /mnt/* 删除 ls /mnt/ 查看 touch /mnt/file{1..100} 建立 umount /mnt 取消挂载 df 查看 ls /mnt/ lvcreate -L 20M -n lv0-backup -s /dev/vg0/lv0 #设备快照 mount /dev/vg0/lv0-backup /mnt/ 挂载 ls /mnt/ rm -rf /mnt/* 删除 ls /mnt/ umount /mnt/ lvremove /dev/vg0/lv0-backup #取消快照 lvcreate -L 20M -n lv0-backup -s /dev/vg0/lv0 mount /dev/vg0/lv0-backup /mnt/ ls /mnt/ ###删除 df 查看 umount /mnt/ 取消挂载 df 查看 lvremove /dev/vg0/lv0-backup 删除lv快照 lvremove /dev/vg0/lv0 删除lv vgremove vg0 删除vg0 pvremove /dev/vdb2 删除 vdb2 pvs ######## vgs ##查看## lvs #######