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 create and use LVM logical volumes

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you how to create and use LVM logical volume, I hope you have something to gain after reading this article, let's discuss it together!

1 Creating PV

Add an sdb disk and create 4 partitions

[root@xuegod63 ~]# fdisk /dev/sdb #Create 4 primary partitions of 1G each

[root@xuegod63 ~]# ls /dev/sdb*

/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4

Set partition type code: fdisk /dev/sdb ===> t ==> Select partition number ===> 8e ====> w

Note: Now the system is smart enough to use the default 83 Linux partition directly, and you can also create pv.

Create pv using newly created partition

[root@xuegod63 ~]# pvcreate /dev/sdb{1,2,3,4} #Create pv

Physical volume "/dev/sdb1" successfully created.

Physical volume "/dev/sdb2" successfully created.

Physical volume "/dev/sdb3" successfully created.

Physical volume "/dev/sdb4" successfully created.

View information on creating pv

[root@xuegod63 ~]# pvdisplay /dev/sdb1 #View physical volume information

"/dev/sdb1" is a new physical volume of "1.00 GiB"

--- NEW Physical volume ---

PV Name /dev/sdb1

VG Name

PV Size 1.00 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID SHKFwf-WsLr-kkox-wlee-dAXc-5eL0-hyhaTV

2 Create a vg volume group

Syntax: vgcreate vg name pv name

[root@xuegod63 ~]# vgcreate vg01 /dev/sdb1

Volume group "vg01" successfully created

[root@xuegod63 ~]# vgs

VG #PV #LV #SN Attr VSize VFree

vg01 1 0 0 wz--n- 1020.00m 1020.00m

[root@xuegod63 ~]# vgdisplay vg01

--- Volume group ---

VG Name vg01

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 1

Act PV 1

VG Size 1020.00 MiB

PE Size 4.00 MiB

Total PE 255

Alloc PE / Size 0 / 0

3 Creating LV

lvcreate -n Specifies the name of the new logical volume-L Specifies the LV size SIZE(M,G)(-l: small l Specifies the number of LEs) vgname

[root@xuegod63 ~]# lvcreate -n lv01 -L 16M vg01

Logical volume "lv01" created.

[root@xuegod63 ~]# lvcreate -n lv02 -l 4 vg01

Logical volume "lv02" created.

[root@xuegod63 ~]# lvs

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

lv01 vg01 -wi-a----- 16.00m

lv02 vg01 -wi-a----- 16.00m

[root@xuegod63 ~]# pvdisplay /dev/sdb1

--- Physical volume ---

PV Name /dev/sdb1

VG Name vg01

PV Size 1.00 GiB / not usable 4.00 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 255

Free PE 247

Allocated PE 8 # Allocated ['? l? ke? t? d] Allocation, 8 PEs have been used

[root@xuegod63 ~]# vgdisplay vg01

。。。

Alloc PE / Size 8 / 32.00 MiB #already used 8M

Free PE / Size 247 / 988.00 MiB

[root@xuegod65 ~]# lvdisplay /dev/vg01/lv01 #Note that the absolute path should be followed here

--- Logical volume ---

LV Path /dev/vg01/lv01

LV Name lv01

VG Name vg01

LV UUID vx7Ib4-vkT8-MP6P-DubV-Vmhx-3Oau-LZcODv

LV Write Access read/write

LV Creation host, time xuegod65, 2018-05-19 12:32:50 +0800

LV Status available

# open 0

LV Size 16.00 MiB

Current LE 4

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 8192

Block device 253:2

4 File system formats and mounts

Create mount points

[root@xuegod63 ~]# mkdir /lv01

Interaction: where is the path to the lv01 logical volume?

#View logical volumes

[root@xuegod63 ~]# ls /dev/vg01/

lv01 lv02

LV01 is a soft link to DM-0.

[root@xuegod63 ~]# ll /dev/vg01/lv01

lrwxrwxrwx 1 root root 7 May 19 12:32 /dev/vg01/lv01 -> ../ dm-2

Format LV01 to ext4 format

[root@xuegod63 ~]# mkfs.ext4 /dev/vg01/lv01

Mount to LV01 mount point

[root@xuegod63 ~]# mount /dev/vg01/lv01 /lv01

View hanging situation

[root@xuegod63 ~]# df -Th /lv01

File System Type Capacity Used Available % Mount Point Used

/dev/mapper/vg01-lv01 ext4 15M 268K 14M 2% /lv01

Set boot auto mount

[root@xuegod63 ~]#echo "/dev/vg01/lv01 /lv01 ext4 defaults 0 0" >> /etc/fstab

After reading this article, I believe you have a certain understanding of "how to create and use LVM logical volumes". If you want to know more about this knowledge, please pay attention to 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.

Share To

Servers

Wechat

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

12
Report