In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people don't know what to do about how to create logical volume management LVM in Linux. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
LVM explanation:
Image outline:
1) what is LVM and its function:
LVM is called logical volume management, and its purpose is to improve the flexibility of disk partition management and use.
Through logical volume LVM, disk space can be effectively managed and allocated, and scattered small partitions can be combined into a large volume group, and the required space can be separated from the volume group to make logical volumes, which makes disk expansion and reduction easy to use. There is also a backup function, which refers to lvm snapshots.
2) create an instance:
Disk-"partition -" ID modification 8e-"save.
I use a disk to do it through partitions. Each disk can also be divided into a zone to do.
Device Boot Start End Blocks Id System
/ dev/sdb1 1 1306 10490413 + 8e Linux LVM
/ dev/sdb2 1307 2612 10490445 8e Linux LVM
/ dev/sdb3 2613 3918 10490445 8e Linux LVM
3) create a physical volume: through the pvcreate command.
Pvcreate / dev/sdb1
Pvcreate / dev/sdb2
Pvcreate / dev/sdb3
[root@station106 ~] # pvs (view the physical volume created).
PV VG Fmt Attr PSize PFree
/ dev/sda2 vg0 lvm2 a muri-59.99g 7.99g
/ dev/sdb1 lvm2 a muri-10.00g 10.00g
/ dev/sdb2 lvm2 a muri-10.00g 10.00g
/ dev/sdb3 lvm2 a muri-10.00g 10.00g
Pvdisplay to see more details.
[root@station106 ~] # pvdisplay
-Physical volume
PV Name / dev/sdb1
VG Name myvg
PV Size 10.00 GiB / not usable 4.54 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID XP8QfA-WQDd-1v9p-QKxk-AztZ-Nr9e-QbN6Gu
-Physical volume
PV Name / dev/sdb2
VG Name myvg
PV Size 10.00 GiB / not usable 4.58 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID f8Dtdd-fV9e-1yB7-1B8P-21mU-CU2f-fQDAxe
-Physical volume
PV Name / dev/sdb3
VG Name myvg
PV Size 10.00 GiB / not usable 4.58 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID rKNL0x-WXq2-gHYD-T27r-Gf05-a4y3-f4zqzt
4) create a logical volume: through vgcreate.
[root@station106 ~] # vgcreate myvg / dev/sdb {1pm 2pm 3}
Volume group "myvg" successfully created
[root@station106 ~] # vgs
VG # PV # LV # SN Attr VSize VFree
Myvg 30 0 wz--n- 30.00g 30.00g
5) create a logical volume, lvcreate.
[root@station106] # lvcreate-L 10G-n test myvg
Logical volume "test" created
-L: space size.
-n: logical volume name.
[root@station106 ~] # lvdisplay / dev/myvg/test
-Logical volume
LV Path / dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 + 0800
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
-currently set to 256
Block device 253:4
6) Mount the created logical volume.
Mke2fs-t ext4 / dev/myvg/test format.
Mount / dev/myvg/test / mnt/ is used for mounting.
7) if one day the logical volume is not enough. How do you extend from a volume group? The analysis is as follows.
Rough steps for logical volume expansion:
1, first determine the size of the extension and make sure that the volume group to which you belong has enough remaining space.
I'm going to expand 5G now, which is the size of 10G itself. The command is as follows:
[root@station106] # lvextend-L + 5G / dev/myvg/test
Extending logical volume test to 15.00 GiB
Logical volume test successfully resized
2. Extend the physical boundary. The physical boundary refers to the physical edge size of itself.
[root@station106 ~] # lvdisplay / dev/myvg/test
-Logical volume
LV Path / dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 + 0800
LV Status available
# open 1
LV Size 15.00 GiB
Current LE 3840
Segments 2
Allocation inherit
Read ahead sectors auto
-currently set to 256
Block device 253:4
When you have extended the physical boundaries, you will find that the logical volume in the mount is still its own size.
[root@station106 ~] # df-hT
Filesystem Type Size Used Avail Use% Mounted on
/ dev/mapper/vg0-root
Ext4 20G 387m 19G 3% /
Tmpfs tmpfs 242m 0 242m 0% / dev/shm
/ dev/sda1 ext4 194M 29M 156M 16% / boot
/ dev/mapper/vg0-usr
Ext4 9.9G 1.9G 7.6G 20% / usr
/ dev/mapper/vg0-var
Ext4 20G 288m 19G 2% / var
/ dev/mapper/myvg-test
Ext4 9.9G 151m 9.2G 2% / mnt
Extend the logical boundary, which means that after mounting, the logical volume in use is also directly identified.
[root@station106 ~] # resize2fs / dev/myvg/test
Resize2fs 1.41.12 (17-May-2010)
Filesystem at / dev/myvg/test is mounted on / mnt; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of / dev/myvg/test to 3932160 (4k) blocks.
The filesystem on / dev/myvg/test is now 3932160 blocks long.
[root@station106 ~] # df-hT
Filesystem Type Size Used Avail Use% Mounted on
/ dev/mapper/vg0-root
Ext4 20G 387m 19G 3% /
Tmpfs tmpfs 242m 0 242m 0% / dev/shm
/ dev/sda1 ext4 194M 29M 156M 16% / boot
/ dev/mapper/vg0-usr
Ext4 9.9G 1.9G 7.6G 20% / usr
/ dev/mapper/vg0-var
Ext4 20G 288m 19G 2% / var
/ dev/mapper/myvg-test
Ext4 15G 153M 14G 2% / mnt
This is the part of the extended logical volume.
Example demonstration: shrink the logical volume. First of all, in order to test that I went to the previously mounted record to create some files, test whether it will cause the files to disappear after zooming out.
The steps to shrink the logical volume are as follows:
1) uninstall the previous mount first, and perform a forced test.
[root@station106 ~] # umount / mnt/
[root@station106] # e2fsck-f / dev/myvg/test
E2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/ dev/myvg/test: 13ram 983040 files (0.0% non-contiguous), 100864amp 3932160 blocks
2) reduce the logical boundary.
[root@station106 ~] # resize2fs / dev/myvg/test 10G
Resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on / dev/myvg/test to 2621440 (4k) blocks.
The filesystem on / dev/myvg/test is now 2621440 blocks long.
3) reduce the physical boundary.
[root@station106] # lvreduce-L 10G / dev/myvg/test
WARNING: Reducing active logical volume to 10.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce test? [y/n]: y
Reducing logical volume test to 10.00 GiB
Logical volume test successfully resized
View after downsizing:
[root@station106 ~] # lvdisplay / dev/myvg/test
-Logical volume
LV Path / dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 + 0800
LV Status available
# open 0
LV Size 10.00 GiB- "here becomes 10G again.
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
-currently set to 256
Block device 253:4
Mount to continue to use and see if the file exists.
[root@station106 ~] # mount / dev/myvg/test / mnt/
[root@station106 ~] # cd / mnt/
[root@station106 mnt] # ls
The accp benet lost+found-- view still exists. Not lost.
[root@station106 mnt] # df-hT
Filesystem Type Size Used Avail Use% Mounted on
/ dev/mapper/vg0-root
Ext4 20G 387m 19G 3% /
Tmpfs tmpfs 242m 0 242m 0% / dev/shm
/ dev/sda1 ext4 194M 29M 156M 16% / boot
/ dev/mapper/vg0-usr
Ext4 9.9G 1.9G 7.6G 20% / usr
/ dev/mapper/vg0-var
Ext4 20G 288m 19G 2% / var
/ dev/mapper/myvg-test
Ext4 9.9G 151m 9.2G 2% / mnt
Suppose that one day, the VG volume group is used up by logical volumes, how to continue to expand the volume group?
1) create a physical volume.
[root@station106 mnt] # pvcreate / dev/sdb5
Physical volume "/ dev/sdb5" successfully created
2) add the new physical machine to the volume group.
[root@station106 mnt] # vgextend myvg / dev/sdb5
Volume group "myvg" successfully extended
View the added volume groups.
[root@station106 mnt] # vgextend myvg / dev/sdb5
Volume group "myvg" successfully extended
[root@station106 mnt] # vgdisplay myvg
-Volume group
VG Name myvg
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size 40.00 GiB-- "from 30g to 40g."
PE Size 4.00 MiB
Total PE 10240
Alloc PE / Size 2560 / 10.00 GiB
Free PE / Size 7680 / 30.00 GiB
VG UUID KyFWJg-BU15-KrOA-uef4-Cckf-eoTz-oM38nu
If there is an extended volume group, there must be a reduction. The reduction process is as follows.
[root@station106 mnt] # vgreduce myvg / dev/sdb5
Removed "/ dev/sdb5" from volume group "myvg"
[root@station106 mnt] # vgdisplay myvg
-Volume group
VG Name myvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 30.00 GiB
PE Size 4.00 MiB
Total PE 7680
Alloc PE / Size 2560 / 10.00 GiB
Free PE / Size 5120 / 20.00 GiB
VG UUID KyFWJg-BU15-KrOA-uef4
-Cckf-eoTz-oM38nu
LVM takes a snapshot.
A snapshot is a logical volume, usually read-only. Popular saying: "Snapshot size depends on backup size."
Function, can maintain the operation before the snapshot, if the subsequent operation has an impact, you can restore some of the previous operations, which is equivalent to making a backup before the snapshot, after the creation of the snapshot, there is no impact before the subsequent operation team snapshot.
[root@station106 mnt] # lvcreate-s-L 50m-n snap-p r / dev/myvg/test
Rounding up size to full physical extent 52.00 Mi
The name of the snapshot created is snap.
-L sets the size.
-p:permission, which sets the read and write permissions for generating snapshots. By default, RW;r is read-only.
-s: specifies that lvcreate generates a snapshot.
-n: specify the snapshot name
Mount the snapshot: here are the contents of the backup.
Mount / dev/myvg/snap / me
[root@station106 me] # ls
Accp benet lost+found
Then the files in the snapshot can be backed up, and the snapshot can be deleted in time after the backup.
[root@station106 ~] # lvremove / dev/myvg/snap
Do you really want to remove active logical volume snap? [y/n]: y
Logical volume "snap" successfully removed
After reading the above, have you mastered how to create a logical volume management LVM in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.