In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use LVM in RHEL6.5, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
One of the common problems that Linux users encounter when installing an operating system is how to correctly evaluate the size of each partition in order to allocate the appropriate hard disk space. The ordinary disk partition management method cannot change the size of each partition after it has been partitioned, and when a logical partition cannot hold a file, the file cannot be stored across multiple partitions because of the limitations of the upper file system. So it can't be put on another disk at the same time. Or when a partition is running out of space, the solution is usually to use symbolic links, or to create a new directory plug-in partition and use a tool to resize the partition, but this is only a temporary solution, not a fundamental solution to the problem. In fact, under Linux, using LVM, these problems can be easily solved, and users can easily adjust the size of each partition without downtime.
1. Brief introduction of LVM command
LVM (Logical Volume Manager) is a logical volume manager applied to the kernel of Linux and a mechanism for disk partition management in Linux environment.
Nouns you need to know in LVM:
1. PV (physical volume) can be a disk and a partition. Composed of PE (physical extent), multiple PV can form a VG (volume group).
2. VG (volume group) is a group composed of multiple physical volumes, but the volume group cannot be used directly. You need to create a LV (logical volume) on it before you can use it. Multiple LV can be created on VG.
3. PE (physical extent) is like the block block of the disk we learned earlier, and the default is 4MB.
4. LV (logical volume) is an available space built on top of a volume group. There are two kinds of boundaries: physical boundary and logical boundary.
2. Introduction of related commands
1. Physical volume PV
Pvcreate creates pv example: pvcreate / dev/sda1
Pvs to view pv information example: enter pvs directly on the command line
Pvdisplay View pv details example: pvcreate / dev/sda1
Pvmove moves pv data to another pv example: pvmove / dev/sda1 / dev/sda4
Pvremove deletes pv example: pvremove / dev/sda1
2. Volume group VG
How to create, view, and delete vg
Vgcreate creates vg as an example: vgcreate myvg / dev/sda {mrecom n}
Vgs to view vg information example: enter vgs directly on the command line
Vgdisplay View vg details example: vgdisplay myvg
Vgremove deletes vg example: vgremove myvg
How to extend vg
First of all, prepare a PV.
Then use the vgextend command to complete the extension
Format: vgextend VG_NAME / PATH/TO/PV
Vgextend testvg / dev/sdb2 extends the myvg volume group, adding / dev/sda2
How to reduce vg
1) determine the PV to be removed
2) transfer the data on this PV to another PV
Pvmove / path/ to / pv
3) remove this PV from the volume group
Format: vgreduce VG_NAME / PATH/TO/PV
Vgreduce testvg / dev/sdb2 reduce the myvg volume group and remove / dev/sda2
3. Logical volume LV
How to create, view, and delete lv
Lvcreate creates lv example: lvcreate lv1 / dev/myvg
Lvs to view lv information example: enter lvs directly on the command line
Lvdisplay View lv details example: vgdisplay lv1
Lvremove removes lv example: lvremove / dev/myvg/lv1
How to extend lv
Determine how much space needs to be expanded
Determine whether the volume group in which the current logical volume belongs has enough free space
An example of expansion:
1. Physical boundary
Lvextend-L [+] SIZE / path/to/lv
2. Logical boundary
Resize2fs / path/to/device
How to reduce lv
Determine the size of the reduction, but only if it can accommodate at least all the original data.
Shrink:
1) unmount and forcibly detect the file system
Umount / path
E2fsck-f
2) logical boundary
Resize2fs / path/to/device SIZE
3) physical boundary
Lvreduce-L [-] SIZE / path/to/lv
4. Snapshot Volume
1) the lifecycle is the entire data duration, during which the growth of data cannot exceed the snapshot volume size.
2) the snapshot volume should be read-only
3) in the same volume group as the original volume
Lvcreate
-L specifies the size of the snapshot volume
-s create snapshot volum
The snapshot volume created by-p r is read-only
Format:
Lvcreate-L SIZE-s-pr-n LV_NAME / path/to/lv
III. An example of lv
1. Create a partition
[root@test11 ~] # fdisk-l / / View the partition
[root@test11 ~] # fdisk / dev/sda / / to partition
Command (m for help): n / / n to add a partition, p view partition
First cylinder (2898-10443, default 2898): / / Press the [Enter] key to decide
Using default value 2898 / / start cylinder Select default
Last cylinder or + size or + sizeM or + sizeK (289810443, default 10443): + 2G / / give the size of 2G
Command (m for help): t / / change partition type
Partition number (1-5): 5 / / selected partition
Hex code (type L to list codes): l / / list of partition types
Hex code (type L to list codes): 8e / / Mark the newly added partition as lvm
Command (m for help): P / / View partition table
/ dev/sda5 2756 2999 1959898 + 8e Linux LVM
Command (m for help): W / / Save
[root@test11 ~] # partprobe / dev/sda / / is the system identification partition (instead of reboot)
[root@test11 ~] # mkfs.ext4 / dev/sda5 / / format the newly added partition
2. The creation of PV
[root@test11 ~] # pvcreate / dev/sda5 / / create pv
Writing physical volume data to disk "/ dev/sda5"
Physical volume "/ dev/sda5" successfully created
[root@test11 ~] # pvs / / View the current pv information
PV VG Fmt Attr PSize PFree
/ dev/sda5 lvm2 Amuri-1.87G 1.87G
3. The creation of VG
[root@test11 ~] # vgcreate vg0 / dev/sda5 / / vg0 is the name of the current vg
Volume group "vg0" successfully created
[root@test11 ~] # vgs / / View the information of vg
VG # PV # LV # SN Attr VSize VFree
Vg0 1 0 0 wz--n- 1.87G 1.87G
4. The creation of lv
[root@test11] # lvcreate-L 500m-n lv01 vg0
Logical volume "lv01" created
[root@test11 ~] # lvs / / View the information of lv
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
Lv01 vg0-wi-a- 500.00m
[root@test11 ~] # mkfs.ext4 / dev/vg0/lv01 / / format
5. The increase of lv
[root@test11 ~] # lvextend-L + 300m / dev/vg0/lv01 / / (original lv size 500m, stretch partition to 800m) Extending logical volume lv01 to 800.00 MB
Logical volume lv01 successfully resized
[root@test11 ~] # resize2fs / dev/vg0/lv01 / / stretch the file system
[root@test11 ~] # lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
Lv01 vg0-wi-ao 800.00m / / size becomes 800m
6. Reduction of lv
# umount / dev/vg0/lv01 / / unmount logical volumes / dev/vg0/lv01
# df-h / / View
# e2fsck-f / dev/vg0/lv01 / / disk check
# resize2fs / dev/vg0/lv01 500m / / retract the file system to 500m
# lvreduce-L 500m / dev/vg0/lv01 / / retract partition to 500m
WARNING: Reducing active logical volume to 500.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv01? [y/n]: y
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
Lv01 vg0-wi-a- 500.00m / / now 500m size
# mount / dev/vg0/lv01 / mnt/lv01 / / remount the partition
# df-h / / View
# ls / mnt/lv01 / / View files
IV. Shutdown of lvm
[root@test11 ~] # umount / mnt/lv01
[root@test11 ~] # lvremove / dev/vg0/lv01 / / Delete lv
Do you really want to remove active logical volume lv01? [y/n]: y
Logical volume "lv01" successfully removed
[root@test11 ~] # vgchange-an vg0 / / makes vg0 without the active flag
0 logical volume (s) in volume group "vg0" now active
[root@test11 ~] # vgremove vg0 / / Delete vg
Volume group "vg0" successfully removed
[root@test11 ~] # pvremove / dev/sda5 / / Delete pv
Labels on physical volume "/ dev/sda5" successfully wiped
Expand the root partition and SWAP
[root@zkdb1 ~] # pvs
PV VG Fmt Attr PSize PFree
/ dev/sda3 vg_zkdb1 lvm2 a muri-557.46g 521.46g
[root@zkdb1 ~] # lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
Root vg_zkdb1-wi-ao---- 20.00g
Swap vg_zkdb1-wi-ao---- 16.00g
[root@zkdb1] # lvcreate-L 30720m vg_zkdb1
Logical volume "lvol0" created
[root@zkdb1 ~] # lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
Lvol0 vg_zkdb1-wi-a- 30.00g
Root vg_zkdb1-wi-ao---- 20.00g
Swap vg_zkdb1-wi-ao---- 16.00g
[root@zkdb1] # lvextend-L + 30g / dev/mapper/vg_zkdb1-root
Extending logical volume root to 50.00 GiB
Logical volume root successfully resized
[root@zkdb1] # e2fsck-f / dev/mapper/vg_zkdb1-root
E2fsck 1.41.12 (17-May-2010)
/ dev/mapper/vg_zkdb1-root is mounted.
E2fsck: Cannot continue, aborting.
[root@zkdb1 ~] # lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
Lvol0 vg_zkdb1-wi-a- 30.00g
Root vg_zkdb1-wi-ao---- 50.00g
Swap vg_zkdb1-wi-ao---- 16.00g
[root@zkdb1 ~] # resize2fs / dev/mapper/vg_zkdb1-root
Resize2fs 1.41.12 (17-May-2010)
Filesystem at / dev/mapper/vg_zkdb1-root is mounted on /; on-line resizing required
Old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of / dev/mapper/vg_zkdb1-root to 13107200 (4k) blocks.
The filesystem on / dev/mapper/vg_zkdb1-root is now 13107200 blocks long.
Extended SWAP
[root@zkdb1 ~] # lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
Lvol0 vg_zkdb1-wi-a- 30.00g
Root vg_zkdb1-wi-ao---- 50.00g
Swap vg_zkdb1-wi-ao---- 16.00g
[root@zkdb1] # lvextend-L + 16G / dev/mapper/vg_zkdb1-swap
Extending logical volume swap to 32.00 GiB
Logical volume swap successfully resized
[root@zkdb1] # e2fsck-f / dev/mapper/vg_zkdb1-swap
E2fsck 1.41.12 (17-May-2010)
/ dev/mapper/vg_zkdb1-swap is mounted.
E2fsck: Cannot continue, aborting.
[root@zkdb1 ~] # resize2fs / dev/mapper/vg_zkdb1-swap
Resize2fs 1.41.12 (17-May-2010)
Resize2fs: Bad magic number in super-block while trying to open / dev/mapper/vg_zkdb1-swap
Couldn't find valid filesystem superblock.
[root@zkdb1 ~] # lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
Lvol0 vg_zkdb1-wi-a- 30.00g
Root vg_zkdb1-wi-ao---- 50.00g
Swap vg_zkdb1-wi-ao---- 32.00g
Attached: the solution of changing root partition to read-only
1 single user mode
Enter the command to repair the file system: fsck-C-y
Enter the command to restart after the repair is complete: reboot
2 remount
Mount-o remount,rw partition name can be read and written
Mount-o remount,rw /
If prompted for file system type
Mount-t ext3-o remount,rw /
The above is all the contents of the article "how to use LVM in RHEL6.5". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.