CentOS under LVM logical volume creation and use

Linux disk management: LVM LVM logical basic concepts and works, a detailed explanation of the basic concepts of dynamic disk management Linux LVM logical volumes and LVM works, including LVM is the most important of the four basic points (PE, PV , VG and LV), this essay will explain in detail the creation of LVM logical volumes, use, and delete.

First, create LVM logical volumes

Illustrated the way we look at how to create our LVM, it is on an essay, we are already familiar with LVM works, first is to our physical hard drives formatted as PV, then added to create multiple PV good VG, the last created by our LV VG. So we first step is to our physical hard disk formatted into PV (physical volume)

Here I have three quick advance virtualization physical drives, each drive’s size is 8G, by fdisk -l command to view
Copy the code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

[root@xiaoluo~]# fdisk -l

Disk/dev/sda:21.5GB,21474836480bytes

255heads,63sectors/track,2610cylinders

Units=cylinders of16065*512=8225280bytes

Sector size(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Disk identifier:0x00093d90

Device Boot Start EndBlocks Id System

/dev/sda11523419430482Linux swap/Solaris

Partition1does notendon cylinder boundary.

/dev/sda2 *52326111677619283Linux

Disk/dev/sdb:8589MB,8589934592bytes

255heads,63sectors/track,1044cylinders

Units=cylinders of16065*512=8225280bytes

Sector size(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Disk identifier:0x00000000

Disk/dev/sdc:8589MB,8589934592bytes

255heads,63sectors/track,1044cylinders

Units=cylinders of16065*512=8225280bytes

Sector size(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Disk identifier:0x00000000

Disk/dev/sdd:8589MB,8589934592bytes

255heads,63sectors/track,1044cylinders

Units=cylinders of16065*512=8225280bytes

Sector size(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Disk identifier:0x00000000

Here we are in accordance with the above figure, we first / dev / sdb, / dev / sdc two hard drives formatted as PV

1

2

3

4

[root@xiaoluo~]# pvcreate /dev/sdb /dev/sdc

Physical volume"/dev/sdb"successfully created

Physical volume"/dev/sdc"successfully created

After you create the PV, we can use pvdisplay (show details), pvs command to view information about the current pv

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

[root@xiaoluo~]# pvdisplay

"/dev/sdb"isanewphysical volume of"8.00 GiB"

---NEWPhysical volume---

PV Name/dev/sdb

VG Name

PV Size8.00GiB

Allocatable NO

PE Size0

Total PE0

Free PE0

Allocated PE0

PV UUID93UEEl-cxBU-A4HC-LNSh-jp9G-uU5Q-EG8LM9

"/dev/sdc"isanewphysical volume of"8.00 GiB"

---NEWPhysical volume---

PV Name/dev/sdc

VG Name

PV Size8.00GiB

Allocatable NO

PE Size0

Total PE0

Free PE0

Allocated PE0

PV UUID lH1vul-KBHx-H2C6-wbt1-8AdK-yHpr-bBIul5

[root@xiaoluo~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sdb lvm2a--8.00g8.00g

/dev/sdc lvm2a--8.00g8.00g

With these two commands, we can see a good PV information that we have created, two PV are 8G, there is no use, PFree is 8G.

② create a volume group (VG), and PV is added to the volume group by the vgcreate command

After you create the PV, this time we need to create a VG, then our PV are added to them this volume group, from the volume group when you create a volume group to give a name

1

2

3

[root@xiaoluo~]# vgcreate xiaoluo /dev/sdb /dev/sdc

Volume group"xiaoluo"successfully created

Similarly, after the created VG, we can also use vgdisplay or vgs command to view information about VG

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[root@xiaoluo~]# vgdisplay

---Volume group---

VG Name xiaoluo

System ID

Format lvm2

Metadata Areas2

Metadata Sequence No1

VG Access read/write

VG Status resizable

MAX LV0

Cur LV0

Open LV0

Max PV0

Cur PV2// /dev/sdb 和 /dev/sdc

Act PV2

VG Size15.99GiB//

PE Size4.00MiB//

Total PE4094//

Alloc PE/Size0/0

Free PE/Size4094/15.99GiB

VG UUID B8eavI-21kD-Phnm-F1t1-eo4K-wgvg-T5qUbt

[root@xiaoluo~]# vgs

VG#PV #LV #SN Attr VSize VFree

xiaoluo200wz--n-15.99g15.99g

③ Based on the volume group (VG) create a logical volume (LV) by lvcreate command

Because creating good PV, VG are the bottom of things, we use the upper logical, so we have to create our logical volume is based VG job

1

2

3

[root@xiaoluo~]# lvcreate -n mylv -L 2G xiaoluo

Logical volume"mylv"created

VG created our logical name for the mylv, the size of 2G, we can use the same lvdisplay or lvs command to check the created logical volumes by lvcreate command based

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

[root@xiaoluo~]# lvdisplay

---Logical volume---

LV Path/dev/xiaoluo/mylv//

LV Name mylv//

VG Name xiaoluo//

LV UUID PYuiYy-WpI6-XZB8-IhnQ-ANjM-lcz0-dlk4LR

LV Write Access read/write

LV Creation host,time xiaoluo,2013-05-2323:45:08+0800

LV Status available

# open 0

LV Size2.00GiB//

Current LE512

Segments1

Allocation inherit

Read ahead sectors auto

-currently set to256

Block device253:0

[root@xiaoluo~]# lvs

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

mylv xiaoluo-wi-a----2.00g

This way we will have created a logical volume, and this time we take another look at our information via the PV and VG also vgs pvs command

1

2

3

4

5

6

7

8

[root@xiaoluo mnt]# vgs

VG#PV #LV #SN Attr VSize VFree

xiaoluo210wz--n-15.99g13.99g//

[root@xiaoluo mnt]# pvs

PV VG Fmt Attr PSize PFree

/dev/sdb xiaoluo lvm2a--8.00g6.00g//

/dev/sdc xiaoluo lvm2a--8.00g8.00g

We found that when we each have created a LV, VG and PV information is constantly changing, and we create the LV size is based on the current size of VG to the decision, no more than the remaining size of current VG!

We have talked in an essay on the inside, each created a logical volume, there will be a volume group named folder in the / dev directory, based on all of the logical volume group is created that is stored in this folder, we can look

1

2

3

[root@xiaoluo~]# ls /dev/xiaoluo/mylv

/dev/xiaoluo/mylv

We each create a new logical volume, the VG catalog will be more such a device.

Second, the format and the use of our logical volumes

We have created our PV, VG and LV, this time if we want to use the logical volume, it must be formatted as we need to use the file system, and mount up, and then you can go as using the same partition using logical volumes of

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

[root@xiaoluo~]# mkfs.ext4 /dev/xiaoluo/mylv

mke2fs1.41.12(17-May-2010)

Filesystem label=

OS type:Linux

Block size=4096(log=2)

Fragment size=4096(log=2)

Stride=0blocks,Stripe width=0blocks

131072inodes,524288blocks

26214blocks(5.00%)reserved forthe superuser

First data block=0

Maximum filesystem blocks=536870912

16block groups

32768blocks per group,32768fragments per group

8192inodes per group

Superblock backups stored on blocks:

32768,98304,163840,229376,294912

Writing inode tables:done

Creating journal(16384blocks):done

Writing superblocks andfilesystem accounting information:done

Thisfilesystem will be automatically checked every31mounts or

180days,whichever comes first.Usetune2fs-cor-itooverride.

After our logical format, you can use the mount command to be mounted, we will mount it to / mnt directory

We see that our group has mounted a good volume, and can use as partitions to be the same document operate.

Third, delete the logical volume

After we created a logical volume by creating a file system, mount the logical volume to use it, if we do not want to use or it can be deleted.

[Note:] to create a physical volume, create a volume group and create logical volumes we have a strict order, also, to remove the logical volume, delete the volume group and remove the physical volume is also a strict sequence requirements

① First, the logical volume is being used by umount command uninstall

② to delete the logical command by lvremove

③ Delete volume group commands by vgremove

④ Finally, we come to remove the physical volumes by pvremove command

1

2

3

4

5

6

7

8

9

10

11

[root@xiaoluo/]# mount /dev/xiaoluo/mylv /mnt/

[root@xiaoluo/]# umount /mnt/

[root@xiaoluo/]# lvremove /dev/xiaoluo/mylv

Doyou really want toremove active logical volume mylv?[y/n]:y

Logical volume"mylv"successfully removed

[root@xiaoluo/]# vgremove xiaoluo

Volume group"xiaoluo"successfully removed

[root@xiaoluo/]# pvremove /dev/sdb

Labels on physical volume"/dev/sdb"successfully wiped

At this point we just created logical mylv, xiaoluo volume group and physical volume / dev / sdb has been removed from our current operating system out by lvs, vgs, pvs command to check

1

2

3

4

5

6

7

8

9

[root@xiaoluo/]# lvs

No volume groups found//

[root@xiaoluo/]# vgs

No volume groups found//

[root@xiaoluo/]# pvs

PV VG Fmt Attr PSize PFree

/dev/sdc lvm2a--8.00g8.00g//

essays explain in detail the creation of LVM logical volumes, use and remove, in the next essay we will continue to explain the knowledge LVM logical volumes, including how the logical volume dynamic stretching and compressing them! ! !