AWS-LVM 男娘i 2022-05-26 09:41 226阅读 0赞 LVM相关命令解释 vg管理工具: vgs #查看vg简要信息 vgdisplay #查看vg详细信息 vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...] //创建vg vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...] //扩展vg容量 vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...] //缩减vg容量 vgremove VolumeGroupName //删除vg lv管理工具: lvs #查看lv简要信息 lvdisplay #查看lv详细信息 lvcreate -L #[mMgGtT] -n NAME VolumeGroup //创建lv lvremove /dev/VG_NAME/LV_NAME //删除lv 扩展逻辑卷: lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME //扩展逻辑卷 resize2fs /dev/VG_NAME/LV_NAME //重新定义文件系统大小 缩减逻辑卷: umount /dev/VG_NAME/LV_NAME //卸载lv e2fsck -f /dev/VG_NAME/LV_NAME //检查lv resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT] //重新定义lv大小 lvreduce -L [-] [mMgGtT] /dev/VG_NAME/LV_NAME //缩减lv ==================================================================== 一、新增加盘--挂载(样例) ==================================================================== [root@innerCoreService1 ~]# fdisk -l Disk /dev/sda: 53.7 GB, 53687091200 bytes 64 heads, 32 sectors/track, 51200 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000b9693 Device Boot Start End Blocks Id System /dev/sda1 * 2 501 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 502 51200 51915776 8e Linux LVM Partition 2 does not end on cylinder boundary. Disk /dev/sdb: 161.1 GB, 161061273600 bytes 255 heads, 63 sectors/track, 19581 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_root: 75.2 GB, 75161927680 bytes 255 heads, 63 sectors/track, 9137 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_home: 118.1 GB, 118111600640 bytes 255 heads, 63 sectors/track, 14359 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 ===================================================================== [root@innerCoreService1 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root ext4 69G 5.9G 60G 9% / tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm /dev/sda1 ext4 477M 34M 419M 8% /boot /dev/mapper/VolGroup-lv_home ext4 109G 21G 83G 20% /home ==================================================================== 实例: /dev/mapper/VolGroup-lv_swap /dev/mapper/VolGroup-lv_root /dev/mapper/VolGroup-lv_home ===================================================================== [root@innerCoreService1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom sda 8:0 0 50G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 49.5G 0 part ├─VolGroup-lv_swap (dm-0) 253:0 0 8G 0 lvm [SWAP] ├─VolGroup-lv_root (dm-1) 253:1 0 70G 0 lvm / └─VolGroup-lv_home (dm-2) 253:2 0 110G 0 lvm /home sdb 8:16 0 150G 0 disk ├─VolGroup-lv_root (dm-1) 253:1 0 70G 0 lvm / └─VolGroup-lv_home (dm-2) 253:2 0 110G 0 lvm / ===================================================================== ====================================================================== 二、新增加盘--挂载---创建逻辑卷 ===================================================================== root@ip-172-31-2-252:/# apt-get install lvm2 root@ip-172-31-2-252:/# fdisk -l Disk /dev/xvda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders, total 125829120 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 identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/xvda1 * 16065 125821079 62902507+ 83 Linux /dev/xvda2 2048 16064 7008+ 5 Extended Partition table entries are not in disk order Disk /dev/xvdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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 identifier: 0x00000000 root@ip-172-31-2-252:/# pvcreate /dev/xvdb //将xvdb 硬盘添加到PV池中 Physical volume "/dev/xvdb" successfully created // 提示成功 root@ip-172-31-2-252:/# root@ip-172-31-2-252:/# pvs //查看PV池 PV VG Fmt Attr PSize PFree /dev/xvdb lvm2 a-- 20.00g 20.00g root@ip-172-31-2-252:/# # vgcreate VolGroup /dev/xvdb // 创建名称为"VolGroup" vg 卷 Volume group "VolGroup" successfully created //提示成功 root@ip-172-31-2-252:/# vgs VG #PV #LV #SN Attr VSize VFree //查看 vgs 池 VolGroup 1 0 0 wz--n- 20.00g 20.00g root@ip-172-31-2-252:/# lvcreate -L 19G -n lv_svn_newdata VolGroup //创建挂载盘上的目录 lv_svn_newdata Logical volume "lv_svn_newdata" created root@ip-172-31-2-252:/# mkfs.ext4 /dev/mapper/VolGroup-lv_svn_newdata mke2fs 1.42.9 (4-Feb-2014) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1245184 inodes, 4980736 blocks 249036 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 152 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done root@ip-172-31-2-252:/# mount /dev/mapper/VolGroup-lv_svn_newdata /svn_newdata root@ip-172-31-2-252:/# df -hT |grep svn_newdata /dev/mapper/VolGroup-lv_svn_newdata ext4 19G 44M 18G 1% /svn_newdata ubuntu@ip-172-31-2-252:~$ blkid /dev/xvda1: LABEL="cloudimg-rootfs" UUID="34b4dbb4-ac4c-4998-be97-bf192941c651" TYPE="ext4" /dev/mapper/VolGroup-lv_svn_newdata: UUID="dd7be311-2763-469b-b56f-62cb0fb6742d" TYPE="ext4" /dev/xvdb: UUID="l4ldoL-A2Hz-7d6O-QIb7-9W3A-NCxr-Rf0yEL" TYPE="LVM2_member" root@ip-172-31-2-252:/home/ubuntu# vim /etc/fstab LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0 UUID=dd7be311-2763-469b-b56f-62cb0fb6742d /svn_newdata ext4 defaults,discard 0 0 ====================================================================== 三、新增加盘--挂载---扩展逻辑卷 ====================================================================== [root@ip-172-31-2-251 data]# pvcreate /dev/xvdh //将xvdh 硬盘添加到PV池中 Physical volume "/dev/xvdh" successfully created // 提示成功 [root@ip-172-31-2-251 data]# pvs //查看PV池 PV VG Fmt Attr PSize PFree /dev/xvdf1 vgdata lvm2 a--u 100.00g 0 /dev/xvdg vgdata lvm2 a--u 1024.00g 0 /dev/xvdh vgdata lvm2 a--u 1024.00g 47.99g [root@ip-172-31-2-251 ~]# vgextend vgdata /dev/xvdh //创建名称为vgdata的卷组,由/dev/xvdh 提供PE Volume group "vgdata" successfully extended // 提示创建成功 [root@ip-172-31-2-251 ~]# lvs //查看lv简要信息 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lvdata vgdata -wi-ao---- 1.07t [root@ip-172-31-2-251 ~]# pvs //查看PV池 PV VG Fmt Attr PSize PFree /dev/xvdf1 vgdata lvm2 a--u 100.00g 0 /dev/xvdg vgdata lvm2 a--u 1024.00g 23.99g /dev/xvdh vgdata lvm2 a--u 1024.00g 1024.00g [root@ip-172-31-2-251 ~]# lvextend -L 2100G -n /dev/mapper/vgdata-lvdata // 扩展LV到2100G Size of logical volume vgdata/lvdata changed from 1.07 TiB (281600 extents) to 2.05 TiB (537600 extents). Logical volume lvdata successfully resized. [root@ip-172-31-2-251 ~]# lvs //查看lv简要信息 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lvdata vgdata -wi-ao---- 2.05t [root@ip-172-31-2-251 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/xvda1 ext4 7.8G 865M 6.6G 12% / tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/mapper/vgdata-lvdata ext4 1.1T 71M 1.1T 1% /data [root@ip-172-31-2-251 data]# resize2fs /dev/mapper/vgdata-lvdata resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vgdata-lvdata is mounted on /data; on-line resizing required old desc_blocks = 132, new_desc_blocks = 194 Performing an on-line resize of /dev/mapper/vgdata-lvdata to 812646400 (4k) blocks. The filesystem on /dev/mapper/vgdata-lvdata is now 812646400 blocks long.
还没有评论,来说两句吧...