Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Creation and use of LVM logical Volume in Linux disk Management

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Linux disk management in the creation and use of LVM logical volumes, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

The basic concept of LVM logical volume in Linux disk management and the working principle of LVM are explained in detail. The basic concept of Linux dynamic disk management LVM logical volume and the working principle of LVM are explained in detail, including the four most important basic points in LVM (PE, PV, VG and LV).

First, create LVM logical volume

Let's take a look at how to create our LVM in a pictorial way. In the previous essay, we were already familiar with how LVM works, first by formatting our physical hard drive into PV, then adding multiple PV to the created VG, and finally creating our LV through VG. So our first step is to format our physical hard disk into PV (physical volume).

① formats a physical hard disk into a PV (physical volume) using the pvcreate command

Here I have virtualized 3 fast physical hard drives in advance, each of which is 8G in size, which can be viewed through the fdisk-l command.

复制代码

[root@xiaoluo] # fdisk-lDisk / dev/sda: 21.5GB, 21474836480 bytes255 heads, 63 sectors/track 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00093d90 Device Boot Start End Blocks Id System/dev/sda1 1523 4194304 82 Linux swap / SolarisPartition 1 does not end on cylinder boundary./dev/sda2 * 523 2611 16776192 83 LinuxDisk / dev/sdb: 8589 MB, 8589934592 bytes255 heads, 63 sectors/track 1044 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk / dev/sdc: 8589 MB, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersUnits = cylinders of 16065 * 512 = 8225 280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk / dev/sdd: 8589 MB, 8589934592 bytes255 heads, 63 sectors/track 1044 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

Here, according to the figure above, we first format / dev/sdb and / dev/sdc hard drives into PV.

[root@xiaoluo ~] # pvcreate / dev/sdb / dev/sdc Physical volume "/ dev/sdb" > after creating the PV, we can use the pvdisplay (display details) and pvs commands to view the current pv information [root@xiaoluo ~] # pvdisplay "/ dev/sdb" > through these two commands we can see the information of the PV we have created. Both PV are 8G and are not yet in use. PFree is 8G. create volume group (VG) And add PV to the volume group through the vgcreate command, after creating the PV, we need to create a VG, then add our PV to the volume group, and give the volume group a name [root@xiaoluo ~] # vgcreate xiaoluo / dev/sdb / dev/sdc Volume group "xiaoluo" > similarly, after the VG is created. We can also use vgdisplay or vgs life to view VG information [root@xiaoluo ~] # vgdisplay-Volume group-VG Name xiaoluo System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 / / there are currently two PV here Our / dev/sdb and / dev/sdc Act PV 2 VG Size 15.99GiB / / the current VG size PE Size 4.00MiB / / through this we can also see that the default PE size of our LVM is 4m Total PE 4094 / / because what is stored in VG is the PE in each PV. So the number of PE is the VG size divided by the default PE size Alloc PE / Size 0 / 0 Free PE / Size 4094 / 15.99 GiB VG UUID B8eavI-21kD-Phnm-F1t1-eo4K-wgvg-T5qUbt [root@xiaoluo ~] # vgs VG # PV # LV # SN Attr VSize VFree xiaoluo 200 wz--n- 15.99g 15.99g ③ create logic based on volume group (VG) LV through the lvcreate command because the created PV, VG are all things at the bottom. We use logical volumes in the upper layer, so we need to create our logical volumes based on VG [root@xiaoluo] # lvcreate-n mylv-L 2G xiaoluo Logical volume "mylv" created create our logical volumes based on VG through the lvcreate command, named mylv, size 2G Similarly, we can use the lvdisplay or lvs command to view the information of the created logical volume [root@xiaoluo ~] # lvdisplay-Logical volume-LV Path / dev/xiaoluo/mylv / / path of the logical volume LV Name mylv / / name of the logical volume VG Name xiaoluo/ / the name of the volume group to which the logical volume belongs LV UUID PYuiYy-WpI6-XZB8-IhnQ-ANjM-lcz0-dlk4LR LV Write Access read/write LV Creation host Time xiaoluo 2013-05-23 23:45:08 + 0800 LV Status available # open 0 LV Size 2.00 GiB / / size of logical volumes Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto-currently set to 253 Block device 253 lvs LV VG 0 [root@xiaoluo ~] # lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mylv xiaoluo-wi-a---- 2.00g so our logical volume has already been created. At this time, we use vgs and pvs command to check our PV and VG information [root@xiaoluo mnt] # vgs VG # PV # LV # SN Attr VSize VFree xiaoluo 210 wz--n- 15.99g 13.99g / / We see that the number of LV becomes 1 at this time, because we have just created a LV LVFree also has 14G [root@xiaoluo mnt] # pvs PV VG Fmt Attr PSize PFree / dev/sdb xiaoluo lvm2 a muri-8.00g 6.00g / / the newly created LV uses the / dev/sdb hard drive, so the PFree of this hard disk leaves 6G / dev/sdc xiaoluo lvm2 a muri-8.00g 8.00g. We found that every time we create a LV, the information of VG and PV changes from time to time. And the size of the LV we create is based on the size of the current VG and cannot exceed the remaining size of the current VG! As we mentioned in the previous essay, every time a logical volume is created, a folder named after the volume group appears in the / dev directory, and all logical volumes created based on this volume group are stored in this folder. We can take a look at [root@xiaoluo ~] # ls / dev/xiaoluo/mylv / dev/xiaoluo/mylv. Every time we create a new logical volume, there will be such a device in the VG directory. Format and use our logical volumes We have created our PV, VG, and LV. If we want to use logical volumes, we must format them into the file system we need and mount them. Then you can use logical volumes like partitions [root@xiaoluo ~] # mkfs.ext4 / dev/xiaoluo/mylv mke2fs 1.41.12 (17-May-2010) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks131072 inodes, 524288 blocks26214 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=53687091216 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768,98304,163840,229376 294912Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 31 mounts or180 days, whichever comes first. Use tune2fs-c or-i to override. After formatting our logical volume, we can mount it using the mount command We mount it to the / mnt directory [root@xiaoluo ~] # mount/dev/ xiaoluo/mylv / mnt [root@xiaoluo ~] # mount/dev/sda2 on / type ext4 (rw) proc on / proc type proc (rw) sysfs on / sys type sysfs (rw) devpts on / dev/pts type devpts (rw,gid=5,mode=620) tmpfs on / dev/shm type tmpfs (rw Rootcontext= "system_u:object_r:tmpfs_t:s0") none on / proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on / var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) / dev/mapper/xiaoluo-mylv on / mnt type ext4 (rw) [root@xiaoluo ~] # cd / mnt/ [root@xiaoluo mnt] # lslost+found [root@xiaoluo mnt] # touch xiaoluo.txt [root@xiaoluo mnt] # lslost+found xiaoluo.txt Our volume group has been mounted and can be manipulated as if it were a partition. Delete logical Volume after we have created the logical volume, we can use it by creating a file system and mounting the logical volume. If we don't want to use it, we can delete it. [note:] We have a strict order for creating physical volumes, creating volume groups, and creating logical volumes, again For deleting logical volumes, Deleting volume groups and deleting physical volumes is also a strict order requirement. ① first unmounts the logical volumes in use through the umount command ②, deletes the logical volumes first through the lvremove command ③ delete volume groups, and then deletes our physical volumes through the vgremove command ④. Through the pvremove command [root@xiaoluo /] # mount / dev/xiaoluo/mylv / mnt/ [root@xiaoluo /] # umount / mnt/ [root @ xiaoluo/] # lvremove / dev/xiaoluo/mylv Do you really want to remove active logical volume mylv? [yplan]: y Logical volume "mylv" > at this point our newly created logical volume mylv, volume group xiaoluo, and physical volume / dev/sdb have been deleted from our current operating system. You can check that the [root@xiaoluo /] # lvs No volume groups found / / logical volume is gone through lvs, vgs and pvs commands. [root@xiaoluo /] # vgs No volume groups found / / volume group is also missing [root@xiaoluo /] # pvs PV VG Fmt Attr PSize PFree / dev/sdc lvm2 aMi-8.00g 8.00g / / sdb physical volume is gone. Only sdc physics volumes are left. This essay explains in detail the creation, use, and deletion of LVM logical volumes. In the next essay, we will continue to explain the knowledge of LVM logical volumes, including how to dynamically stretch logical volumes and compress them! Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report