LVM原理及详细操作.docx
- 文档编号:7844775
- 上传时间:2023-01-26
- 格式:DOCX
- 页数:15
- 大小:20.39KB
LVM原理及详细操作.docx
《LVM原理及详细操作.docx》由会员分享,可在线阅读,更多相关《LVM原理及详细操作.docx(15页珍藏版)》请在冰豆网上搜索。
LVM原理及详细操作
LVM
LVM是在磁盘分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统。
首先我们讨论以下几个LVM术语:
*物理存储介质(Thephysicalmedia)
这里指系统的存储设备:
硬盘,是存储系统最低层的存储单元。
*物理卷(physicalvolume)
物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
*卷组(VolumeGroup)
LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷组成。
可以在卷组上创建一个或多个“LVM分区”(逻辑卷),LVM卷组由一个或多个物理卷组成。
*逻辑卷(logicalvolume)
LVM的逻辑卷类似于非LVM系统中的硬盘分区,在逻辑卷之上可以建立文件系统(比如/home或者/usr等)。
*PE(physicalextent)
每一个物理卷被划分为称为PE(PhysicalExtents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。
PE的大小是可配置的,默认为4MB。
*LE(logicalextent)
逻辑卷也被划分为被称为LE(LogicalExtents)的可被寻址的基本单位。
在同一个卷组中,LE的大小和PE是相同的,并且一一对应。
首先可以看到,物理卷(PV)被由大小等同的基本单元PE组成。
一个卷组由一个或多个物理卷组成。
从上图可以看到,PE和LE有着一一对应的关系。
逻辑卷建立在卷组上。
逻辑卷就相当于非LVM系统的磁盘分区,可以在其上创建文件系统。
下图是磁盘分区、卷组、逻辑卷和文件系统之间的逻辑关系的示意图:
和非LVM系统将包含分区信息的元数据保存在位于分区的起始位置的分区表中一样,逻辑卷以及卷组相关的元数据也是保存在位于物理卷起始处的VGDA(卷组描述符区域)中。
VGDA包括以下内容:
PV描述符、VG描述符、LV描述符、和一些PE描述符。
系统启动LVM时激活VG,并将VGDA加载至内存,来识别LV的实际物理存储位置。
当系统进行I/O操作时,就会根据VGDA建立的映射机制来访问实际的物理位置。
LVM操作:
//查看物理磁盘状态
(none):
/home/liuzq/Desktop#fdisk-l
Disk/dev/sda:
107.3GB,107374182400bytes
255heads,63sectors/track,13054cylinders
Units=cylindersof16065*512=8225280bytes
Diskidentifier:
0x000cd6a5
DeviceBootStartEndBlocksIdSystem
/dev/sda11143114861682Linuxswap/Solaris
/dev/sda2*14413054103707607+83Linux
Disk/dev/sdb:
107.3GB,107374182400bytes
255heads,63sectors/track,13054cylinders
Units=cylindersof16065*512=8225280bytes
Diskidentifier:
0x00000000
Disk/dev/sdbdoesn'tcontainavalidpartitiontable
//使用fdisk对/dev/sdb分区
(none):
/home/liuzq/Desktop#fdisk/dev/sdb
DevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabel
BuildinganewDOSdisklabelwithdiskidentifier0xe5260b42.
Changeswillremaininmemoryonly,untilyoudecidetowritethem.
Afterthat,ofcourse,thepreviouscontentwon'tberecoverable.
Thenumberofcylindersforthisdiskissetto13054.
Thereisnothingwrongwiththat,butthisislargerthan1024,
andcouldincertainsetupscauseproblemswith:
1)softwarethatrunsatboottime(e.g.,oldversionsofLILO)
2)bootingandpartitioningsoftwarefromotherOSs
(e.g.,DOSFDISK,OS/2FDISK)
Warning:
invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite)
//创建新分区
Command(mforhelp):
new
Commandaction
eextended
pprimarypartition(1-4)
//设置成主分区
p
Partitionnumber(1-4):
1
Firstcylinder(1-13054,default1):
Usingdefaultvalue1
Lastcylinder,+cylindersor+size{K,M,G}(1-13054,default13054):
Usingdefaultvalue13054
Command(mforhelp):
m
Commandaction
atoggleabootableflag
beditbsddisklabel
ctogglethedoscompatibilityflag
ddeleteapartition
llistknownpartitiontypes
mprintthismenu
naddanewpartition
ocreateanewemptyDOSpartitiontable
pprintthepartitiontable
qquitwithoutsavingchanges
screateanewemptySundisklabel
tchangeapartition'ssystemid
uchangedisplay/entryunits
vverifythepartitiontable
wwritetabletodiskandexit
xextrafunctionality(expertsonly)
//继续下一步操作之前先确认对相应分区的修改正确无误。
如果一切妥当则写入新分区表
Command(mforhelp):
w
Thepartitiontablehasbeenaltered!
Callingioctl()tore-readpartitiontable.
Syncingdisks.
//查看分区后的物理磁盘
(none):
/home/liuzq/Desktop#fdisk-l
Disk/dev/sda:
107.3GB,107374182400bytes
255heads,63sectors/track,13054cylinders
Units=cylindersof16065*512=8225280bytes
Diskidentifier:
0x000cd6a5
DeviceBootStartEndBlocksIdSystem
/dev/sda11143114861682Linuxswap/Solaris
/dev/sda2*14413054103707607+83Linux
Disk/dev/sdb:
107.3GB,107374182400bytes
255heads,63sectors/track,13054cylinders
Units=cylindersof16065*512=8225280bytes
Diskidentifier:
0xe5260b42
DeviceBootStartEndBlocksIdSystem
/dev/sdb1113054104856223+83Linux
//进入LVM模式
(none):
/home/liuzq/Desktop#lvm
//查看LVM磁盘状态----目前没有任何LVM磁盘信息
lvm>lvmdiskscan
/dev/sda1[1.10GB]
/dev/root[98.90GB]
/dev/sdb1[100.00GB]
1disk
2partitions
0LVMphysicalvolumewholedisks
0LVMphysicalvolumes
//查看LVM的配置文件
lvm>dumpconfig
devices{
dir="/dev"
scan="/dev"
filter=["r|/dev/.*/by-path/.*|","r|/dev/.*/by-id/.*|","a/.*/"]
cache="/etc/lvm/.cache"
write_cache_state=1
sysfs_scan=1
md_component_detection=1
}
dmeventd{
mirror_library="libdevmapper-event-lvm2mirror.so.2.02"
snapshot_library="libdevmapper-event-lvm2snapshot.so.2.02"
}
activation{
missing_stripe_filler="/dev/ioerror"
mirror_region_size=512
reserved_stack=256
reserved_memory=8192
process_priority=-18
}
global{
umask=63
test=0
activation=1
proc="/proc"
locking_type=1
locking_dir="/var/lock/lvm"
}
shell{
history_size=100
}
backup{
backup=1
backup_dir="/etc/lvm/backup"
archive=1
archive_dir="/etc/lvm/archive"
retain_min=10
retain_days=30
}
log{
verbose=0
syslog=1
overwrite=0
level=0
indent=1
command_names=0
prefix=""
}
//创建PV
lvm>pvcreate/dev/sdb1
Nophysicalvolumelabelreadfrom/dev/sdb1
Physicalvolume"/dev/sdb1"successfullycreated
//查看PV状态
lvm>pvdisplay
"/dev/sdb1"isanewphysicalvolumeof"100.00GB"
---NEWPhysicalvolume---
PVName/dev/sdb1
VGName
PVSize100.00GB
AllocatableNO
PESize(KByte)0
TotalPE0
FreePE0
AllocatedPE0
PVUUID7daSq9-7KXU-Lvil-SUHc-ELrI-fyX7-FM9Bfy
//再次查看LVM磁盘状态
lvm>lvmdiskscan
/dev/sda1[1.10GB]
/dev/root[98.90GB]
/dev/sdb1[100.00GB]LVMphysicalvolume
1disk
1partition
0LVMphysicalvolumewholedisks
1LVMphysicalvolume
//创建VG
lvm>vgcreatevg_test/dev/sdb1
Volumegroup"vg_test"successfullycreated
//查看VG状态
lvm>vgdisplay
---Volumegroup---
VGNamevg_test
SystemID
Formatlvm2
MetadataAreas1
MetadataSequenceNo1
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV0
OpenLV0
MaxPV0
CurPV1
ActPV1
VGSize100.00GB
PESize4.00MB
TotalPE25599
AllocPE/Size0/0
FreePE/Size25599/100.00GB
VGUUIDoSUogC-mV2F-b7Dg-5sFa-tztZ-NDh4-fpL6zu
//查看所有VG
lvm>vgs
VG#PV#LV#SNAttrVSizeVFree
vg_test100wz--n-100.00G100.00G
//创建LV
lvm>lvcreate--size10G--namelvm_u1vg_test
Logicalvolume"lvm_u1"created
//查看LV状态
lvm>lvs
LVVGAttrLSizeOriginSnap%MoveLogCopy%Convert
lvm_u1vg_test-wi-a-10.00G
lvm>vgs
VG#PV#LV#SNAttrVSizeVFree
vg_test110wz--n-100.00G90.00G
//退出LVM配置模式
lvm>exit
Exiting.
//ext3格式化逻辑卷
(none):
/home/liuzq/Desktop#mkfs-text3-j/dev/vg_test/lvm_u1
mke2fs1.41.1(01-Sep-2008)
Filesystemlabel=
OStype:
Linux
Blocksize=4096(log=2)
Fragmentsize=4096(log=2)
655360inodes,2621440blocks
131072blocks(5.00%)reservedforthesuperuser
Firstdatablock=0
Maximumfilesystemblocks=2684354560
80blockgroups
32768blockspergroup,32768fragmentspergroup
8192inodespergroup
Superblockbackupsstoredonblocks:
32768,98304,163840,229376,294912,819200,884736,1605632
Writinginodetables:
done
Creatingjournal(32768blocks):
done
Writingsuperblocksandfilesystemaccountinginformation:
done
Thisfilesystemwillbeautomaticallycheckedevery26mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.
//使用LVM
//首先创建挂载点
(none):
/home/liuzq/Desktop#mkdir/mnt/u1
//挂载卷
(none):
/home/liuzq/Desktop#mount/dev/vg_test/lvm_u1/mnt/u1/
//检查磁盘空间
(none):
/home/liuzq/Desktop#df-m/mnt/u1/
Filesystem1M-blocksUsedAvailableUse%Mountedon
/dev/mapper/vg_test-lvm_u1
1008015194172%/mnt/u1
(none):
/home/liuzq/Desktop#ls/mnt/u1/
lost+found
(none):
/home/liuzq/Desktop#ll/boot/
total14056
-rw-------1rootroot5122012-12-2009:
15backup_mbr
lrwxrwxrwx1rootroot12012-12-2009:
00boot->.
-rw-r--r--1rootroot12362009-02-2406:
40boot.readme
-rw-r--r--1rootroot901372009-02-2803:
09config-2.6.27.19-5-default
drwxr-xr-x2rootroot5682012-12-2009:
15grub
lrwxrwxrwx1rootroot262012-12-2009:
21initrd->initrd-2.6.27.19-5-default
-rw-r--r--1rootroot61993942012-12-2009:
21initrd-2.6.27.19-5-default
-rw-r--r--1rootroot4352002012-12-2009:
15message
-rw-r--r--1rootroot1412062009-02-2803:
13symsets-2.6.27.19-5-default.tar.gz
-rw-r--r--1rootroot4048042009-02-2803:
12symtypes-2.6.27.19-5-default.gz
-rw-r--r--1rootroot1195802009-02-2803:
10symvers-2.6.27.19-5-default.gz
-rw-r--r--1rootroot14194512009-02-2803:
01System.map-2.6.27.19-5-default
-rw-r--r--1rootroot30043232009-02-2803:
09vmlinux-2.6.27.19-5-default.gz
lrwxrwxrwx1rootroot272012-12-2009:
06vmlinuz->vmlinuz-2.6.27.19-5-default
-rw-r--r--1rootroot25371842009-02-2803:
01vmlinuz-2.6.27.19-5-default
//在新建文件系统里复制一个大文件例如在/boot目录里挑个内核文件复制到/mnt/u1
(none):
/home/liuzq/Desktop#cp/boot/vmlinux-2.6.27.19-5-default.gz/mnt/u1/
//对复制过来的文件运行md5sum并保存校验值留待后用
(none):
/home/liuzq/Desktop#md5sum/mnt/u1/vmlinux-2.6.27.19-5-default.gz
71603654a26edc4faa85054cbe2900be/mnt/u1/vmlinux-2.6.27.19-5-default.gz
(none):
/home/liuzq/Desktop#ll/mnt/u1/
total2956
drwx------2rootroot163842013-01-0501:
43lost+found
-rw-r--r--1rootroot30043232013-01-0501:
51vmlinux-2.6.27.19-5-default.gz
//扩大LVM卷
假定空间不够用准备向LVM卷增加更多空间。
首先卸载该卷并使用lvresize命令调整卷大小。
然后还必须用e2fsck检查整个文件系统并运行resize2fs调整该卷上ext3文件系统的大小
//卸载
(none):
/home/liuzq/Desktop#umount/mnt/u1/
//调整卷大小
(none):
/home/liuzq/Desktop#lvresize--size20G/dev/vg_test/lvm_u1
Extendinglogicalvolumelvm_u1to20.00GB
Logicalvolumelvm_u1successfullyresized
//检查文件系统
(none):
/home/liuzq/Desktop#e2fsck-f/dev/vg_test/lvm_u1
e2fsck1.41.1(01-Sep-2008)
Pass1:
Checkinginodes,blocks,andsizes
Pass2:
Checkingdirectorystr
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- LVM 原理 详细 操作
![提示](https://static.bdocx.com/images/bang_tan.gif)