LINUX LVM和快照卷配置和管理
具体参考这个文章把: http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_042_lvm.html
1.LVM是什么
逻辑卷管理LVM是一个多才多艺的硬盘系统工具。无论在Linux或者其他类似的系统,都是非常的好用。传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据。可以随意将新的硬盘添加到LVM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。
2准备磁盘分区
2.1添加2块磁盘
2.2给/dev/sdb创建分区并调整类型为8e
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 2610. There 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 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +1G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (124-2610, default 124): Using default value 124 Last cylinder or +size or +sizeM or +sizeK (124-2610, default 2610): +1G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (247-2610, default 247): Using default value 247 Last cylinder or +size or +sizeM or +sizeK (247-2610, default 2610): +1G Command (m for help): p Disk /dev/sdb: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 123 987966 83 Linux /dev/sdb2 124 246 987997+ 83 Linux /dev/sdb3 247 369 987997+ 83 Linux Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): L 0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris 1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx 5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data 6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 123 987966 8e Linux LVM /dev/sdb2 124 246 987997+ 8e Linux LVM /dev/sdb3 247 369 987997+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks.
2.3同样给、dev/sdc创建分区并调整类型为8e
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 1305. There 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 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +1g Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (124-1305, default 124): Using default value 124 Last cylinder or +size or +sizeM or +sizeK (124-1305, default 1305): +1g Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (247-1305, default 247): Using default value 247 Last cylinder or +size or +sizeM or +sizeK (247-1305, default 1305): +1g Command (m for help): p Disk /dev/sdc: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 123 987966 83 Linux /dev/sdc2 124 246 987997+ 83 Linux /dev/sdc3 247 369 987997+ 83 Linux Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdc: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 123 987966 8e Linux LVM /dev/sdc2 124 246 987997+ 8e Linux LVM /dev/sdc3 247 369 987997+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks.
2.4查看上面2步骤的信息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 2610 20860402+ 8e Linux LVM Disk /dev/sdb: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 123 987966 8e Linux LVM /dev/sdb2 124 246 987997+ 8e Linux LVM /dev/sdb3 247 369 987997+ 8e Linux LVM Disk /dev/sdc: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 123 987966 8e Linux LVM /dev/sdc2 124 246 987997+ 8e Linux LVM /dev/sdc3 247 369 987997+ 8e Linux LVM
3.准备物理卷(PV)
3.1确保分区已经被系统识别
[root@localhost ~]# partprobe [root@localhost ~]# cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 104391 sda1 8 2 20860402 sda2 8 16 20971520 sdb 8 17 987966 sdb1 8 18 987997 sdb2 8 19 987997 sdb3 8 32 10485760 sdc 8 33 987966 sdc1 8 34 987997 sdc2 8 35 987997 sdc3 253 0 15728640 dm-0 253 1 5111808 dm-1
注:上面创建的6个分区都已经被系统读取到了。
3.2创建PV
[root@localhost ~]# pvcreate /dev/sdb{1,2,3} /dev/sdc{1,2,3} Writing physical volume data to disk "/dev/sdb1" Physical volume "/dev/sdb1" successfully created Writing physical volume data to disk "/dev/sdb2" Physical volume "/dev/sdb2" successfully created Writing physical volume data to disk "/dev/sdb3" Physical volume "/dev/sdb3" successfully created Writing physical volume data to disk "/dev/sdc1" Physical volume "/dev/sdc1" successfully created Writing physical volume data to disk "/dev/sdc2" Physical volume "/dev/sdc2" successfully created Writing physical volume data to disk "/dev/sdc3" Physical volume "/dev/sdc3" successfully created
3.3使用pvdisplay查看各个pv详细信息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 19.89 GB / not usable 19.49 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 636 Free PE 0 Allocated PE 636 PV UUID 0Z3ac4-OGzp-8Aop-Pz1t-KEtL-lgWk-iWjU5y "/dev/sdb1" is a new physical volume of "964.81 MB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 964.81 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID gd7wHw-e4Hx-Sq3R-Y1ls-8emn-LT57-jrgGc8 "/dev/sdb2" is a new physical volume of "964.84 MB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 964.84 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID J00YwU-AG77-lXDD-bZuf-jmni-5Mpj-0EOIGs "/dev/sdb3" is a new physical volume of "964.84 MB" --- NEW Physical volume --- PV Name /dev/sdb3 VG Name PV Size 964.84 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID BcPaAb-kyr1-uzMC-VV1D-M2Rr-mFh0-k7qD4L "/dev/sdc1" is a new physical volume of "964.81 MB" --- NEW Physical volume --- PV Name /dev/sdc1 VG Name PV Size 964.81 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 7pxh1W-9bXB-VFyi-Ccwn-ol7z-tkbW-xyW1js "/dev/sdc2" is a new physical volume of "964.84 MB" --- NEW Physical volume --- PV Name /dev/sdc2 VG Name PV Size 964.84 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID mN7ZbA-XZtH-V0lq-TDSO-jcXW-W3yt-bIaTIy "/dev/sdc3" is a new physical volume of "964.84 MB" --- NEW Physical volume --- PV Name /dev/sdc3 VG Name PV Size 964.84 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID PuBFaL-En9g-vlFh-Zn2F-0NYZ-OgbH-78lHf9
3.4 删除pv
[root@localhost ~]# pvremove /dev/sdb1 #删除创建好的pv Labels on physical volume "/dev/sdb1" successfully wiped [root@localhost ~]# pvcreate /dev/sdb1 #为了后续的实验,这里创建创建一次 Writing physical volume data to disk "/dev/sdb1" Physical volume "/dev/sdb1" successfully created
4 准备卷组(VG)
4.1创建vg
[root@localhost ~]# vgcreate vg-zhaojiedi /dev/sdb{1,2} /dev/sdc{1,2} Volume group "vg-zhaojiedi" successfully created
4.2查看vg信息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost ~]# vgdisplay --- Volume group --- VG Name vg-zhaojiedi System ID Format lvm2 Metadata Areas 4 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 4 Act PV 4 VG Size 3.77 GB PE Size 4.00 MB Total PE 964 Alloc PE / Size 0 / 0 Free PE / Size 964 / 3.77 GB VG UUID tLoxsN-ZISg-Ebdf-7OIk-i5gz-73iN-RWjtoU --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.88 GB PE Size 32.00 MB Total PE 636 Alloc PE / Size 636 / 19.88 GB Free PE / Size 0 / 0 VG UUID pL0fvM-64mT-Vu4Y-2hUA-hyvj-FHMK-NF2t5m
4.3删除vg
[root@localhost ~]# vgremove vg-zhaojiedi #删除vg Volume group "vg-zhaojiedi" successfully removed [root@localhost ~]# vgcreate vg-zhaojiedi /dev/sdb{1,2} /dev/sdc{1,2} #再次创建,用于后续测试 Volume group "vg-zhaojiedi" successfully created
5.创建逻辑卷(LV)
5.1创建逻辑卷
[root@localhost ~]# lvcreate -L 1G -n lv-zhaojiedi vg-zhaojiedi Logical volume "lv-zhaojiedi" created
- -L:指定逻辑卷的大小
- -n:指定逻辑卷的名字
5.2 查看逻辑卷
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost ~]# lvdisplay --- Logical volume --- LV Name /dev/vg-zhaojiedi/lv-zhaojiedi VG Name vg-zhaojiedi LV UUID qyvrpi-TV4Q-1U3h-0UXJ-6c8N-bds5-kapP11 LV Write Access read/write LV Status available # open 0 LV Size 1.00 GB Current LE 256 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Name /dev/VolGroup00/LogVol00 VG Name VolGroup00 LV UUID YQ5wpv-9bjK-WAOG-03lr-dsHD-hMBJ-Wcj22F LV Write Access read/write LV Status available # open 1 LV Size 15.00 GB Current LE 480 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/LogVol01 VG Name VolGroup00 LV UUID h2xJcZ-Aszi-u2aa-Mi5i-U8cP-R6V2-5KrI2H LV Write Access read/write LV Status available # open 1 LV Size 4.88 GB Current LE 156 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
5.3 挂载逻辑卷
[root@localhost ~]# mkfs.ext3 /dev/vg-zhaojiedi/lv-zhaojiedi #格式化文件系统 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 131072 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# mkdir /mnt/lvm #创建挂载点目录 [root@localhost ~]# mount /dev/vg-zhaojiedi/lv-zhaojiedi /mnt/lvm #挂载
5.4删除逻辑卷
[root@localhost ~]# umount /dev/vg-zhaojiedi/lv-zhaojiedi #先卸载 [root@localhost ~]# lvremove /dev/vg-zhaojiedi/lv-zhaojiedi #在移除 Do you really want to remove active logical volume lv-zhaojiedi? [y/n]: y Logical volume "lv-zhaojiedi" successfully removed [root@localhost ~]# lvcreate -L 1G -n lv-zhaojiedi vg-zhaojiedi #这里为了接下来的测试,重新创建 Logical volume "lv-zhaojiedi" created [root@localhost ~]# mount /dev/vg-zhaojiedi/lv-zhaojiedi /mnt/lvm #重新挂载 mount: you must specify the filesystem type
6扩展一个逻辑卷
6.1 卸载逻辑卷
[root@localhost ~]# umount /dev/vg-zhaojiedi/lv-zhaojiedi
6.2查看vg,lv空间情况
[root@localhost ~]# lvdisplay /dev/vg-zhaojiedi/lv-zhaojiedi --- Logical volume --- LV Name /dev/vg-zhaojiedi/lv-zhaojiedi VG Name vg-zhaojiedi LV UUID x1Oru1-0khT-xbmW-qk0R-lVEW-UIGf-bakDcl LV Write Access read/write LV Status available # open 0 LV Size 1.00 GB Current LE 256 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 [root@localhost ~]# vgdisplay vg-zhaojiedi --- Volume group --- VG Name vg-zhaojiedi System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size 3.77 GB PE Size 4.00 MB Total PE 964 Alloc PE / Size 256 / 1.00 GB Free PE / Size 708 / 2.77 GB VG UUID pp8kaf-FQH6-kFfj-kxmb-OrfU-K5IE-34QjNR
注: 从上图中可以发现, 我们的vg是4G的, lv的空间是1G的, 还有3G可用的空间
6.3 我们扩容的大小还在vg的空间范围内的话
[root@localhost ~]# lvextend -L +1G /dev/vg-zhaojiedi/lv-zhaojiedi #扩展1G Extending logical volume lv-zhaojiedi to 2.00 GB Logical volume lv-zhaojiedi successfully resized [root@localhost ~]# resize2fs /dev/vg-zhaojiedi/lv-zhaojiedi #重新定义文件大小 resize2fs 1.39 (29-May-2006) resize2fs: Bad magic number in super-block while trying to open /dev/vg-zhaojiedi/lv-zhaojiedi Couldn't find valid filesystem superblock. [root@localhost ~]# e2fsck -f /dev/vg-zhaojiedi/lv-zhaojiedi #检查磁盘错误 e2fsck 1.39 (29-May-2006) Couldn't find ext2 superblock, trying backup blocks... Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg-zhaojiedi/lv-zhaojiedi: ***** FILE SYSTEM WAS MODIFIED ***** /dev/vg-zhaojiedi/lv-zhaojiedi: 11/131072 files (9.1% non-contiguous), 12645/262144 blocks [root@localhost ~]# resize2fs /dev/vg-zhaojiedi/lv-zhaojiedi #重新定义文件系统大小 resize2fs 1.39 (29-May-2006) Resizing the filesystem on /dev/vg-zhaojiedi/lv-zhaojiedi to 524288 (4k) blocks. The filesystem on /dev/vg-zhaojiedi/lv-zhaojiedi is now 524288 blocks long.
6.4卷组的大小不够我们扩容的需求的话
上面我们已经扩容1G,逻辑卷就是2G的带下了。 vg的大小是4G,如果我们还要扩容3G的话, VG的大小是不够的。
[root@localhost ~]# vgextend vg-zhaojiedi /dev/sdb3 /dev/sdc3 #上面创建的那个pv没有使用呢。 这里添加到vg中,扩展vg Volume group "vg-zhaojiedi" successfully extended [root@localhost ~]# vgdisplay #查看vg --- Volume group --- VG Name vg-zhaojiedi System ID Format lvm2 Metadata Areas 6 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 6 Act PV 6 VG Size 5.65 GB PE Size 4.00 MB Total PE 1446 Alloc PE / Size 512 / 2.00 GB Free PE / Size 934 / 3.65 GB VG UUID pp8kaf-FQH6-kFfj-kxmb-OrfU-K5IE-34QjNR --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.88 GB PE Size 32.00 MB Total PE 636 Alloc PE / Size 636 / 19.88 GB Free PE / Size 0 / 0 VG UUID pL0fvM-64mT-Vu4Y-2hUA-hyvj-FHMK-NF2t5m [root@localhost ~]# lvextend -L +3G /dev/vg-zhaojiedi/lv-zhaojiedi #扩展lv Extending logical volume lv-zhaojiedi to 5.00 GB Logical volume lv-zhaojiedi successfully resized [root@localhost ~]# resize2fs /dev/vg-zhaojiedi/lv-zhaojiedi #文件系统大小 resize2fs 1.39 (29-May-2006) Resizing the filesystem on /dev/vg-zhaojiedi/lv-zhaojiedi to 1310720 (4k) blocks. The filesystem on /dev/vg-zhaojiedi/lv-zhaojiedi is now 1310720 blocks long.
7缩减逻辑卷
[root@localhost ~]# mount /dev/vg-zhaojiedi/lv-zhaojiedi /mnt/lvm #挂载 [root@localhost ~]# df -lh #查看使用情况 Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 15G 5.2G 8.6G 38% / /dev/sda1 99M 13M 82M 13% /boot tmpfs 252M 0 252M 0% /dev/shm /dev/mapper/vg--zhaojiedi-lv--zhaojiedi 5.0G 35M 4.7G 1% /mnt/lvm [root@localhost ~]# umount /mnt/lvm #卸载 [root@localhost ~]# resize2fs /dev/vg-zhaojiedi/lv-zhaojiedi 2G resize2fs 1.39 (29-May-2006) Please run 'e2fsck -f /dev/vg-zhaojiedi/lv-zhaojiedi' first. [root@localhost ~]# e2fsck -f /dev/vg-zhaojiedi/lv-zhaojiedi #检查 e2fsck 1.39 (29-May-2006) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg-zhaojiedi/lv-zhaojiedi: 11/655360 files (9.1% non-contiguous), 29288/1310720 blocks [root@localhost ~]# resize2fs /dev/vg-zhaojiedi/lv-zhaojiedi 2G resize2fs 1.39 (29-May-2006) Resizing the filesystem on /dev/vg-zhaojiedi/lv-zhaojiedi to 524288 (4k) blocks. The filesystem on /dev/vg-zhaojiedi/lv-zhaojiedi is now 524288 blocks long. [root@localhost ~]# lvreduce -L 2G /dev/vg-zhaojiedi/lv-zhaojiedi #减少到2G,注意减少逻辑卷的大小值若小于储存的数据大小,存储在后面的数据会丢失。 WARNING: Reducing active logical volume to 2.00 GB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv-zhaojiedi? [y/n]: y Reducing logical volume lv-zhaojiedi to 2.00 GB Logical volume lv-zhaojiedi successfully resized
8 创建快照卷
#下面我们在/mnt/lvm目录挂载逻辑卷,在/mnt/lvm-snap目录挂载快照卷,然后需要lvm目录的文件, 在查看lvm目录的文件和lvm-snap的文件。
[root@localhost cron]# mount /dev/vg-zhaojiedi/lv-zhaojiedi /mnt/lvm #挂载逻辑卷
[root@localhost cron]# cd /mnt/lvm #进入挂载目录 [root@localhost lvm]# cp /etc/fstab . #copy一些文件进入逻辑卷挂载目录 [root@localhost lvm]# cp /etc/sysctl.conf . [root@localhost lvm]# ls fstab lost+found sysctl.conf [root@localhost lvm]# mkdir /mnt/lvm-snap #提前创建快照卷挂载目录 [root@localhost lvm]# lvcreate -L 100M -s -n "lvm-snap" /dev/vg-zhaojiedi/lv-zhaojiedi #创建快照卷 Logical volume "lvm-snap" created [root@localhost lvm]# mount /dev/vg-zhaojiedi/lvm-snap /mnt/lvm-snap/ #挂载快照卷 [root@localhost lvm]# ls ../lvm-snap/ #查看快照卷, 此时已经有文件显示出来了 fstab lost+found sysctl.conf [root@localhost lvm]# echo " hello " >> /mnt/lvm/fstab #修改lvm目录的文件内容 [root@localhost lvm]# cat /mnt/lvm/fstab #查看逻辑卷的内容 /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/VolGroup00/LogVol01 swap swap defaults 0 0 /dev/sdb1 /test/project ext3 rw 0 0 LABEL="MYDATA" /mnt/mydata ext3 rw 0 0 hello [root@localhost lvm]# cat /mnt/lvm-snap/fstab #查看快照卷的内容 /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/VolGroup00/LogVol01 swap swap defaults 0 0 /dev/sdb1 /test/project ext3 rw 0 0 LABEL="MYDATA" /mnt/mydata ext3 rw 0 0
posted on 2017-03-25 11:00 LinuxPanda 阅读(1068) 评论(0) 编辑 收藏 举报