如何在运行的LVM系统(包括GRUB配置)上设置软件RAID1(Debian Lenny)
本指南介绍如何在已经运行的LVM系统(Debian Lenny)上设置软件RAID1。 GRUB引导加载程序将被配置为使得如果其中一个硬盘驱动器发生故障,系统仍然可以启动(无论哪一个)。
我不会保证这将为您工作!
1初步说明
在本教程中,我使用的Debian Lenny系统有两个硬盘驱动器, / dev / sda
和/ dev / sdb
,大小相同。 / dev / sdb
当前未使用,并且/ dev / sda
具有以下分区(这是默认的Debian Lenny LVM分区方案 - 您应该在系统上找到类似的内容,除非您选择在系统安装期间手动分区):
-
/ dev / sda1
:/ boot
partition,ext3; -
/ dev / sda2
:extended,包含/ dev / sda5
; -
/ dev / sda5
:用于LVM(卷组debian
),并且包含/
(卷根
)和交换(卷交换
)。
最后我想要有以下情况:
-
/ dev / md0
(由/ dev / sda1
和/ dev / sdb1组成
):/ boot
partition,ext3; -
/ dev / md1
(由/ dev / sda5
和/ dev / sdb5组成
):LVM(卷组debian
),包含/
(卷根)
和交换(卷swap_1
)。
这是现在的情况:
df -h
server1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/debian-root
4.2G 747M 3.2G 19% /
tmpfs 126M 0 126M 0% /lib/init/rw
udev 10M 88K 10M 1% /dev
tmpfs 126M 0 126M 0% /dev/shm
/dev/sda1 236M 32M 193M 14% /boot
server1:~#
fdisk -l
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: 0x0004a259
Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 83 Linux
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 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: 4496 MB, 4496293888 bytes
255 heads, 63 sectors/track, 546 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: 608 MB, 608174080 bytes
255 heads, 63 sectors/track, 73 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-1 doesn't contain a valid partition table
server1:~#
pvdisplay
server1:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name debian
PV Size 4.76 GB / not usable 3.24 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 1217
Free PE 0
Allocated PE 1217
PV UUID biVzjB-5f9A-yeZx-WDgY-RWaH-d2Ek-xlp4to
server1:~#
vgdisplay
server1:~# vgdisplay
--- Volume group ---
VG Name debian
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.75 GB
PE Size 4.00 MB
Total PE 1217
Alloc PE / Size 1217 / 4.75 GB
Free PE / Size 0 / 0
VG UUID 4UfyCV-s32P-uZ5R-asRH-9Jjg-pkF6-d5wi32
server1:~#
lvdisplay
server1:~# lvdisplay
--- Logical volume ---
LV Name /dev/debian/root
VG Name debian
LV UUID N58aS0-n1uV-32gb-S51m-kP75-sfA5-38SMVo
LV Write Access read/write
LV Status available
# open 1
LV Size 4.19 GB
Current LE 1072
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Name /dev/debian/swap_1
VG Name debian
LV UUID IGWTnc-Zgmr-pKW8-Jcp6-URYF-2j2D-Ile6kQ
LV Write Access read/write
LV Status available
# open 2
LV Size 580.00 MB
Current LE 145
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
server1:~#
2安装mdadm
设置RAID的最重要的工具是mdadm
。 让我们像这样安装:
aptitude install initramfs-tools mdadm
您将被问到以下问题:
根文件系统需要MD数组:
< - all
之后,我们加载了几个内核模块(以避免重启):
modprobe md
modprobe linear
modprobe multipath
modprobe raid0
modprobe raid1
modprobe raid5
modprobe raid6
modprobe raid10
现在跑
cat /proc/mdstat
输出应如下所示:
server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices: <none>
server1:~#
3准备/ dev / sdb
要在我们已经运行的系统上创建RAID1阵列,我们必须为RAID1准备/ dev / sdb
硬盘,然后将/ dev / sda
硬盘的内容复制到它,最后将/ dev / sda
添加到RAID1阵列。
首先,我们将分区表从/ dev / sda
复制到/ dev / sdb
,以使两个磁盘都具有完全相同的布局:
sfdisk -d /dev/sda | sfdisk /dev/sdb
输出结果如下:
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 498014 497952 83 Linux
/dev/sdb2 498015 10474379 9976365 5 Extended
/dev/sdb3 0 - 0 0 Empty
/dev/sdb4 0 - 0 0 Empty
/dev/sdb5 498078 10474379 9976302 8e Linux LVM
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).)
server1:~#
命令
fdisk -l
现在应该显示两个硬盘都有相同的布局:
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: 0x0004a259
Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 83 Linux
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 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 31 248976 83 Linux
/dev/sdb2 32 652 4988182+ 5 Extended
/dev/sdb5 32 652 4988151 8e Linux LVM
Disk /dev/dm-0: 4496 MB, 4496293888 bytes
255 heads, 63 sectors/track, 546 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: 608 MB, 608174080 bytes
255 heads, 63 sectors/track, 73 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-1 doesn't contain a valid partition table
server1:~#
接下来,我们必须将/ dev / sdb
上的三个分区的分区类型更改为Linux raid autodetect
:
fdisk /dev/sdb
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-5):
< - 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-5):
< - 5
十六进制代码(L型列表代码):
< - fd
更改系统类型的分区5到fd(Linux raid autodetect)
命令(m为帮助):
< - w
分区表已被更改!
调用ioctl()重新读取分区表。
同步磁盘
server1:〜#
命令
fdisk -l
现在应该显示/ dev / sdb1
和/ dev / sdb5
是Linux raid autodetect
的类型:
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: 0x0004a259
Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 83 Linux
/dev/sda2 32 652 4988182+ 5 Extended
/dev/sda5 32 652 4988151 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 31 248976 fd Linux raid autodetect
/dev/sdb2 32 652 4988182+ 5 Extended
/dev/sdb5 32 652 4988151 fd Linux raid autodetect
Disk /dev/dm-0: 4496 MB, 4496293888 bytes
255 heads, 63 sectors/track, 546 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: 608 MB, 608174080 bytes
255 heads, 63 sectors/track, 73 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-1 doesn't contain a valid partition table
server1:~#
要确保/ dev / sdb
上以前的RAID安装中没有剩余的内容,我们运行以下命令:
mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdb5
如果以前的RAID安装没有任何遗漏,上述每个命令将会抛出一个这样的错误(这是不用担心的):
server1:~# mdadm --zero-superblock /dev/sdb1
mdadm: Unrecognised md component device - /dev/sdb1
server1:~#
否则命令根本不会显示任何内容。