In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to create and configure LVM in Linux". In daily operation, I believe many people have doubts about how to create and configure LVM in Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to create and configure LVM in Linux". Next, please follow the editor to study!
Logical Volume Management (LVM) plays an important role in Linux systems, which can improve availability, disk Imando O, performance and disk management capabilities.
LVM is a widely used technology that is very flexible for disk management.
It adds an extra layer between the physical disk and the file system, allowing you to create a logical volume instead of a physical disk.
LVM allows you to easily resize, expand, and reduce the size of logical volumes when needed.
How do I create a LVM physical volume?
You can use any disk, RAID array, SAN disk, or partition as the LVM physical volume Physical Volume (PV).
Let's imagine that you have added three disks: / dev/sdb, / dev/sdc, and / dev/sdd.
Run the following command to discover the newly added LUN or disk in Linux:
# ls / sys/class/scsi_hosthost0# echo "- -" > / sys/class/scsi_host/host0/scan# fdisk-l
General syntax for creating a physical volume (pvcreate):
Pvcreate [physical volume name]
When a disk is detected in the system, initialize the LVM PV using the pvcreate command:
# pvcreate / dev/sdb / dev/sdc / dev/sddPhysical volume "/ dev/sdb" successfully createdPhysical volume "/ dev/sdc" successfully createdPhysical volume "/ dev/sdd" successfully created
Please note:
The above command deletes all data on the given disks / dev/sdb, / dev/sdc, and / dev/sdd.
Physical disks can be added directly to the LVM PV without having to be partitioned.
Use the pvdisplay and pvs commands to display the PV you created. The pvs command displays the summary output, and the pvdisplay shows the detailed output of the PV:
# pvsPV VG Fmt Attr PSize PFree/dev/sdb lvm2 Amura-15.00g 15.00g/dev/sdc lvm2 Amuri-15.00g 15.00g/dev/sdd lvm2 Amure-15.00g 15.00g# pvdisplay "/ dev/sdb" is a new physical volume of "15.00GiB"-NEW Physical volume-PV Name / dev/sdbVG NamePV Size 15.00GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID 69d9dd18-36be-4631-9ebb-78f05fe3217f "/ dev/sdc" is a new physical volume of "15.00 GiB"-NEW Physical volume-PV Name / dev/sdcVG NamePV Size 15.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID a2092b92-af29-4760-8e68-7a201922573b "/ dev/sdd" is a new physical volume of "15.00 GiB"-NEW Physical volume-PV Name / dev/sddVG NamePV Size 15.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID How d92fa769-e00f-4fd7-b6ed-ecf7224af7faS creates a volume group
The volume group Volume Group (VG) is another layer in the LVM structure. Basically, volume groups are made up of LVM physical volumes that you create, and you can add physical volumes to existing volume groups or create new volume groups for physical volumes as needed.
General syntax for creating a volume group (vgcreate):
Vgcreate [volume group name] [physical volume name]
Use the following command to add a new physical volume to the new volume group:
# vgcreate vg01 / dev/sdb / dev/sdc / dev/sddVolume group "vg01" successfully created
Please note: by default, it uses 4MB's physical range Physical Extent (PE), but you can change it according to your needs.
Use the vgs and vgdisplay commands to display information about the VG you created:
# vgs vg01VG # PV # LV # SN Attr VSize VFreevg01 300 wz--n- 44.99g 44.99g# vgdisplay vg01--- Volume group-VG Name vg01System IDFormat lvm2Metadata Areas 3Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 3Act PV 3VG Size 44.99 GiBPE Size 4.00 MiBTotal PE 11511Alloc PE / Size 0 / 0Free PE / Size 11511 / 44.99 GiBVG UUID d17e3c31-e2c9-4f11-809c-94a549bc43b7 how to extend volume groups
If there is no space for VG, use the following command to add the new physical volume to the existing volume group.
General syntax for volume group extension (vgextend):
Vgextend [existing volume group name] [physical volume name] # vgextend vg01 / dev/sde Volume group "vg01" successfully extended how to create logical volumes in units of GB?
The logical volume Logical Volume (LV) is the top level in the LVM structure. Logical volumes are block devices created by volume groups. As a virtual disk partition, it can be easily managed using the LVM command.
You can create a new logical volume using the lvcreate command.
General syntax for creating logical volumes (lvcreate):
Lvcreate-n [logical volume name]-L [logical volume size] [volume group name of the LV to be created]
Run the following command to create a logical volume lv001 of 10GB size:
# lvcreate-n lv001-L 10G vg01Logical volume "lv001" created
Use the lvs and lvdisplay commands to display information about the LV you created:
# lvs / dev/vg01/lvol01LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convertlv001 vg01 mwi-a-m-- 10.00g lv001_mlog 100.0 lvdisplay / dev/vg01/lv001--- Logical volume-LV Path / dev/vg01/lv001LV Name lv001VG Name vg01LV UUID ca307aa4-0866-49b1-8184-004025789e63LV Write Access read/writeLV Creation host, time localhost.localdomain 2020-09-10 11:43:05-0700LV Status available# open 0LV Size 10.00 GiBCurrent LE 2560Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253PE 4 how do I create logical volumes in PE size?
Alternatively, you can create logical volumes using physical range (PE) sizes.
How is the PE value calculated?
It's very simple, for example, if you have a volume group for 10GB, what is the size of PE?
By default, it uses the physical scope of 4MB, but you can check the correct PE size by running the vgdisplay command, because this can be changed as needed.
10GB = 10240MB / 4MB (PE size) = 2560 PE
The general syntax for creating logical volumes (lvcreate) with PE size:
Lvcreate-n [logical volume name]-l [physical extension (PE) size] [volume group name of the LV to be created]
To create a logical volume of 10GB using the PE size, the command is as follows:
# lvcreate-n lv001-l 2560 vg01 how to create a file system
You cannot use logical volumes until you create a valid file system.
General syntax for creating a file system:
Mkfs-t [file system type] / dev/ [volume group name where LV belongs] / [LV name]
Use the following command to format the logical volume lv001 as an ext4 file system:
# mkfs-t ext4 / dev/vg01/lv001
For xfs file systems:
# mkfs-t xfs / dev/vg01/lv001 Mount logical Volume
Finally, you need to mount the logical volume to use it. Be sure to add an entry in / etc/fstab so that the system loads automatically at startup.
Create a directory to mount the logical volume:
# mkdir / lvmtest
Mount the logical volume using the mount command:
# mount / dev/vg01/lv001 / lvmtest
Add new logical volume details to the / etc/fstab file so that the system can be mounted automatically at startup:
# vi / etc/fstab/dev/vg01/lv001 / lvmtest xfs defaults 00
Use the df command to check the newly mounted volume:
# df-h / lvmtestFilesystem Size Used Avail Use% Mounted on/dev/mapper/vg01-lv001 15360M 34M 15326M 4% / lvmtest this is the end of the study on "how to create and configure LVM in Linux". I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.