如何设置LVM
时间:2020-02-23 14:44:46 来源:igfitidea点击:
介绍
存储是我们服务器无法做的那些基本组件之一,无论如何都需要解决。
设置LVM存储
逻辑卷管理(LVM)技术简化了存储管理的完成方式。
与旧的分区范例相比,LVM虚拟化存储和专业系统管理员,以更灵活的方式管理磁盘存储。
逻辑卷管理通过将物理卷(PVS)划分为物理范围(PES),该物理范围(PE)映射到逻辑范围内(LES)。
此后将逻辑范围分组成体积组(VGS)。
如我们所猜,这些生成的卷组将组合成逻辑卷(LV),该卷充当上述虚拟磁盘分区。
LVM使得在需要时调整大小和移动存储卷真的很简单。
第一步
使用fdisk列出可用的设备和分区。
我们可以从输出中看到,有一个标记为/dev/sdb的物理设备
➤ sudo fdisk -l Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 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 Disklabel type: dos Disk identifier: 0xa3bc85b8 Device Boot Start End Sectors Size Id Type /dev/sda1 62517248 250067789 187550542 89.4G 83 Linux /dev/sda2 2048 62517247 62515200 29.8G 83 Linux Partition table entries are not in disk order. Disk /dev/sdb: 14.9 GiB, 15938355200 bytes, 31129600 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 Disklabel type: dos Disk identifier: 0x2a4e70c2 Device Boot Start End Sectors Size Id Type /dev/sdb1 8192 31129599 31121408 14.9G c W95 FAT32 (LBA)
第二步
通过格式化它来准备物理设备 fdisk
那 parted
或者 gdisk
。
我们将使用 fdisk
。
首先,我们将删除现有分区并创建新分区。
➤ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): 3 No free sectors available. #deleting the exiting partitions Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 has been deleted. Command (m for help): d Selected partition 1 Partition 1 has been deleted. #creating new partitions Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-31129599, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-31129599, default 31129599): +7G Created a new partition 1 of type 'Linux' and of size 7 GiB. 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 (container for logical partitions) Select (default p): p Partition number (2-4, default 2): First sector (14682112-31129599, default 14682112): Last sector, +sectors or +size{K,M,G,T,P} (14682112-31129599, default 31129599): Created a new partition 2 of type 'Linux' and of size 7.9 GiB. 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): w The partition table has been altered. Failed to remove partition 1 from system: Device or resource busy Failed to add partition 1 to system: Device or resource busy Failed to add partition 2 to system: Device or resource busy The kernel still uses the old partitions. The new table will be used at the next reboot. Syncing disks.
通过执行确认LVM分区 fdisk -l
如下:
➤ sudo fdisk -l [sudo] password for penchant: Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 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 Disklabel type: dos Disk identifier: 0xa3bc85b8 Device Boot Start End Sectors Size Id Type /dev/sda1 62517248 250067789 187550542 89.4G 83 Linux /dev/sda2 2048 62517247 62515200 29.8G 83 Linux Partition table entries are not in disk order. Disk /dev/sdb: 14.9 GiB, 15938355200 bytes, 31129600 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 Disklabel type: dos Disk identifier: 0x2a4e70c2 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 14682111 14680064 7G 8e Linux LVM /dev/sdb2 14682112 31129599 16447488 7.9G 8e Linux LVM Partition table entries are not in disk order.
第三步
使用创建物理量 pvcreate
➤ sudo pvcreate /dev/sdb1 /dev/sdb2 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdb2" successfully created.
使用 pvdisplay
命令
➤ sudo pvdisplay --- Physical volume -- PV Name /dev/sdb1 VG Name tech PV Size 7.00 GiB/not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 1791 Free PE 214 Allocated PE 1577 PV UUID cGnGfI-oVG7-9CcY-kdmK-aR4R-iZY9-O9gD0g --- Physical volume -- PV Name /dev/sdb2 VG Name tech PV Size 7.84 GiB/not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 2007 Free PE 0 Allocated PE 2007 PV UUID UvewNB-Z2d1-T3L1-c92C-rOLa-lcrg-19zuPk
第四步
使用卷组使用 vgcreate
有我们选择的名称。
我要使用'tech'
sudo vgcreate tech /dev/sdb1 /dev/sdb2 Volume group "tech" successfully created
第五步
使用我们选择的名称和大小创建逻辑卷 lvcreate
具有某些选项和交换机,如下所示。
选项-n用于指定逻辑卷选项-l的名称指定大小。
它可以在mib中用于兆字节或者gib用于千兆字节。
➤ sudo lvcreate -n part1 -L 14GiB tech Logical volume "part1" created.
发出上述命令后,将创建已知为/dev/tech/part1的设备。
我们可以通过调用来确认这一点 lvdisplay
命令。
但是,此设备没有文件系统。
➤ sudo lvdisplay --- Logical volume -- LV Path /dev/tech/part1 LV Name part1 VG Name tech LV UUID O1qtcJ-dDAj-gPoL-nZn0-VUMs-rVwe-f31OHq LV Write Access read/write LV Creation host, time computing-pc, 2016-10-14 00:39:25 +0300 LV Status available # open 0 LV Size 14.00 GiB Current LE 3584 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0
我们可以使用使用的卷组 vgdisplay
第六步
将我们选择的文件系统加载到创建的逻辑卷中。
让我们加载XFS文件系统。
我们可以根据需要加载Ext3,Ext4,BRTF和其他人。
➤ sudo mkfs -t xfs /dev/tech/part1 meta-data=/dev/tech/part1 isize=512 agcount=4, agsize=917504 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=0 data = bsize=4096 blocks=3670016, 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
使用此操作,我们已成功创建了具有XFS文件系统的逻辑卷/dev/tech/part1.