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

How to use LVM to adjust hard disk Partition in Ubuntu system

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

Share

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

This article shows you how to use LVM to adjust the hard disk partition in the Ubuntu system, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

LVM is the abbreviation of Logical Volume Manager (logical Volume Manager), which is also translated as logical Volume Manager, logical sector Manager and logical disk Manager. Is the logical volume management (Logical Volume Management) function provided by the Linux core. It creates a logic layer on top of the hard disk partition of the hard disk to facilitate the system to manage the hard disk partition system.

Advantages of LVM:

It is an abstraction layer based on physical storage devices that allows users to generate logical storage volumes, providing more flexibility than using physical storage directly for management.

LVM virtualizes storage, uses logical volumes, and users are not limited by the size of physical disks; in addition, hardware-related storage settings are hidden by the device, and users can adjust volume size or data migration without having to stop applying or unmounting file systems, thus reducing operation costs.

LVM has the following advantages over using physical storage directly:

1. Flexible capacity

When using logical volumes, the file system can be extended to multiple disks, and you can aggregate multiple disks or partition into a single logical volume.

2. Scalable storage pool

You can use simple commands to expand or reduce the size of logical volumes without reformatting or partitioning disk devices.

3. Online data redistribution

You can move data online, and data can be redistributed while the disk is online. For example, you can replace hot-swappable disks online.

4. Convenient device naming

Logical volumes can be named any way you find convenient.

5. Disk fragmentation

You can generate a logical disk whose data can be stored in blocks on 2 or more disks. This can significantly improve data throughput.

6. Mirror the volume

Logical volumes provide a convenient way to mirror your data.

7. Volume snapshot

Using logical volumes, you can get device snapshots for consistent backups or test data updates without affecting real data.

two。 Version:

LVM1's original LVM, released in 1998, is only available on version 2.4 of the Linux kernel and provides the most basic logical volume management.

A newer version of LVM2 LVM-1, which is only available in the Linux kernel 2.6, provides additional functionality in addition to the standard LVM-1 functionality.

View the version:

The code is as follows:

[root@localhost] # uname-a

Linux localhost.localdomain2.6.32-504.el6.x86_64 # 1 SMP Wed Oct 15 04:27:16 UTC 2014 x86'64 x 86'64 x86_64GNU/Linux

The code is as follows:

[root@localhost ~] # uname-r

2.6.32-504.el6.x86_64

The code is as follows:

[root@localhost ~] # rpm-qa | grep lvm

Mesa-private-llvm-3.4-3.el6.x86_64

Lvm2-libs-2.02.111-2.el6.x86_64

Lvm2-2.02.111-2.el6.x86_64

Basic terms of 3.LVM:

Physical storage media (The Physical Media):

Here, the storage devices of the system, such as / dev/hda1, / dev/sda, and so on, are the storage units at the lowest level of the storage system.

Physical volume (PV,Physical Volume):

Physical volumes refer to disks, disk partitions or devices (such as RAID) that logically have the same function as disk partitions. It is the basic storage logic block of LVM, but compared with basic physical storage media (such as partitions, disks, etc.), it contains management parameters related to LVM. The current LVM allows you to save 0 to 2 copies of the metadata of each physical volume. The default is 1, which is saved at the beginning of the device. At 2, save the second backup at the end of the device.

Volume group (VG,Volume Group):

LVM volume groups are similar to physical hard disks in non-LVM systems and are made up of physical volumes. You can create one or more LVM partitions (logical) on a volume group

Volumes), the LVM volume group consists of one or more physical volumes.

Logical volume (LV,Logical Volume):

LVM's logical volumes are similar to hard disk partitions in non-LVM systems, and file systems can be built on top of logical volumes (such as / home or / usr, etc.).

Linear logical Volume (Linear Volumes):

A linear logical volume aggregates multiple physical volumes into a single logical volume. For example, if you have two 60GB hard drives, you can generate 120GB logical volumes.

Striped logical volumes (Striped Logical Volumes)

When you write data to this logical volume, the file system can place the data on multiple physical volumes. For a large number of connection read and write operations, it can improve the efficiency of data Ihammer O.

Mirrored logical volumes (MirroredLogical Volumes)

Mirroring keeps consistent data on different devices. The data is written to both the original device and the mirror device. It provides fault tolerance between devices.

Snapshot Volume (SnapshotVolumes)

The snapshot volume provides a virtual image of the device at a specific moment, and when the snapshot starts, it copies a change to the current data area, and because it gives priority to these changes, it can reconstruct the state of the current device.

PE (physical extent)

Each physical volume is divided into basic units called PE (Physical Extents), and PE with a unique number is the smallest unit that can be addressed by LVM. The size of PE is configurable and defaults to 4MB.

LE (logical extent)

Logical volumes are also divided into basic addressable units called LE (Logical Extents). In the same volume group, the size of LE and PE are the same and correspond one to one.

Just as non-LVM systems store metadata containing partition information in the partition table at the beginning of the partition, logical volumes and volume group related metadata are stored in the VGDA (volume group descriptor area) at the beginning of the physical volume. VGDA includes the following: PV descriptors, VG descriptors, LV descriptors, and some PE descriptors. When the system starts LVM, activate VG and load the VGDA into memory to identify the actual physical storage location of the LV. When the system performs an iCandle O operation, it accesses the actual physical location according to the mapping mechanism established by VGDA.

4.LVM module:

Physicalvolume (PV), Volume group (VG), Logicalvolume (LV), Physical extent (PE), let's use a simple

To illustrate the relationship between physical volumes, volume groups, and logical volumes

The creation of logical volumes is to create physical volumes from multiple hard disks, and assemble these physical volumes into a container in logical form, and then create partition files of different sizes from this container, and this container is called volume group (VG), and create partition files of different sizes from this container, this partition file is called logical volume.

Implementation of logical Volume Mirror with LVM

LVM's mirroring function is a bit similar to Raid1, where multiple disks are synchronized with each other to ensure that data is not lost.

1. Add 4 physical hard drives here, each with 2G space

2. Create physical volumes with sdb, sdc, sdd and sde, and add volume groups of sdb, sdc and sdd to vmTest

The code is as follows:

[root@node4 ~] # pvcreate / dev/sdb

Physical volume "/ dev/sdb" successfully created

The code is as follows:

[root@node4 ~] # pvcreate / dev/sdc

Physical volume "/ dev/sdc" successfully created

The code is as follows:

[root@node4 ~] # pvcreate / dev/sdd

Physical volume "/ dev/sdd" successfully created

The code is as follows:

[root@node4 ~] # pvcreate / dev/sde

Physical volume "/ dev/sde" successfully created

The code is as follows:

[root@node4 ~] # vgcreate vgTest / dev/sdb / dev/sdc / dev/sdd

Volume group "vgTest" successfully created

The code is as follows:

[root@node4 ~] #

3. Create a logical volume

The code is as follows:

[root@node4] # lvcreate-L 1G-M1-n lvTest vgTest / dev/sdb / dev/sdc / dev/sdd

Logical volume "lvTest" created

View lvs information

The code is as follows:

[root@node4] # lvs-a-o + devices

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert Devices

Lv_root VolGroup-wi-ao---- 8.54g / dev/sda2 (0)

Lv_swap VolGroup-wi-ao---- 992.00m / dev/sda2 (2186)

LvTest vgTest mwi-a-m--- 1.00g lvTest_mlog 100.00 lvTest_mimage_0 (0), lvTest_mimage_1 (0)

[lvTest_mimage_0] vgTest iwi-aom--- 1.00g / dev/sdb (0)

[lvTest_mimage_1] vgTest iwi-aom--- 1.00g / dev/sdc (0)

[lvTest_mlog] vgTest lwi-aom--- 4.00m / dev/sdd (0)

The LVM image requires the-M1 parameter. As you can see from the above, / dev/sdb and / dev/sdc are mirrors to each other, while / dev/sdd is used as log storage.

4. Format the partition and create a file on the logical volume. Destroy / dev/sdc.

The code is as follows:

[root@node4 ~] # mkfs.ext4 / dev/vgTest/lvTest

Mke2fs 1.41.12 (17-May-2010)

File system label =

Operating system: Linux

Block size = 4096 (log=2)

Chunk size = 4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

65536 inodes, 262144 blocks

13107 blocks (5.00%) reserved for the super user

First data block = 0

Maximum filesystem blocks=268435456

8 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376

Writing inode table: complete

Creating journal (8192 blocks): complete

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or

180 days, whichever comes first. Use tune2fs-c or-i to override.

The code is as follows:

[root@node4 ~] # dd if=/dev/zero of=/dev/sdc count=10 bs=20M

Recorded a 10: 0 reading.

Recorded a 10: 0 write-out.

209715200 bytes (210 MB) replicated, 2.08666 seconds, 101 MB/ seconds

The code is as follows:

[root@node4] # lvs-a-o + devices

Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert Devices

Lv_root VolGroup-wi-ao---- 8.54g / dev/sda2 (0)

Lv_swap VolGroup-wi-ao---- 992.00m / dev/sda2 (2186)

LvTest vgTest mwi-a-m-p- 1.00g lvTest_mlog 100.00 lvTest_mimage_0 (0), lvTest_mimage_1 (0)

[lvTest_mimage_0] vgTest iwi-aom--- 1.00g / dev/sdb (0)

[lvTest_mimage_1] vgTest iwi-aom-p- 1.00g unknown device (0)

[lvTest_mlog] vgTest lwi-aom--- 4.00m / dev/sdd (0)

The code is as follows:

[root@node4 ~] # lvscan

Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.

ACTIVE'/ dev/vgTest/lvTest' [1.00 GiB] inherit

ACTIVE'/ dev/VolGroup/lv_root' [8.54 GiB] inherit

ACTIVE'/ dev/VolGroup/lv_swap' [992.00 MiB] inherit

The code is as follows:

[root@node4 ~] #

Remount the logical volume to confirm that the file can be read normally

The code is as follows:

[root@node4 ~] # mkdir / lvmTest

[root@node4 ~] # mount / dev/vgTest/lvTest / lvmTest/

[root@node4 ~] # cd / lvmTest/

[root@node4 lvmTest] # ls

Lost+found

The code is as follows:

[root@node4 lvmTest] # echo "ac" > ac

[root@node4 lvmTest] # cat ac

Ac

The code is as follows:

[root@node4 lvmTest] #

Remove the broken physical volume (/ dev/sdc) from the volume group:

The code is as follows:

[root@node4 lvmTest] # vgdisplay

Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.

-Volume group

VG Name vgTest

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 3

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 1

Open LV 1

Max PV 0

Cur PV 3

Act PV 2

VG Size 5.99 GiB

PE Size 4.00 MiB

Total PE 1533

Alloc PE / Size 513 / 2.00 GiB

Free PE / Size 1020 / 3.98 GiB

VG UUID 1qzO3A-Tjvi-by9l-Oq49-byz3-tIkx-rfSqex

The code is as follows:

[root@node4 lvmTest] # vgreduce-removemissing-force vgTest

Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.

Wrote out consistent volume group vgTest

The code is as follows:

[root@node4 lvmTest] #

5. Add a new physical volume (/ dev/sde) to the volume group:

The code is as follows:

[root@node4 lvmTest] # vgextend vgTest / dev/sde

Volume group "vgTest" successfully extended

The code is as follows:

[root@node4 lvmTest] #

6. Data recovery (there is no need to unmount the logical volume in the process)

The code is as follows:

[root@node4 lvmTest] # lvconvert-M1 / dev/vgTest/lvTest / dev/sdb / dev/sdd / dev/sde

VgTest/lvTest: Converted: 0.0%

VgTest/lvTest: Converted: 100.0%

The code is as follows:

[root@node4 lvmTest] # lvs-a-o + devices

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert Devices

Lv_root VolGroup-wi-ao---- 8.54g / dev/sda2 (0)

Lv_swap VolGroup-wi-ao---- 992.00m / dev/sda2 (2186)

LvTest vgTest mwi-aom--- 1.00g lvTest_mlog 100.00 lvTest_mimage_0 (0), lvTest_mimage_1 (0)

[lvTest_mimage_0] vgTest iwi-aom--- 1.00g / dev/sdb (0)

[lvTest_mimage_1] vgTest iwi-aom--- 1.00g / dev/sdd (0)

[lvTest_mlog] vgTest lwi-aom--- 4.00m / dev/sde (0)

7. Verify the original data

The code is as follows:

[root@node4 lvmTest] # cat ac

Ac

The code is as follows:

[root@node4 lvmTest] # echo "abcde" > > ac

[root@node4 lvmTest] # cat ac

Ac

Abcde

The code is as follows:

[root@node4 lvmTest] #

[root@node4 lvmTest] # lvdisplay

-Logical volume

LV Path / dev/vgTest/lvTest

LV Name lvTest

VG Name vgTest

LV UUID a8kDmI-R3ls-SfKJ-qx3d-1Tbb-wPAd-TJcQfn

LV Write Access read/write

LV Creation host, time node4.lansgg.com, 2015-09-10 20:50:41 + 0800

LV Status available

# open 1

LV Size 1.00 GiB

Current LE 256

Mirrored volumes 2

Segments 1

Allocation inherit

Read ahead sectors auto

-currently set to 256

Block device 253:5

The above content is how to use LVM to adjust hard disk partition in Ubuntu system. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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.

Share To

Servers

Wechat

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

12
Report