Technical explanation of LVM logical volume Management in CentOS

Source: Internet
Author: User
Tags hex code

1. Background of LVM logical volume Management Technology

The changing storage needs of enterprises make the traditional disk partition storage not flexible enough

2. Disk Partition Storage

For these three physical partitions, data will be filled one day sooner or later, because it is dead and cannot be scaled.

Assume that the three partitions on the/dev/sda disk are as follows:


1) initialize the three physical partitions on/dev/sda:

Command: # pvcreate/dev/sda1/dev/sda2/dev/sda3 or # pvcreate/dev/sda [1-3]

2) Merge the three physical Volume PVS into one Volume Group (VG Volume Group)


Command: # vgcreate vg0/dev/sda [1-2]

3) create a logical Volume LV from the volume group VG 0. The logical volume name is date.

Command: # lvcreate-n date-L 10 M vg0

4) Expand the date size of the LV logical volume:

Command: # e2fsadm-L + 10 M/dev/vg0/date

5) add another PV logical volume/dev/sda3 to VG:

Command: # vgextend vg0/dev/sda3

6) remove some physical partitions from the logical volume group LV:


Command: 1, # pvmove/dev/sda1 <-------- move data in sda1 to another physical volume

2. # vgreduce vg0/dev/sda1 <-------- remove the sda1 partition from the vg0 volume group

---------------------------------- Actual configuration process ----------------------------------

[Root @ localhost root] # fdisk/dev/sdb <--------- perform this experiment on the/dev/sdb partition.

Command (m for help): n
Command action
E extended
P primary partition (1-4)
P
Partition number (1-4): 1
First cylinder (1-522, default 1 ):
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-522, default 522): 200

Command (m for help): t <--------- converts the partition type
Selected partition 1
Hex code (type L to list codes): L <-------- type code used to list all partitions

0 Empty 1c Hidden Win95 FA 70 DiskSecure Mult bb Boot Wizard hid
1 FAT12 1e Hidden Win95 FA 75 PC/IX be Solaris boot
2 XENIX root 24 nec dos 80 Old Minix c1 DRDOS/sec (FAT-
3 XENIX usr 39 Plan 9 81 Minix/old Lin c4 DRDOS/sec (FAT-
4 FAT16 <32 M 3c PartitionMagic 82 Linux swap c6 DRDOS/sec (FAT-
5 Extended 40 Venix 80286 83 Linux c7 syr.pdf
6 FAT16 41 PPC PReP Boot 84 OS/2 hidden C: da Non-FS data
7 HPFS/NTFS 42 SFS 85 Linux extended db CP/M/CTOS /.
8 AIX 4d QNX4.x 86 NTFS volume set de Dell Utility
9 AIX bootable 4e QNX4.x 2nd part 87 NTFS volume set df BootIt
A OS/2 Boot Manag 4f QNX4.x 3rd part8e Linux LVM e1 DOS access
B Win95 FAT32 50 OnTrack DM 93 Amoeba e3 DOS R/O
C Win95 FAT32 (LB 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
E Win95 FAT16 (LB 52 CP/M 9f BSD/OS eb BeOS fs
F Win95 Ext 'd (LB 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
10 OPUS 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
11 Hidden FAT12 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC B
12 Compaq diagnost 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
14 Hidden FAT16 <3 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
16 Hidden FAT16 61 SpeedStor a9 NetBSD f2 DOS secondary
17 Hidden HPFS/NTF 63 gnu hurd or Sys AB Darwin boot fd Linux raid auto
18 AST SmartSleep 64 Novell Netware b7 BSDI fs fe LANstep
1b Hidden Win95 FA 65 Novell Netware b8 BSDI swap ff BBT
Hex code (type L to list codes): 8e <------ enter the corresponding Linux LVM partition code
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): n
Command action
E extended
P primary partition (1-4)
P
Partition number (1-4): 2
First cylinder (201-522, default 201 ):
Using default value 201
Last cylinder or + size or + sizeM or + sizeK (201-522, default 522): 401

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): n
Command action
E extended
P primary partition (1-4)
P
Partition number (1-4): 3
First cylinder (402-522, default 402 ):
Using default value 402
Last cylinder or + size or + sizeM or + sizeK (402-522, default 522 ):
Using default value 522

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p <------ print partition table information

Disk/dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1 1 200 1606468 + 8e Linux LVM
/Dev/sdb2 201 401 1614532 + 8e Linux LVM
/Dev/sdb3 402 522 971932 + 8e Linux LVM

Command (m for help): w <-------- save and quit ~!
The partition table has been altered!

Calling ioctl () to re-read partition table.
Syncing disks.
[Root @ localhost root] # pvcreate/dev/sdb [1-3] <--------- create a physical volume PV
Pvcreate -- ERROR: "/etc/lvmtab" doesn't exist; please run vgscan <-- create for the first time. run vgscan to generate the configuration file/etc/lvmtab.

[Root @ localhost root] # vgscan <----- run the vgscan command to generate the configuration file/etc/lvmtab.
Vgscan -- reading all physical volumes (this may take a while ...)
Vgscan -- "/etc/lvmtab" and "/etc/lvmtab. d" successfully created <---- two files are successfully created.
Vgscan -- WARNING: This program does not do a VGDA backup of your volume group

[Root @ localhost root] # pvcreate/dev/sdb [1-3] <------ create a pv physical partition again
Pvcreate -- physical volume "/dev/sdb1" successfully created
Pvcreate -- physical volume "/dev/sdb2" successfully created
Pvcreate -- physical volume "/dev/sdb3" successfully created

[Root @ localhost root] # vgcreate vg0/dev/sdb [1-2] <-------- create a vg volume group
Vgcreate -- INFO: using default physical extent size 4 MB
Vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte
Vgcreate -- doing automatic backup of volume group "vg0"
Vgcreate -- volume group "vg0" successfully created and activated

[Root @ localhost root] # vgdisplay vg0 <---------- view VG volume group information
--- Volume group ---
VG Name vg0
VG Access read/write
VG Status available/resizable
VG #0
MAX lv256
Cur LV 0
Open LV 0
Max lv Size 255.99 GB
Max PV 256
Cur PV 2
Act PV 2
VG Size 3.06 GB <--------- total available VG Size
PE Size 4 MB <--------- expansion block Size is 4 MB
Total PE 784 <--------- Total number of extended Blocks
Alloc PE/Size 0/0 <---------- assign the size in the form of PE Size
Free PE/Size 784/3 .06 GB
Vg uuid fsfUSc-GH4e-lQGl-EjS6-EMKF-56xa-V6Qpy4

[Root @ localhost root] # lvcreate-n data-L 100 M vg0 <-------- create a logical Volume lv: data in the vg0 volume group
Lvcreate -- doing automatic backup of "vg0"
Lvcreate -- logical volume "/dev/vg0/data" successfully created

[Root @ localhost root] # mkfs. ext3/dev/vg0/data <--------- format the logical Volume lv
Mke2fs 1.32 (09-Nov-2002)
Filesystem label =
OS type: Linux
Block size = 1024 (log = 0)
Fragment size = 1024 (log = 0)
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block = 1
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193,245 77, 40961,573 45, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
[Root @ localhost root] # mount/dev/vg0/data/mnt <---- mount a logical volume
[Root @ localhost root] # cp/etc/services/mnt <-------- test whether it can be used
[Root @ localhost root] # lvdisplay/dev/vg0/data <------- display detailed information about lv
--- Logical volume ---
LV Name/dev/vg0/data
VG Name vg0
LV Write Access read/write
LV Status available
LV #1
# Open 1
LV Size 100 MB <--------- logical volume Size
Current LE 25
Allocated LE 25
Allocation next free
Read ahead sectors 1024
Block device 58: 0

[Root @ localhost root] # vgdisplay vg0 <-------- displays the details of the volume group vg
--- Volume group ---
VG Name vg0
VG Access read/write
VG Status available/resizable
VG #0
MAX lv256
Cur LV 1
Open LV 1
Max lv Size 255.99 GB
Max PV 256
Cur PV 2
Act PV 2
VG Size 3.06 GB
PE Size 4 MB
Total PE 784
Alloc PE/Size 25/100 MB <---------- In the form of PE size to indicate the Size of allocated space
Free PE/Size 759/2 .96 GB <---------- the remaining space size is expressed in the form of PE Size
Vg uuid fsfUSc-GH4e-lQGl-EjS6-EMKF-56xa-V6Qpy4

[Root @ localhost root] # lvscan <------- view logical volume information
Lvscan -- ACTIVE "/dev/vga0./data" [100 MB]
Lvscan -- 1 logical volumes with 100 MB total in 1 volume group
Lvscan -- 1 active logical volumes

[Root @ localhost root] # df-lh <------- view the usage of the mounted Partition
Filesystem Size Used Avail Use % Mounted on
/Dev/sda1 5.0 GB 1.1G 3.6G 24%/
None 78 M 0 78 M 0%/dev/shm
/Dev/vg0/data 97 M 4.1 M 88 M 5%/mnt
[Root @ localhost root] # umount/mnt <------ uninstall/dev/vg0/data logical volume
[Root @ localhost root] # e2fsadm-L + 200 M/dev/vg0/data <------ 200 M for logical volumes/dev/vg0/data
E2fsck 1.32 (09-Nov-2002)
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/vg0/data: 12/25688 files (0.0% non-contiguous), 7398/102400 blocks
Lvextend -- extending logical volume "/dev/vg0/data" to 300 MB
Lvextend -- doing automatic backup of volume group "vg0"
Lvextend -- logical volume "/dev/vg0/data" successfully extended

Resize2fs 1.32 (09-Nov-2002)
Begin pass 1 (max = 25)
Extending the inode table xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin pass 2 (max = 1)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 13)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 5 (max = 7)
Moving inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on/dev/vg0/data is now 307200 blocks long.

E2fsadm -- ext2fs in logical volume/dev/vg0/data successfully extended to 300 MB <------ it has been successfully expanded to 300 MB

[Root @ localhost root] # mount/dev/vg0/data/mnt <------- mount the logical volume data again
[Root @ localhost root] # df-lh <----- view the usage of the mounted Partition
Filesystem Size Used Avail Use % Mounted on
/Dev/sda1 5.0 GB 1.1G 3.6G 24%/
None 78 M 0 78 M 0%/dev/shm
/Dev/vg0/data 291 M 4.1 M 272 M 2%/mnt <---------- has been successfully resized and mounted.
[Root @ localhost root] # vgdisplay vg0 <-------- view VG volume group information
--- Volume group ---
VG Name vg0
VG Access read/write
VG Status available/resizable
VG #0
MAX lv256
Cur LV 1
Open LV 1
Max lv Size 255.99 GB
Max PV 256
Cur PV 2
Act PV 2
VG Size 3.06 GB
PE Size 4 MB
Total PE 784
Alloc PE/Size 75/300 MB
Free PE/Size 709/2 .77 GB
Vg uuid fsfUSc-GH4e-lQGl-EjS6-EMKF-56xa-V6Qpy4

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.