LVM原理及详细操作_第1页
LVM原理及详细操作_第2页
LVM原理及详细操作_第3页
LVM原理及详细操作_第4页
LVM原理及详细操作_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、最新LVM原理及详细操作LVMLVM是在磁盘分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统。首先我们讨论以下几个LVM术语: *物理存储介质The physical media 这里指系统的存储设备:硬盘,是存储系统最低层的存储单元。 *物理卷physical volume 物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备如RAID,是LVM的根本存储逻辑块,但和根本的物理存储介质如分区、磁盘等比拟,却包含有与LVM相关的管理参数。 *卷组Volume Group LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷组成

2、。可以在卷组上创立一个或多个“LVM分区逻辑卷,LVM卷组由一个或多个物理卷组成。 *逻辑卷logical volume LVM的逻辑卷类似于非LVM系统中的硬盘分区,在逻辑卷之上可以建立文件系统比方/home或者/usr等。 *PEphysical extent 每一个物理卷被划分为称为PE(PhysicalExtents的根本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。 *LElogical extent 逻辑卷也被划分为被称为LE(LogicalExtents的可被寻址的根本单位。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。 首先

3、可以看到,物理卷PV被由大小等同的根本单元PE组成。 一个卷组由一个或多个物理卷组成。 从上图可以看到,PE和LE有着一一对应的关系。逻辑卷建立在卷组上。逻辑卷就相当于非LVM系统的磁盘分区,可以在其上创立文件系统。 下列图是磁盘分区、卷组、逻辑卷和文件系统之间的逻辑关系的示意图: 和非LVM系统将包含分区信息的元数据保存在位于分区的起始位置的分区表中一样,逻辑卷以及卷组相关的元数据也是保存在位于物理卷起始处的VGDA卷组描述符区域中。VGDA包括以下内容:PV描述符、VG描述符、LV描述符、和一些PE描述符。 系统启动LVM时激活VG,并将VGDA加载至内存,来识别LV的实际物理存储位置。当

4、系统进行I/O操作时,就会根据VGDA建立的映射机制来访问实际的物理位置。LVM操作:/查看物理磁盘状态(none):/home/liuzq/Desktop # fdisk -l255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0 x000cd6a5 Device Boot Start End Blocks Id System/dev/sda1 1 143 1148616 82 Linux swap / Solaris/dev/

5、sda2 * 144 13054 103707607+ 83 Linux255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0 x00000000Disk /dev/sdb doesnt contain a valid partition table/使用fdisk对/dev/sdb分区(none):/home/liuzq/Desktop # fdisk /dev/sdbDevice contains neither a vali

6、d DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0 xe5260b42.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content wont be recoverable.The number of cylinders for this disk is set to 13054.T

7、here is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)Warning: invalid flag 0 x0000 of partition tab

8、le 4 will be corrected by w(rite)/创立新分区Command (m for help): newCommand action e extended p primary partition (1-4)/设置成主分区pPartition number (1-4): 1First cylinder (1-13054, default 1): Using default value 1Last cylinder, +cylinders or +sizeK,M,G (1-13054, default 13054): Using default value 13054Com

9、mand (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving ch

10、anges s create a new empty Sun disklabel t change a partitions system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)/继续下一步操作之前先确认对相应分区的修改正确无误。如果一切妥当那么写入新分区表Command (m for help): wThe partition table has been altered!Ca

11、lling ioctl() to re-read partition table.Syncing disks./查看分区后的物理磁盘(none):/home/liuzq/Desktop # fdisk -l255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0 x000cd6a5 Device Boot Start End Blocks Id System/dev/sda1 1 143 1148616 82 Linux swap

12、/ Solaris/dev/sda2 * 144 13054 103707607+ 83 Linux255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0 xe5260b42 Device Boot Start End Blocks Id System/dev/sdb1 1 13054 104856223+ 83 Linux/进入LVM模式(none):/home/liuzq/Desktop # lvm/查看LVM磁盘状态-目前没

13、有任何LVM磁盘信息lvm lvmdiskscan /dev/sda1 1.10 GB /dev/root 98.90 GB /dev/sdb1 100.00 GB 1 disk 2 partitions 0 LVM physical volume whole disks 0 LVM physical volumes/查看LVM的配置文件lvm dumpconfig devices dir=/dev scan=/dev filter=r|/dev/.*/by-path/.*|, r|/dev/.*/by-id/.*|, a/.*/ cache=/etc/lvm/.cache write_cac

14、he_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 gl

15、obal 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= /创立P

16、Vlvm pvcreate /dev/sdb1 No physical volume label read from /dev/sdb1 Physical volume /dev/sdb1 successfully created/查看PV状态lvm pvdisplay /dev/sdb1 is a new physical volume of 100.00 GB - NEW Physical volume - PV Name /dev/sdb1 VG Name PV Size 100.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free

17、 PE 0 Allocated PE 0 PV UUID 7daSq9-7KXU-Lvil-SUHc-ELrI-fyX7-FM9Bfy /再次查看LVM磁盘状态lvm lvmdiskscan /dev/sda1 1.10 GB /dev/root 98.90 GB /dev/sdb1 100.00 GB LVM physical volume 1 disk 1 partition 0 LVM physical volume whole disks 1 LVM physical volume/创立VGlvm vgcreate vg_test /dev/sdb1 Volume group vg_t

18、est successfully created/查看VG状态lvm vgdisplay - Volume group - VG Name vg_test 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 100.00 GB PE Size 4.00 MB Total PE 25599 Alloc PE / Size

19、 0 / 0 Free PE / Size 25599 / 100.00 GB VG UUID oSUogC-mV2F-b7Dg-5sFa-tztZ-NDh4-fpL6zu /查看所有VGlvm vgs VG #PV #LV #SN Attr VSize VFree vg_test 1 0 0 wz-n- 100.00G 100.00G/创立LVlvm lvcreate -size 10G -name lvm_u1 vg_test Logical volume lvm_u1 created/查看LV状态lvm lvs LV VG Attr LSize Origin Snap% Move Log

20、 Copy% Convert lvm_u1 vg_test -wi-a- 10.00G lvm vgs VG #PV #LV #SN Attr VSize VFree vg_test 1 1 0 wz-n- 100.00G 90.00G/退出LVM配置模式lvm exit Exiting./ext3格式化逻辑卷(none):/home/liuzq/Desktop # mkfs -t ext3 -j /dev/vg_test/lvm_u1 mke2fs 1.41.1 (01-Sep-2022)Filesystem label=OS type: LinuxBlock size=4096 (log=

21、2)Fragment size=4096 (log=2)655360 inodes, 2621440 blocks131072 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=268435456080 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 1638

22、40, 229376, 294912, 819200, 884736, 1605632Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 26 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.

23、/使用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/Filesystem 1M-blocks Used Available Use% Mounted on/dev/mapper/vg_test-lvm_u1 10080 151 9417 2% /mnt/u1(none):/home/liuzq/Deskt

24、op # ls /mnt/u1/lost+found(none):/home/liuzq/Desktop # ll /boot/total 14056-rw- 1 root root 512 2022-12-20 09:15 backup_mbrlrwxrwxrwx 1 root root 1 2022-12-20 09:00 boot - .-rw-r-r- 1 root root 1236 2022-02-24 06:40 boot.readmedrwxr-xr-x 2 root root 568 2022-12-20 09:15 grub-rw-r-r- 1 root root 4352

25、00 2022-12-20 09:15 message/在新建文件系统里复制一个大文件例如在/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 (none):/home/liuzq/Desktop # ll /mnt/u1/total 2956dr

26、wx- 2 root root 16384 2022-01-05 01:43 lost+found-rw-r-r- 1 root root 3004323 2022-01-05 01:51 /扩大LVM卷假定空间不够用准备向LVM卷增加更多空间。首先卸载该卷并使用lvresize命令调整卷大小。然后还必须用e2fsck检查整个文件系统并运行resize2fs调整该卷上ext3文件系统的大小/卸载(none):/home/liuzq/Desktop # umount /mnt/u1/调整卷大小(none):/home/liuzq/Desktop # lvresize -size 20G /dev

27、/vg_test/lvm_u1 Extending logical volume lvm_u1 to 20.00 GB Logical volume lvm_u1 successfully resized/检查文件系统(none):/home/liuzq/Desktop # e2fsck -f /dev/vg_test/lvm_u1 e2fsck 1.41.1 (01-Sep-2022)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory

28、connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/vg_test/lvm_u1: 12/655360 files (0.0% non-contiguous), 80431/2621440 blocks/调整文件系统大小(none):/home/liuzq/Desktop # resize2fs /dev/vg_test/lvm_u1 20Gresize2fs 1.41.1 (01-Sep-2022)Resizing the filesystem on /dev/

29、vg_test/lvm_u1 to 5242880 (4k) blocks.The filesystem on /dev/vg_test/lvm_u1 is now 5242880 blocks long.在上面的例子中卷和文件系统的大小都调整为20G。下面重新挂载卷检查磁盘空间和之前计算的md5sum/重新挂载(none):/home/liuzq/Desktop # mount /dev/vg_test/lvm_u1 /mnt/u1(none):/home/liuzq/Desktop # df -m /mnt/u1/Filesystem 1M-blocks Used Available Us

30、e% Mounted on/dev/mapper/vg_test-lvm_u1 20229 159 18977 1% /mnt/u1(none):/home/liuzq/Desktop # ll /mnt/u1/total 2956drwx- 2 root root 16384 2022-01-05 01:43 lost+found(none):/home/liuzq/Desktop # md5sum /mnt/u1/vmlinux-2.6.27.19-5-default.gz (none):/home/liuzq/Desktop # lvmlvm lvs LV VG Attr LSize O

31、rigin Snap% Move Log Copy% Convert lvm_u1 vg_test -wi-ao 20.00G lvm vgs VG #PV #LV #SN Attr VSize VFree vg_test 1 1 0 wz-n- 100.00G 80.00Glvm lvdisplay - Logical volume - LV Name /dev/vg_test/lvm_u1 VG Name vg_test LV UUID hO9SlO-6t9u-nHfE-tm0V-SQPC-827D-1EksZT LV Write Access read/write LV Status a

32、vailable # open 1 LV Size 20.00 GB Current LE 5120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 lvm exit Exiting.(none):/home/liuzq/Desktop # (none):/home/liuzq/Desktop # lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lvm_u1 vg_test -wi-ao

33、 20.00G 缩小LVM卷 缩减现有LVM卷里不需要的空间时也可以使用lvresize。和前面一样在调整卷大小之前先卸载这个卷然后运行e2fsck检查文件系统和resize2fs调整成较小尺寸 (none):/home/liuzq/Desktop # umount /mnt/u1/(none):/home/liuzq/Desktop # e2fsck -f /dev/vg_test/lvm_u1 e2fsck 1.41.1 (01-Sep-2022)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory str

34、ucturePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/vg_test/lvm_u1: 12/1310720 files (0.0% non-contiguous), 122833/5242880 blocks(none):/home/liuzq/Desktop # resize2fs /dev/vg_test/lvm_u1 15Gresize2fs 1.41.1 (01-Sep-2022)Resizing the filesystem on /dev/vg_test/lvm_u1 to 3932160 (4k) blocks.The filesystem on /dev/vg_test/lvm_u1 is now 3932160 blocks long.(none):/home/liuzq/Desktop # lvresize -size 15G /dev/vg_test/lvm_u1 WARNING: Reducing active logical volume to 15.00

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论