redhat6.2上做LVM
1 先给虚拟机上的RH加一个硬盘。2 启动RH3 在终端上输入[BeiGang@localhost~]$fdisk -lDisk /dev/sdc: 1073 MB, 1073741824 bytes……Disk /dev/sdc doesn't contain a valid partition table4分区1[BeiGang@localhost~]$fdisk /dev/sdcCommand (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-130, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +100MCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[BeiGang@localhost~]$5查看[BeiGang@localhost~]$fdisk -lDevice Boot Start End Blocks Id System/dev/sdc1 1 14 112423+ 83 Linux6分区2[BeiGang@localhost~]$fdisk /dev/sdcnp215+100Mw7查看[BeiGang@localhost~]$fdisk -lDevice Boot Start End Blocks Id System/dev/sdc1 1 14 112423+ 83 Linux/dev/sdc2 15 28 112455 83 Linux8添加物理卷[BeiGang@localhost~]$pvcreate /dev/sdc1Writing physical volume data to disk "/dev/sdc1"Physical volume "/dev/sdc1" successfully created[BeiGang@localhost~]$pvcreate /dev/sdc2Writing physical volume data to disk "/dev/sdc2"Physical volume "/dev/sdc2" successfully created[BeiGang@localhost~]$9查看PV[BeiGang@localhost~]$pvsPV VG Fmt Attr PSize PFree /dev/sdc1 lvm2 a-- 109.79m 109.79m/dev/sdc2 lvm2 a-- 109.82m 109.82m[BeiGang@localhost~]$10创建卷组[BeiGang@localhost~]$vgcreate VG1 /dev/sdc1 /dev/sdc2Volume group "VG1" successfully created[BeiGang@localhost~]$11查看卷组[BeiGang@localhost~]$vgsVG #PV #LV #SN Attr VSize VFree VG1 2 0 0 wz--n- 216.00m 216.00m[BeiGang@localhost~]$ 12创建逻辑卷1[BeiGang@localhost~]$lvcreate -n lv1 -L +50M VG1Rounding up size to full physical extent 52.00 MiBLogical volume "lv1" created[BeiGang@localhost~]$13创建逻辑卷2,因为是PE(4M)的整数倍,所以没有上调[BeiGang@localhost~]$lvcreate -n lv2 -L +60M VG1Logical volume "lv2" created[BeiGang@localhost~]$14查看逻辑卷[BeiGang@localhost~]$lvsLV VG Attr LSize Origin Snap% Move Log Copy% Convertlv1 VG1 -wi-a- 52.00m lv2 VG1 -wi-a- 60.00m [BeiGang@localhost~]$15格式化lv1时报找不到该文件,[BeiGang@localhost~]$mkfs.ext3 /dev/VG1/lv116挂载lv1[BeiGang@localhost~]$mount /dev/VG1/lv1 /seconddisk/17在文件夹seconddisk上生成文件[BeiGang@localhost~]$touch /seconddisk/{1..9}.txt[BeiGang@localhost~]$ll /seconddisk/total 23-rw-r--r--. 1 root root 0 Nov 8 14:06 1.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 2.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 3.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 4.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 5.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 6.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 7.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 8.txt-rw-r--r--. 1 root root 0 Nov 8 14:06 9.txtdrwx------. 2 root root 12288 Nov 8 13:51 lost+found[BeiGang@localhost~]$http://www.fpzhuhai.com/content/20130203/6682.do;
18
删除/dev/VG1/lv1,/dev/VG1/lv2[BeiGang@localhost~]$lvremove /dev/VG1/lv1Can't remove open logical volume "lv1"[BeiGang@localhost~]$umount /seconddisk/[BeiGang@localhost~]$lvremove /dev/VG1/lv1Do you really want to remove active logical volume lv1? [y/n]: yLogical volume "lv1" successfully removed[BeiGang@localhost~]$ [BeiGang@localhost~]$lvremove /dev/VG1/lv2Do you really want to remove active logical volume lv2? [y/n]: yLogical volume "lv2" successfully removedhttp://www.fpshijiazhuang.com/content/20130203/6680.do;
19删除/dev/VG1[BeiGang@localhost~]$vgremove /dev/VG1Volume group "VG1" successfully removed[BeiGang@localhost~]$
http://www.fpzhangsha.com/content/20130203/6681.do;
20删除物理卷[BeiGang@localhost~]$pvremove /dev/sdc3Labels on physical volume "/dev/sdc3" successfully wiped[BeiGang@localhost~]$pvremove /dev/sdc2Labels on physical volume "/dev/sdc2" successfully wiped[BeiGang@localhost~]$pvremove /dev/sdc1Labels on physical volume "/dev/sdc1" successfully wiped[BeiGang@localhost~]$值得说的一点是在做LVM时,文件类型不必是8e,83也可,具体见下面的Id。[BeiGang@localhost~]$fdisk -lDevice Boot Start End Blocks Id System/dev/sdc1 1 14 112423+ 83 Linux/dev/sdc2 15 28 112455 83 Linux=========================================================下面再在上面第17步完成后的基础上再对lv2做一个扩展。1首先fdisk搞一个/dev/sdc3查看:[BeiGang@localhost~]$ fdisk -l | grep /sdb/dev/sdc1 1 14 112423+ 83 Linux/dev/sdc2 15 28 112455 83 Linux/dev/sdc3 29 42 112455 83 Linux2增加pv失败[BeiGang@localhost~]$ pvcreate /dev/sdc3Device /dev/sdc3 not found (or ignored by filtering).3加载disc partation:[BeiGang@localhost~]$ partx -a /dev/sdcBLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2[BeiGang@localhost~]$ partx -a /dev/sdcBLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2BLKPG: Device or resource busyerror adding partition 34增加pv:[BeiGang@localhost~]$ pvcreate /dev/sdc3Writing physical volume data to disk "/dev/sdc3"Physical volume "/dev/sdc3" successfully created5扩展sdb3到vg:[BeiGang@localhost~]$ vgextend /dev/VG1 /dev/sdc3Volume group "VG1" successfully extended[BeiGang@localhost~]$ 6查看VG:[BeiGang@localhost~]$ vgsVG #PV #LV #SN Attr VSize VFree VG1 3 1 0 wz--n- 324.00m 272.00mVolGroup 1 2 0 wz--n- 19.51g 0 查看LV:[BeiGang@localhost~]$ lvsLV VG Attr LSize Origin Snap% Move Log Copy% Convertlv2 VG1 -wi-a- 52.00m 7扩展lv[BeiGang@localhost~]$ lvextend -L +50M /dev/VG1/lv2 Rounding up size to full physical extent 52.00 MiBExtending logical volume lv2 to 104.00 MiBLogical volume lv2 successfully resized[BeiGang@localhost~]$ 8查看:[BeiGang@localhost~]$ lvsLV VG Attr LSize Origin Snap% Move Log Copy% Convertlv2 VG1 -wi-a- 104.00m 9挂载再查看,lv2只有51M,刚才扩展的还没有真正加上[BeiGang@localhost~]$ mount /dev/VG1/lv2 /mnt[BeiGang@localhost~]$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VG1-lv251M 4.9M 43M 11% /mnt[BeiGang@localhost~]$ 10再resize一下:[BeiGang@localhost~]$ resize2fs /dev/VG1/lv2 11再df查看:[BeiGang@localhost~]$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VG2-lv2 101M 5.3M 91M 6% /mnt[BeiGang@localhost~]$