centos6.x 使用raid5构建lvm逻辑卷
1、将之前实验环境还原: a、利用umount先卸载之前挂载的文件系统; b、修改/etc/fstab里面的数据,让开机不会自动挂载; c、利用fdisk将该分区删除; 整合raid5和lvm实验 实验环境: 一块6G的盘,分成5个分区,每个分区1G。 其中4个作为active态,一个为spare态。 fdisk -l 开始磁盘分区: [plain] view plain copy Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x00000000 [plain] view plain copy [root@srcxtts~]#fdisk/dev/sdd DevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabel BuildinganewDOSdisklabelwithdiskidentifier0x95cc4770. Changeswillremaininmemoryonly,untilyoudecidetowritethem. Afterthat,ofcourse,thepreviouscontentwon'tberecoverable. Warning:invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite) WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedto switchoffthemode(command'c')andchangedisplayunitsto sectors(command'u'). Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem Command(mforhelp):n Commandaction eextended pprimarypartition(1-4) p Partitionnumber(1-4):1 Firstcylinder(1-783,default1): Usingdefaultvalue1 Lastcylinder,+cylindersor+size{K,M,G}(1-783,default783):+1G Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux Command(mforhelp):n Commandaction eextended pprimarypartition(1-4) p Partitionnumber(1-4):2 Firstcylinder(133-783,default133): Usingdefaultvalue133 Lastcylinder,+cylindersor+size{K,M,G}(133-783,default783):+1G Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux /dev/sdd2133264106029083Linux Command(mforhelp):n Commandaction eextended pprimarypartition(1-4) p Partitionnumber(1-4):3 Firstcylinder(265-783,default265): Usingdefaultvalue265 Lastcylinder,+cylindersor+size{K,M,G}(265-783,default783):+1G Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux /dev/sdd2133264106029083Linux /dev/sdd3265396106029083Linux Command(mforhelp):n Commandaction eextended pprimarypartition(1-4) e Selectedpartition4 Firstcylinder(397-783,default397): Usingdefaultvalue397 Lastcylinder,+cylindersor+size{K,M,G}(397-783,default783): Usingdefaultvalue783 Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux /dev/sdd2133264106029083Linux /dev/sdd3265396106029083Linux /dev/sdd43977833108577+5Extended Command(mforhelp):n Firstcylinder(397-783,default397): Usingdefaultvalue397 Lastcylinder,+cylindersor+size{K,M,G}(397-783,default783):+1G Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux /dev/sdd2133264106029083Linux /dev/sdd3265396106029083Linux /dev/sdd43977833108577+5Extended /dev/sdd53975281060258+83Linux Command(mforhelp):n Firstcylinder(529-783,default529): Usingdefaultvalue529 Lastcylinder,+cylindersor+size{K,M,G}(529-783,default783):+1G Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux /dev/sdd2133264106029083Linux /dev/sdd3265396106029083Linux /dev/sdd43977833108577+5Extended /dev/sdd53975281060258+83Linux /dev/sdd65296601060258+83Linux Command(mforhelp):w Thepartitiontablehasbeenaltered! Callingioctl()tore-readpartitiontable. Syncingdisks. 2、创建raid5磁盘 [plain] view plain copy [root@srcxtts~]#mdadm--create--auto=yes/dev/md0--level=5\ >--raid-devices=4--spare-devices=1/dev/sdd{1,2,3,5,6} mdadm:Defaultingtoversion1.2metadata mdadm:array/dev/md0started. [root@srcxtts~]#ll/dev/md0 brw-rw----.1rootdisk9,05月1009:26/dev/md0 [root@srcxtts~]#cat/proc/mdstat Personalities:[raid6][raid5][raid4] md0:activeraid5sdd5[5]sdd6[4](S)sdd3[2]sdd2[1]sdd1[0] 3176448blockssuper1.2level5,512kchunk,algorithm2[4/4][UUUU] unuseddevices:<none> 3、对raid5磁盘/dev/md0创建pv [plain] view plain copy [root@srcxtts~]#pvcreate/dev/md0 Physicalvolume"/dev/md0"successfullycreated [root@srcxtts~]#pvdisplay/dev/md0 "/dev/md0"isanewphysicalvolumeof"3.03GiB" ---NEWPhysicalvolume--- PVName/dev/md0 VGName PVSize3.03GiB AllocatableNO PESize0 TotalPE0 FreePE0 AllocatedPE0 PVUUIDGjGVBh-z3h6-uyD0-xNjQ-LflN-j1gb-XvR4I7 4、根据生成的pv创建vg,参数默认,pe大小默认4M [plain] view plain copy [root@srcxtts~]#vgcreateraidvg/dev/md0 Volumegroup"raidvg"successfullycreated [plain] view plain copy [root@srcxtts~]#vgdisplayraidvg ---Volumegroup--- VGNameraidvg SystemID Formatlvm2 MetadataAreas1 MetadataSequenceNo1 VGAccessread/write VGStatusresizable MAXLV0 CurLV0 OpenLV0 MaxPV0 CurPV1 ActPV1 VGSize3.03GiB PESize4.00MiB TotalPE775 AllocPE/Size0/0 FreePE/Size775/3.03GiB VGUUIDJx2ZNz-juP4-g8fx-oPJ5-F3Mg-QYn4-WoZ5HO 5、把vg中全部的pe都分配给lv,创建lv [plain] view plain copy [root@srcxtts~]#lvcreate-l775-nraidlvraidvg Logicalvolume"raidlv"created [root@srcxtts~]#lvscan ACTIVE'/dev/vg_srcxtts/lv_root'[21.58GiB]inherit ACTIVE'/dev/vg_srcxtts/lv_swap'[3.94GiB]inherit ACTIVE'/dev/raidvg/raidlv'[3.03GiB]inherit [root@srcxtts~]#lvdisplay/dev/raidvg/raidlv ---Logicalvolume--- LVPath/dev/raidvg/raidlv LVNameraidlv VGNameraidvg LVUUIDrOaylO-3Br7-sUo3-3IRZ-Rf4D-O5V8-A98KGh LVWriteAccessread/write LVCreationhost,timesrcxtts,2018-05-1009:29:36+0800 LVStatusavailable #open0 LVSize3.03GiB CurrentLE775 Segments1 Allocationinherit Readaheadsectorsauto -currentlysetto6144 Blockdevice253:2 6、将lv格式化为ext3文件系统 [plain] view plain copy [root@srcxtts~]#mkfs.ext3/dev/raidvg/raidlv mke2fs1.41.12(17-May-2010) 文件系统标签= 操作系统:Linux 块大小=4096(log=2) 分块大小=4096(log=2) Stride=128blocks,Stripewidth=384blocks 198400inodes,793600blocks 39680blocks(5.00%)reservedforthesuperuser 第一个数据块=0 Maximumfilesystemblocks=813694976 25blockgroups 32768blockspergroup,32768fragmentspergroup 7936inodespergroup Superblockbackupsstoredonblocks: 32768,98304,163840,229376,294912 正在写入inode表:完成 Creatingjournal(16384blocks):完成 Writingsuperblocksandfilesystemaccountinginformation:完成 Thisfilesystemwillbeautomaticallycheckedevery33mountsor 180days,whichevercomesfirst.Usetune2fs-cor-itooverride. 7、创建挂载点并挂载lv [plain] view plain copy [root@srcxtts~]#mkdir/mnt/raidlvm [root@srcxtts~]#mount/dev/raidvg/raidlv/mnt/raidlvm [plain] view plain copy [root@srcxtts~]#df-h 文件系统容量已用可用已用%%挂载点 /dev/mapper/vg_srcxtts-lv_root 22G11G9.4G54%/ tmpfs2.0G84K2.0G1%/dev/shm /dev/sda1477M60M392M14%/boot /dev/mapper/raidvg-raidlv 3.0G69M2.8G3%/mnt/raidlvm [root@srcxtts~]# 到此整合就完成了。 实验还原: 1、卸载lv文件系统 [plain] view plain copy [root@srcxtts~]#umount/mnt/raidlvm [root@srcxtts~]#df-h 文件系统容量已用可用已用%%挂载点 /dev/mapper/vg_srcxtts-lv_root 22G11G9.4G54%/ tmpfs2.0G84K2.0G1%/dev/shm /dev/sda1477M60M392M14%/boot 2、移除lv [plain] view plain copy [root@srcxtts~]#lvremove/dev/raidvg/raidlv Doyoureallywanttoremoveactivelogicalvolumeraidlv?[y/n]:y Logicalvolume"raidlv"successfullyremoved 3、改变vg的状态为非active [plain] view plain copy [root@srcxtts~]#vgchange-anraidvg 0logicalvolume(s)involumegroup"raidvg"nowactive 4、移除vg [plain] view plain copy [root@srcxtts~]#vgremoveraidvg Volumegroup"raidvg"successfullyremoved 5、移除pv [plain] view plain copy [root@srcxtts~]#pvremove/dev/md0 Labelsonphysicalvolume"/dev/md0"successfullywiped 6、停md0 raid磁盘 [plain] view plain copy [root@srcxtts~]#mdadm--stop/dev/md0 mdadm:stopped/dev/md0 7、使用fdisk将磁盘还原 [plain] view plain copy [root@srcxtts~]#fdisk/dev/sdd WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedto switchoffthemode(command'c')andchangedisplayunitsto sectors(command'u'). Command(mforhelp):p Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem /dev/sdd111321060258+83Linux /dev/sdd2133264106029083Linux /dev/sdd3265396106029083Linux /dev/sdd43977833108577+5Extended /dev/sdd53975281060258+83Linux /dev/sdd65296601060258+83Linux Command(mforhelp):d Partitionnumber(1-6):1 Command(mforhelp):d Partitionnumber(1-6):2 Command(mforhelp):d Partitionnumber(1-6):3 Command(mforhelp):d Partitionnumber(1-6):4 Command(mforhelp):d Nopartitionisdefinedyet! Command(mforhelp):5 5:unknowncommand 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. [root@srcxtts~]#fdisk/dev/sdd WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedto switchoffthemode(command'c')andchangedisplayunitsto sectors(command'u'). Command(mforhelp):q [root@srcxtts~]#fdisk/dev/sdd-l Disk/dev/sdd:6442MB,6442450944bytes 255heads,63sectors/track,783cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x95cc4770 DeviceBootStartEndBlocksIdSystem [root@srcxtts~]#