centos6 使用raid5构建lvm逻辑卷

前端之家收集整理的这篇文章主要介绍了centos6 使用raid5构建lvm逻辑卷前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、将之前实验环境还原:

a、利用umount先卸载之前挂载的文件系统;

b、修改/etc/fstab里面的数据,让开机不会自动挂载;

c、利用fdisk将该分区删除

整合raid5和lvm实验
实验环境:
一块6G的盘,分成5个分区,每个分区1G。

其中4个作为active态,一个为spare态。

fdisk -l

开始磁盘分区:

Disk /dev/sdd: 6442 MB,6442450944 bytes
255 heads,63 sectors/track,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@srcxtts ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table,nor Sun,SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x95cc4770.
Changes will remain in memory only,until you decide to write them.
After that,of course,the prevIoUs content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sdd: 6442 MB,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-783,default 1): 
Using default value 1
Last cylinder,+cylinders or +size{K,M,G} (1-783,default 783): +1G

Command (m for help): p

Disk /dev/sdd: 6442 MB,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-783,default 133): 
Using default value 133
Last cylinder,G} (133-783,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux
/dev/sdd2             133         264     1060290   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (265-783,default 265): 
Using default value 265
Last cylinder,G} (265-783,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux
/dev/sdd2             133         264     1060290   83  Linux
/dev/sdd3             265         396     1060290   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (397-783,default 397): 
Using default value 397
Last cylinder,G} (397-783,default 783): 
Using default value 783

Command (m for help): p

Disk /dev/sdd: 6442 MB,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux
/dev/sdd2             133         264     1060290   83  Linux
/dev/sdd3             265         396     1060290   83  Linux
/dev/sdd4             397         783     3108577+   5  Extended

Command (m for help): n
First cylinder (397-783,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux
/dev/sdd2             133         264     1060290   83  Linux
/dev/sdd3             265         396     1060290   83  Linux
/dev/sdd4             397         783     3108577+   5  Extended
/dev/sdd5             397         528     1060258+  83  Linux

Command (m for help): n
First cylinder (529-783,default 529): 
Using default value 529
Last cylinder,G} (529-783,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux
/dev/sdd2             133         264     1060290   83  Linux
/dev/sdd3             265         396     1060290   83  Linux
/dev/sdd4             397         783     3108577+   5  Extended
/dev/sdd5             397         528     1060258+  83  Linux
/dev/sdd6             529         660     1060258+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

2、创建raid5磁盘

[root@srcxtts ~]# mdadm --create --auto=yes /dev/md0 --level=5 \
> --raid-devices=4 --spare-devices=1 /dev/sdd{1,2,3,5,6}
mdadm: Defaulting to version 1.2 Metadata
mdadm: array /dev/md0 started.
[root@srcxtts ~]# ll /dev/md0
brw-rw----. 1 root disk 9,0 5月  10 09:26 /dev/md0
[root@srcxtts ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd5[5] sdd6[4](S) sdd3[2] sdd2[1] sdd1[0]
      3176448 blocks super 1.2 level 5,512k chunk,algorithm 2 [4/4] [UUUU]
      
unused devices: <none>

3、对raid5磁盘/dev/md0创建pv

[root@srcxtts ~]# pvcreate /dev/md0
  Physical volume "/dev/md0" successfully created
[root@srcxtts ~]# pvdisplay /dev/md0
  "/dev/md0" is a new physical volume of "3.03 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/md0
  VG Name               
  PV Size               3.03 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               GjGVBh-z3h6-uyD0-xNjQ-LflN-j1gb-XvR4I7

4、根据生成的pv创建vg,参数默认,pe大小默认4M

[root@srcxtts ~]# vgcreate raidvg /dev/md0
  Volume group "raidvg" successfully created
[root@srcxtts ~]# vgdisplay raidvg
  --- Volume group ---
  VG Name               raidvg
  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               3.03 GiB
  PE Size               4.00 MiB
  Total PE              775
  Alloc PE / Size       0 / 0   
  Free  PE / Size       775 / 3.03 GiB
  VG UUID               Jx2ZNz-juP4-g8fx-oPJ5-F3Mg-QYn4-WoZ5HO

5、把vg中全部的pe都分配给lv,创建lv

[root@srcxtts ~]# lvcreate -l 775 -n raidlv raidvg
  Logical volume "raidlv" created
[root@srcxtts ~]# lvscan
  ACTIVE            '/dev/vg_srcxtts/lv_root' [21.58 GiB] inherit
  ACTIVE            '/dev/vg_srcxtts/lv_swap' [3.94 GiB] inherit
  ACTIVE            '/dev/raidvg/raidlv' [3.03 GiB] inherit
[root@srcxtts ~]# lvdisplay /dev/raidvg/raidlv
  --- Logical volume ---
  LV Path                /dev/raidvg/raidlv
  LV Name                raidlv
  VG Name                raidvg
  LV UUID                rOaylO-3Br7-sUo3-3IRZ-Rf4D-O5V8-A98KGh
  LV Write Access        read/write
  LV Creation host,time srcxtts,2018-05-10 09:29:36 +0800
  LV Status              available
  # open                 0
  LV Size                3.03 GiB
  Current LE             775
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     6144
  Block device           253:2

6、将lv格式化为ext3文件系统

[root@srcxtts ~]# mkfs.ext3 /dev/raidvg/raidlv
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=128 blocks,Stripe width=384 blocks
198400 inodes,793600 blocks
39680 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=813694976
25 block groups
32768 blocks per group,32768 fragments per group
7936 inodes per group
Superblock backups stored on blocks: 
	32768,98304,163840,229376,294912

正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 33 mounts or
180 days,whichever comes first.  Use tune2fs -c or -i to override.

7、创建挂载点并挂载lv

[root@srcxtts ~]# mkdir /mnt/raidlvm
[root@srcxtts ~]# mount /dev/raidvg/raidlv /mnt/raidlvm
[root@srcxtts ~]# df -h
文件系统	      容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_srcxtts-lv_root
                       22G   11G  9.4G  54% /
tmpfs                 2.0G   84K  2.0G   1% /dev/shm
/dev/sda1             477M   60M  392M  14% /boot
/dev/mapper/raidvg-raidlv
                      3.0G   69M  2.8G   3% /mnt/raidlvm
[root@srcxtts ~]#

到此整合就完成了。

实验还原:

1、卸载lv文件系统

[root@srcxtts ~]# umount /mnt/raidlvm
[root@srcxtts ~]# df -h
文件系统	      容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_srcxtts-lv_root
                       22G   11G  9.4G  54% /
tmpfs                 2.0G   84K  2.0G   1% /dev/shm
/dev/sda1             477M   60M  392M  14% /boot

2、移除lv

[root@srcxtts ~]# lvremove /dev/raidvg/raidlv
Do you really want to remove active logical volume raidlv? [y/n]: y
  Logical volume "raidlv" successfully removed

3、改变vg的状态为非active

[root@srcxtts ~]# vgchange -an raidvg
  0 logical volume(s) in volume group "raidvg" now active

4、移除vg

[root@srcxtts ~]# vgremove raidvg
  Volume group "raidvg" successfully removed

5、移除pv

[root@srcxtts ~]# pvremove /dev/md0
  Labels on physical volume "/dev/md0" successfully wiped

6、停md0 raid磁盘

[root@srcxtts ~]# mdadm --stop /dev/md0
mdadm: stopped /dev/md0

7、使用fdisk将磁盘还原

[root@srcxtts ~]# fdisk /dev/sdd

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sdd: 6442 MB,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         132     1060258+  83  Linux
/dev/sdd2             133         264     1060290   83  Linux
/dev/sdd3             265         396     1060290   83  Linux
/dev/sdd4             397         783     3108577+   5  Extended
/dev/sdd5             397         528     1060258+  83  Linux
/dev/sdd6             529         660     1060258+  83  Linux

Command (m for help): d
Partition number (1-6): 1

Command (m for help): d
Partition number (1-6): 2

Command (m for help): d
Partition number (1-6): 3

Command (m for help): d
Partition number (1-6): 4

Command (m for help): d
No partition is defined yet!

Command (m for help): 5
5: unknown command
Command 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 changes
   s   create a new empty Sun disklabel
   t   change a partition's 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): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@srcxtts ~]# fdisk /dev/sdd

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): q

[root@srcxtts ~]# fdisk /dev/sdd -l

Disk /dev/sdd: 6442 MB,783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x95cc4770

   Device Boot      Start         End      Blocks   Id  System
[root@srcxtts ~]#
原文链接:https://www.f2er.com/centos/374359.html

猜你在找的CentOS相关文章