Linux实用逻辑卷之建立LVM推荐

前面的文章我们介绍了LVM的基本概念,这篇文章就来动手实际操作一下,记录馒头(LVM逻辑卷)的加工过程,这里我的演示环境是VMware虚拟机,操作系统是RedHat Enterprise 5.3 64位操作系统,不同的Linux操作系统之间差别不大,这里也推荐大家使用虚拟机操作,因为这样可以更加灵活的添加硬盘。

实现目标

在接下来的操作中,我们将创建LVM逻辑卷,为系统分别添加3个 物理 硬盘,大小分别为1GB,这里的硬盘就做为LVM中的物理卷PV,然后创建卷组PV及逻辑卷LV。

准备面粉(物理卷PV)

由于使用的是虚拟机,那么可以轻松的为Linux系统添加磁盘,如下图所示,我为系统该虚拟机添加3块独立的SCSI硬盘。

添加好物理磁盘后我们启动系统,通过系统命令我们可以看到磁盘已经添加成功,显示分别为/dev/sdb、/dev/sdc、/dev/sdd

[root@localhost~]#fdisk-lDisk/dev/sda:21.4GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesDeviceBootStartEndBlocksIdSystem/dev/sda1*11310439183Linux/dev/sda214261020860402+8eLinuxLVMDisk/dev/sdb:1073MB,1073741824bytes255heads,63sectors/track,130cylindersUnits=cylindersof16065*512=8225280bytesDisk/dev/sdbdoesn'tcontainavalidpartitiontableDisk/dev/sdc:1073MB,1073741824bytes255heads,63sectors/track,130cylindersUnits=cylindersof16065*512=8225280bytesDisk/dev/sdcdoesn'tcontainavalidpartitiontableDisk/dev/sdd:1073MB,1073741824bytes255heads,63sectors/track,130cylindersUnits=cylindersof16065*512=8225280bytesDisk/dev/sdddoesn'tcontainavalidpartitiontable

虽然物理磁盘添加好了,但我们还要为其创建一个分区,并将系统识别码标示为 Linux LVM ,基本操作如下

[root@localhost~]#fdisk/dev/sdb//使用fdisk工具为磁盘创建分区DevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabelBuildinganewDOSdisklabel.Changeswillremaininmemoryonly,untilyoudecidetowritethem.Afterthat,ofcourse,thepreviouscontentwon'tberecoverable.Warning:invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite)Command(mforhelp):p//显示当前磁盘下已经存在的分区(目前为空)Disk/dev/sdb:1073MB,1073741824bytes255heads,63sectors/track,130cylindersUnits=cylindersof16065*512=8225280bytesDeviceBootStartEndBlocksIdSystemCommand(mforhelp):n//为磁盘添加分区Commandactioneextendedpprimarypartition(1-4)//这里选择创建主分区即可pPartitionnumber(1-4):1//输入分区号,这里输入1即可Firstcylinder(1-130,default1)://分区标记开始,使用默认即可Usingdefaultvalue1Lastcylinderor+sizeor+sizeMor+sizeK(1-130,default130)://分区标记结束,这里分配磁盘全部可用空间Usingdefaultvalue130Command(mforhelp):t//改变分区系统识别IDSelectedpartition1Hexcode(typeLtolistcodes):8e//这里8e代表LVM标示,可以输入L来查看系统支持的ID标示码Changedsystemtypeofpartition1to8e(LinuxLVM)Command(mforhelp):p//再次显示分区,可以看到分区已经创建好Disk/dev/sdb:1073MB,1073741824bytes255heads,63sectors/track,130cylindersUnits=cylindersof16065*512=8225280bytesDeviceBootStartEndBlocksIdSystem/dev/sdb111301044193+8eLinuxLVMCommand(mforhelp):w//最后输入w来报错分区操作Thepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.Syncingdisks.[root@localhost~]#pvcreate/dev/sdb1/dev/sdc1/dev/sdd1//创建物理卷PVPhysicalvolume /dev/sdb1 successfullycreatedPhysicalvolume /dev/sdc1 successfullycreatedPhysicalvolume /dev/sdd1 successfullycreated

上面的操作我们即可完成面粉(PV物理卷)的准备工作,其他两个盘符都按照这样的操作创建好分区,最后使用pvcreate命令创建物理卷PV。

准备面团(卷组VG)

卷组的操作非常简单,通过下面的命令即可将3个物理卷添加到卷组中

[root@localhost~]#vgcreatemyVG/dev/sdb1/dev/sdc1/dev/sdd1Volumegroup myVG successfullycreated

准备馒头(逻辑卷LV)

准备工作完成后,我们就可以从卷组中划分逻辑卷了,通过下面的命令我为系统分别创建3个大小为1000M的逻辑卷

[root@localhost~]#lvcreate-L1000M-nlv01myVG//-L指定分配空间大小-n指定逻辑卷名最后面为卷组名Logicalvolume lv01 created[root@localhost~]#lvcreate-L1000M-nlv02myVGLogicalvolume lv02 created[root@localhost~]#lvcreate-L1000M-nlv03myVGLogicalvolume lv03 created

蒸馒头(分配文件系统、挂载)

虽然我们已经完成了最后逻辑卷的创建,但是现在还不能用,因为逻辑卷还没有自己的文件系统,通过下面的操作为逻辑卷创建文件系统,并挂载到Linux中。

[root@localhost~]#mkfs.ext3/dev/myVG/lv01//为逻辑卷分配ext3文件系统[root@localhost~]#mkfs.ext3/dev/myVG/lv02[root@localhost~]#mkfs.ext3/dev/myVG/lv03[root@localhost~]#mkdir/lv01/lv02/lv03//创建挂载点[root@localhost~]#mount/dev/myVG/lv01/lv01//挂载逻辑卷[root@localhost~]#mount/dev/myVG/lv02/lv02/[root@localhost~]#mount/dev/myVG/lv03/lv03/

至此我们已经将最终的逻辑卷挂载到Linux操作系统中了,并且已经可以正常使用,为了系统下次启动时能够自动将逻辑卷添挂载到系统中,我们通过下面的操作来配置系统开机自动挂载。

[root@localhost~]#vi/etc/fstab/dev/VolGroup00/LogVol00/ext3defaults11LABEL=/boot/bootext3defaults12tmpfs/dev/shmtmpfsdefaults00devpts/dev/ptsdevptsgid=5,mode=62000sysfs/syssysfsdefaults00proc/procprocdefaults00/dev/VolGroup00/LogVol01swapswapdefaults00/dev/myVG/lv01/lv01ext3defaults00//这里为添加的挂载点/dev/myVG/lv02/lv02ext3defaults00/dev/myVG/lv03/lv03ext3defaults00

通过上面的操作即完成了逻辑卷的创建,后续我们会近一步讨论逻辑卷的管理及使用。

所有欺骗中,自欺是最为严重的

Linux实用逻辑卷之建立LVM推荐

相关文章:

你感兴趣的文章:

标签云: