如何在运行的LVM系统(包括GRUB配置)(Fedora 8)上设置软件RAID1)
版本1.0
作者:Falko Timme
本指南介绍如何在已经运行的LVM系统(Fedora 8)上设置软件RAID1。 GRUB引导加载程序将被配置为使得如果其中一个硬盘驱动器发生故障,系统仍然可以启动(无论哪一个)。
我不会保证这将为您工作!
1初步说明
在本教程中,我使用的Fedora 8系统有两个硬盘驱动器,即/ dev / sda
和/ dev / sdb
,大小相同。 / dev / sdb
当前未使用,并且/ dev / sda
具有以下分区(这是默认的Fedora分区方案 - 您应该在系统上找到类似的内容,除非您选择在系统安装期间手动分区):
-
/ dev / sda1
:/ boot
partition,ext3; -
/ dev / sda2
:用于LVM(卷组VolGroup00
),并包含/
(卷LogVol00
)和交换(卷LogVol01
)。
最后我想要有以下情况:
-
/ dev / md0
(由/ dev / sda1
和/ dev / sdb1组成
):/ boot
partition,ext3; -
/ dev / md1
(由/ dev / sda2
和/ dev / sdb2组成
):LVM(卷组VolGroup00
)包含/(卷LogVol00)
和交换(卷LogVol01
)。
这是现在的情况:
df -h
[root@server1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
4.1G 2.0G 2.0G 51% /
/dev/sda1 190M 13M 168M 7% /boot
tmpfs 151M 0 151M 0% /dev/shm
[root@server1 ~]#
fdisk -l
[root@server1 ~]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008b885
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 652 5036377+ 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/dm-0: 4462 MB, 4462739456 bytes
255 heads, 63 sectors/track, 542 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 637 MB, 637534208 bytes
255 heads, 63 sectors/track, 77 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x30307800
Disk /dev/dm-1 doesn't contain a valid partition table
[root@server1 ~]#
pvdisplay
[root@server1 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 4.80 GB / not usable 22.34 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 153
Free PE 1
Allocated PE 152
PV UUID op2n3N-rck1-Pywc-9wTY-EUxQ-KUcr-2YeRJ0
[root@server1 ~]#
vgdisplay
[root@server1 ~]# vgdisplay
--- 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 4.78 GB
PE Size 32.00 MB
Total PE 153
Alloc PE / Size 152 / 4.75 GB
Free PE / Size 1 / 32.00 MB
VG UUID jJj1DQ-SvKY-6hdr-3MMS-8NOd-pb3l-lS7TA1
[root@server1 ~]#
lvdisplay
[root@server1 ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID yt5b4f-m2XC-F3aP-032r-ulAT-Re5P-lmh6hy
LV Write Access read/write
LV Status available
# open 1
LV Size 4.16 GB
Current LE 133
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID VrPqpP-40ym-55Gs-ShVm-Hlzs-Jzot-oYnonY
LV Write Access read/write
LV Status available
# open 1
LV Size 608.00 MB
Current LE 19
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1
[root@server1 ~]#
2安装mdadm
设置RAID的最重要的工具是mdadm
。 让我们像这样安装:
yum install mkinitrd mdadm
之后,我们加载了几个内核模块(以避免重启):
modprobe linear
modprobe multipath
modprobe raid0
modprobe raid1
modprobe raid5
modprobe raid6
modprobe raid10
现在跑
cat /proc/mdstat
输出应如下所示:
[root@server1 ~]# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices: <none>
[root@server1 ~]#
3准备/ dev / sdb
要在我们已经运行的系统上创建RAID1阵列,我们必须为RAID1准备/ dev / sdb
硬盘,然后将/ dev / sda
硬盘的内容复制到它,最后将/ dev / sda
添加到RAID1阵列。
首先,我们将分区表从/ dev / sda
复制到/ dev / sdb
,以使两个磁盘都具有完全相同的布局:
sfdisk -d /dev/sda | sfdisk /dev/sdb
输出结果如下:
[root@server1 ~]# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdb1 * 63 401624 401562 83 Linux
/dev/sdb2 401625 10474379 10072755 8e Linux LVM
/dev/sdb3 0 - 0 0 Empty
/dev/sdb4 0 - 0 0 Empty
Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
[root@server1 ~]#
命令
fdisk -l
现在应该显示两个硬盘都有相同的布局:
[root@server1 ~]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008b885
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 652 5036377+ 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 25 200781 83 Linux
/dev/sdb2 26 652 5036377+ 8e Linux LVM
Disk /dev/dm-0: 4462 MB, 4462739456 bytes
255 heads, 63 sectors/track, 542 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 637 MB, 637534208 bytes
255 heads, 63 sectors/track, 77 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x30307800
Disk /dev/dm-1 doesn't contain a valid partition table
[root@server1 ~]#
接下来,我们必须将我们在/ dev / sdb
上的两个分区的分区类型更改为Linux raid autodetect
:
fdisk /dev/sdb
[root @ server1〜]#fdisk / dev / sdb
命令(m为帮助):
< - m
命令行动
一个可启动标志的切换
b编辑bsd disklabel
c切换dos兼容性标志
d删除一个分区
l列出已知的分区类型
m打印此菜单
n添加一个新的分区
o创建一个新的空DOS分区表
p打印分区表
q退出而不保存更改
s创建一个新的空的Sun磁盘标签
t更改分区的系统ID
u更改显示/输入单位
v验证分区表
w将表写入磁盘并退出
x额外功能(仅限专家)
命令(m为帮助):
< - t
分区号(1-4):
< - 1
十六进制代码(L型列表代码):
< - L
0空1e隐藏W95 FAT1 80旧Minix是Solaris启动
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39计划9 82 Linux交换/ So c1 DRDOS / sec(FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS / sec(FAT-
4 FAT16 <32M 40 Venix 80286 84 OS / 2隐藏C:c6 DRDOS /秒(FAT-
5扩展41 PPC PReP引导85 Linux扩展c7 Syrinx
6 FAT16 42 SFS 86 NTFS卷集da非FS数据
7 HPFS / NTFS 4d QNX4.x 87 NTFS卷集db CP / M / CTOS /。
8 AIX 4e QNX4.x第2部分88 Linux纯文本戴尔实用程序
9 AIX可启动4f QNX4.x第3部分8e Linux LVM df BootIt
OS / 2 Boot Manag 50 OnTrack DM 93变形虫e1 DOS访问
b W95 FAT32 51 OnTrack DM6 Aux 94变形虫BBT e3 DOS R / O
c W95 FAT32(LBA)52 CP / M 9f BSD / OS e4 SpeedStor
e W95 FAT16(LBA)53 OnTrack DM6 Aux a0 IBM Thinkpad Hi eb BeOS fs
f W95 Ext'd(LBA)54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI(FAT-12/16 /
11隐藏FAT12 56金弓a7 NeXTSTEP f0 Linux / PA-RISC b
12 Compaq diagnostics 5c Priam Edisk a8达尔文UFS f1 SpeedStor
14隐藏FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16隐藏FAT16 63 GNU HURD或Sys ab达尔文启动f2 DOS二级
17 Hidden HPFS / NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI交换fe LANstep
1b隐藏W95 FAT3 70 DiskSecure多bb启动向导隐藏ff BBT
1c隐藏W95 FAT3 75 PC / IX
十六进制代码(L型列表代码):
< - fd
更改系统类型的分区1到fd(Linux raid autodetect)
命令(m为帮助):
< - t
分区号(1-4):
< - 2
十六进制代码(L型列表代码):
< - fd
更改系统类型的分区2到fd(Linux raid autodetect)
命令(m为帮助):
< - w
分区表已被更改!
调用ioctl()重新读取分区表。
同步磁盘
[root @ server1〜]#
命令
fdisk -l
现在应该显示/ dev / sdb1
和/ dev / sdb2
是Linux raid autodetect
的类型:
[root@server1 ~]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008b885
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 652 5036377+ 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 25 200781 fd Linux raid autodetect
/dev/sdb2 26 652 5036377+ fd Linux raid autodetect
Disk /dev/dm-0: 4462 MB, 4462739456 bytes
255 heads, 63 sectors/track, 542 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 637 MB, 637534208 bytes
255 heads, 63 sectors/track, 77 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x30307800
Disk /dev/dm-1 doesn't contain a valid partition table
[root@server1 ~]#
要确保/ dev / sdb
上以前的RAID安装中没有剩余的内容,我们运行以下命令:
mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdb2
如果以前的RAID安装没有任何遗漏,上述每个命令将会抛出一个这样的错误(这是不用担心的):
[root@server1 ~]# mdadm --zero-superblock /dev/sdb1
mdadm: Unrecognised md component device - /dev/sdb1
[root@server1 ~]#
否则命令根本不会显示任何内容。