Linux的LVM(Logical Volume Manager) 学习笔记(2)

3、LVM基础配置试验

LVM配置主要是通过LVM命令台和工具命令来实现的。通过lvm的帮助功能,我们能看到对lv、vg和pv的管理命令。

[root@SimpleLinux ~]# lvm

lvm> help

Available lvm commands:

Use 'lvm help <command>' for more information

dumpconfigDump active configuration

formatsList available metadata formats

helpDisplay help for commands

lvchangeChange the attributes of logical volume(s)

lvconvertChange logical volume layout

lvcreateCreate a logical volume

lvdisplayDisplay information about a logical volume

lvextendAdd space to a logical volume

lvmchangeWith the device mapper, this is obsolete and does nothing.

lvmdiskscanList devices that may be used as physical volumes

lvmsadcCollect activity data

lvmsarCreate activity report

lvreduceReduce the size of a logical volume

lvremoveRemove logical volume(s) from the system

lvrenameRename a logical volume

lvresizeResize a logical volume

lvsDisplay information about logical volumes

lvscanList all logical volumes in all volume groups

pvchangeChange attributes of physical volume(s)

pvresizeResize physical volume(s)

pvckCheck the consistency of physical volume(s)

pvcreateInitialize physical volume(s) for use by LVM

pvdataDisplay the on-disk metadata for physical volume(s)

pvdisplayDisplay various attributes of physical volume(s)

pvmoveMove extents from one physical volume to another

pvremoveRemove LVM label(s) from physical volume(s)

pvsDisplay information about physical volumes

pvscanList all physical volumes

segtypesList available segment types

vgcfgbackupBackup volume group configuration(s)

vgcfgrestoreRestore volume group configuration

vgchangeChange volume group attributes

vgckCheck the consistency of volume group(s)

vgconvertChange volume group metadata format

vgcreateCreate a volume group

vgdisplayDisplay volume group information

vgexportUnregister volume group(s) from the system

vgextendAdd physical volumes to a volume group

vgimportRegister exported volume group with system

vgmergeMerge volume groups

vgmknodesCreate the special files for volume group devices in /dev

vgreduceRemove physical volume(s) from a volume group

vgremoveRemove volume group(s)

vgrenameRename a volume group

vgsDisplay information about volume groups

vgscanSearch for all volume groups

vgsplitMove physical volumes into a new or existing volume group

versionDisplay software and driver version information

lvm>

注意:lvm虽然提供了控制台接口,但是直接敲命令Linux也是支持的。

[root@SimpleLinux /]# pvscan

No matching physical volumes found

虽然命令行很多,但是基本上lvm的命令还有很强的规律性。lv开头的都是对logical volume的操作,vg是对logical volume group,而pv是针对phyiscal volume的操作。

创建使用LVM,我们需要从最底层的PV进行构建管理。首先,我们需要创建最底层的Phsical Volume。

--pvcreate命令创建PV

[root@SimpleLinux /]# pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created

--显示信息

[root@SimpleLinux /]# pvscan

PV /dev/sdb1lvm2 [8.00 GB]

Total: 1 [8.00 GB] / in use: 0 [0] / in no VG: 1 [8.00 GB]

[root@SimpleLinux /]# pvcreate /dev/sdc1

Physical volume "/dev/sdc1" successfully created

[root@SimpleLinux /]# pvcreate /dev/sdc2

Physical volume "/dev/sdc2" successfully created

[root@SimpleLinux /]# pvcreate /dev/sdc3

Physical volume "/dev/sdc3" successfully created

[root@SimpleLinux /]# pvcreate /dev/sdc5

Physical volume "/dev/sdc5" successfully created

[root@SimpleLinux /]# pvcreate /dev/sdc6

Physical volume "/dev/sdc6" successfully created

[root@SimpleLinux /]# pvscan

PV /dev/sdb1lvm2 [8.00 GB]

PV /dev/sdc1lvm2 [1.87 GB]

PV /dev/sdc2lvm2 [1.87 GB]

PV /dev/sdc3lvm2 [1.87 GB]

PV /dev/sdc5lvm2 [1.87 GB]

PV /dev/sdc6lvm2 [3.07 GB]

Total: 6 [18.55 GB] / in use: 0 [0] / in no VG: 6 [18.55 GB]

[root@SimpleLinux /]#

使用pvs可以显示出当前可用的Physical Volume情况。

[root@SimpleLinux /]# pvs

PVVGFmtAttr PSize PFree

/dev/sdb1lvm2 --8.00G 8.00G

/dev/sdc1lvm2 --1.87G 1.87G

/dev/sdc2lvm2 --1.87G 1.87G

/dev/sdc3lvm2 --1.87G 1.87G

/dev/sdc5lvm2 --1.87G 1.87G

/dev/sdc6lvm2 --3.07G 3.07G

底层PV创建完成之后,就可以创建Logical Volume Group。

[root@SimpleLinux /]# vgcreate VolGrp01 /dev/sdb1 /dev/sdc1

Volume group "VolGrp01" successfully created

[root@SimpleLinux /]# vgs

VG#PV #LV #SN AttrVSize VFree

VolGrp01200 wz--n- 9.86G 9.86G

[root@SimpleLinux /]# vgcreate VolGrp02 /dev/sdc2 /dev/sdc3

Volume group "VolGrp02" successfully created

[root@SimpleLinux /]# vgs

VG#PV #LV #SN AttrVSize VFree

VolGrp01200 wz--n- 9.86G 9.86G

VolGrp02200 wz--n- 3.73G 3.73G

[root@SimpleLinux /]# vgdisplay

--- Volume group ---

VG NameVolGrp02

System ID

Formatlvm2

Metadata Areas2

Metadata Sequence No1

VG Accessread/write

VG Statusresizable

MAX LV0

Cur LV0

Open LV0

Max PV0

Cur PV2

Act PV2

VG Size3.73 GB

PE Size4.00 MB

Total PE956

Alloc PE / Size0 / 0

FreePE / Size956 / 3.73 GB

VG UUIDgfB8C3-80Ym-eEO5-L12p-8vdS-GWxy-t1QgWx

--- Volume group ---

VG NameVolGrp01

System ID

Formatlvm2

Metadata Areas2

Metadata Sequence No1

VG Accessread/write

VG Statusresizable

MAX LV0

Cur LV0

Open LV0

Max PV0

Cur PV2

Act PV2

VG Size9.86 GB

PE Size4.00 MB

Total PE2525

Alloc PE / Size0 / 0

FreePE / Size2525 / 9.86 GB

VG UUIDSDx5QB-7t14-RFrk-FUkK-1M43-4sNe-LFljgm

创建了两个LVG对象,每个LVG中包括两个分区PV。VolGrp01和VolGrp02为我们创建出的存储池。在其中,我们可以创建控制大小的Logical Volume。

[root@SimpleLinux /]# lvcreate -n lv1 -L +100M VolGrp01

Logical volume "lv1" created

[root@SimpleLinux /]# lvs

LVVGAttrLSizeOrigin Snap%Move Log Copy%Convert

lv1VolGrp01 -wi-a- 100.00M

注意下lvcreate参数,-n表示创建lv的名称,-L表示补充大小。最后一个参数表示在哪个LVG中进行分配。这个分配动作是动态过程。创建了lv1之后,就可以将其作为一个存储进行单独使用。

最后,我们可以格式化lv1,进行分配。

[root@SimpleLinux ~]# mkfs -t ext3 /dev/VolGrp01/lv1

mke2fs 1.39 (29-May-2006)

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

Maximum filesystem blocks=67371008

13 block groups

8192 blocks per group, 8192 fragments per group

1976 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or

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

最后,我们可以加载mount到一个目录上。

[root@SimpleLinux /]# mkdir /voltest01

[root@SimpleLinux /]# ls -l | grep vol

drwxr-xr-x2 rootroot4096 Oct9 12:30 voltest01

[root@SimpleLinux VolGrp01]# mount /dev/VolGrp01/lv1 /voltest01

[root@SimpleLinux VolGrp01]# df -h

FilesystemSizeUsed Avail Use% Mounted on

/dev/sda148G11G35G23% /

tmpfs449M0449M0% /dev/shm

/dev/mapper/VolGrp01-lv1

97M1.6M91M2% /voltest01

使用dd命令,测试/voltest01目录的可用性。

[root@SimpleLinux VolGrp01]# cd /voltest01/

[root@SimpleLinux voltest01]# ls -l

total 12

drwx------ 2 root root 12288 Oct9 12:34 lost+found

[root@SimpleLinux voltest01]# dd if=/dev/zero f=/voltest01/res bs=1024 count=1000

1000+0 records in

1000+0 records out

1024000 bytes (1.0 MB) copied, 0.00376333 seconds, 272 MB/s

[root@SimpleLinux voltest01]# ls -l

total 1017

drwx------ 2 root root12288 Oct9 12:34 lost+found

-rw-r--r-- 1 root root 1024000 Oct9 12:36 res

添加目录和加载成功。最后一个问题是,我们加载mount是手工过程,需要修改/etc/fstab,来实现自动添加。在下次reboot系统时候,就可以实现自动加载Logical Volume了。

[root@SimpleLinux ~]# blkid

/dev/sda2: TYPE="swap" LABEL="SWAP-sda2"

/dev/sda1: LABEL="/" UUID="36e661fb-e9ef-4583-8fc9-422b00009016" TYPE="ext3" SEC_TYPE="ext2"

/dev/cdrom: LABEL="RHEL/5.3 i386 DVD" TYPE="iso9660"

/dev/VolGrp01/lv1: UUID="5e007a89-326d-4a71-9744-8cd7d36a90a7" SEC_TYPE="ext2" TYPE="ext3"

/dev/mapper/VolGrp01-lv1: UUID="5e007a89-326d-4a71-9744-8cd7d36a90a7" SEC_TYPE="ext2" TYPE="ext3"

[root@SimpleLinux ~]# cat /etc/fstab

LABEL=//ext3defaults1 1

tmpfs/dev/shmtmpfsdefaults0 0

devpts/dev/ptsdevptsgid=5,mode=6200 0

sysfs/syssysfsdefaults0 0

proc/procprocdefaults0 0

UUID="5e007a89-326d-4a71-9744-8cd7d36a90a7"/voltest01ext3defaults1 1

LABEL=SWAP-sda2swapswapdefaults0 0

重新reboot之后,依然加载成功。

[root@SimpleLinux ~]# df -h

FilesystemSizeUsed Avail Use% Mounted on

/dev/sda148G11G35G23% /

tmpfs449M0449M0% /dev/shm

/dev/mapper/VolGrp01-lv1

97M5.6M87M7% /voltest01

下面我们测试一下LVM的调整功能。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/18002.html