lvm基本操作
lvm 操作,格式化,挂载
该图来自: https://www.cnblogs.com/diantong/p/10554831.html
多个磁盘/分区/raid PE-->多个物理卷PV-->合成卷组VG-->从VG划分出逻辑卷LV-->格式化LV,挂载 1 添加磁盘 2 PE操作 测试,PE使用使用分区 ,也可使用磁盘,raid //删除原第二个分区,重新分第二个分区,修改为lvm,保存 [root@controller /]# fdisk /dev/sdb //对第二块磁盘操作 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. Command (m for help): m //m 查看帮助 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): p //p 查看当前分区 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 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 label type: dos Disk identifier: 0x2ae54b43 Device Boot Start End Blocks Id System /dev/sdb1 2048 6293503 3145728 8e Linux LVM /dev/sdb2 6293504 16779263 5242880 5 Extended Command (m for help): d //d 删除分区, Partition number (1,2, default 2): 2 //删除分区2 Partition 2 is deleted Command (m for help): n //n 创建分区 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p //创建主分区 Partition number (2-4, default 2): 2 //创建第二个主分区 First sector (6293504-41943039, default 6293504): // 保持默认 Using default value 6293504 Last sector, +sectors or +size{K,M,G} (6293504-41943039, default 41943039): +5G //分区大小5g Partition 2 of type Linux and of size 5 GiB is set Command (m for help): t // 查看lvm格式 system id Partition number (1,2, default 2): 2 //对第二个分区修改 Hex code (type L to list all codes): L //查看lvm 格式为 8e 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): 8e //修改第二个分区为lvm Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p //查看分区后的结果 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 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 label type: dos Disk identifier: 0x2ae54b43 Device Boot Start End Blocks Id System /dev/sdb1 2048 6293503 3145728 8e Linux LVM /dev/sdb2 6293504 16779263 5242880 8e Linux LVM Command (m for help): w //确认完毕,保存修改 The partition table has been altered! Calling ioctl() to re-read partition table. 分区完毕,第一个分区大小3g ,第二个5g PE 创建完毕 2 PV 操作 # pv pvchange pvcreate pvresize pvscan pvck pvdisplay pvs pvremove 删除 pvmove 把本pv数据移动到别处,然后可以删除,数据不会 #pvdisplay #pvcreate /dev/sdb2 #pvcreate /dev/sdb1 #pvdisplay 3 VG操作 #vgcreate vg1 /dev/sdb1 #vgextend vg1 /dev/sdb2 #vgdisplay [root@controller /]# vgdisplay --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 7.99 GiB PE Size 4.00 MiB Total PE 2046 Alloc PE / Size 0 / 0 Free PE / Size 2046 / 7.99 GiB //8G 就是我们创建的VG大小 VG UUID 3ft5nj-LKN9-B37x-X4qx-gvxG-1HZR-nDUVqV 4 LV操作 [root@controller /]# lvcreate -L 2G vg1 -n lv1 //-L 指定分区大小,-n指定lv名字 Logical volume "lv1" created. [root@controller /]# lvdisplay --- Logical volume --- LV Path /dev/vg1/lv1 LV Name lv1 VG Name vg1 LV UUID OiNZAt-HpCa-4trs-FFNR-jTCe-9S08-ssSIID LV Write Access read/write LV Creation host, time controller, 2020-07-13 12:28:07 -0400 LV Status available # open 0 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 5 格式化: # mkfs.xfs /dev/vg1/lv1 //格式化为xfs格式 meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=524288, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 6 挂载 #mkdir /nnt/lvtest # vim /etc/fstab 添加: /dev/vg1/lv1 /mnt/lvtest xfs defaults 0 0 #mount -a # touch /mnt/lvtest/test # ls -a /mnt/lvtest/ . .. test 7 删除: //卸载挂载点 # umount /mnt/lvtest/ # lvremove /dev/vg1/lv1 Do you really want to remove active logical volume vg1/lv1? [y/n]: y Logical volume "lv1" successfully removed # vgremove vgnew # pvremove /dev/sdb1 # pvremove /dev/sdb2 其他查看命令: # lsblk -f NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 xfs d8aa1e02-362b-4081-aad0-9482f01a17d9 /boot └─sda2 LVM2_member seku5v-BetE-uTdn-tVdA-UEaw-O8lF-YDbU6r ├─centos-root xfs be281769-4262-4d0c-aaa1-9c16d6dd5de1 / └─centos-swap swap 5c90888a-8331-4fdb-86f3-8b3d5f0f4a04 [SWAP] sdb ├─sdb1 LVM2_member BM8QfF-eiV3-XW5n-3Mm8-0ujt-Oga5-1vt99K │ └─vg1-lv1 xfs be7d4e6d-5379-41c2-a7f8-c4b06cd41781 /mnt/lvtest └─sdb2 LVM2_member KK0OzZ-A79N-e4Ti-dRs9-lOs9-SuZv-lX2s3h # df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 899M 0 899M 0% /dev tmpfs tmpfs 910M 0 910M 0% /dev/shm tmpfs tmpfs 910M 9.5M 901M 2% /run tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 47G 2.0G 45G 5% / /dev/sda1 xfs 1014M 189M 826M 19% /boot tmpfs tmpfs 182M 0 182M 0% /run/user/0 /dev/mapper/vg1-lv1 xfs 2.0G 33M 2.0G 2% /mnt/lvtest //新添加的