如何在运行的LVM系统(包括GRUB2配置)上设置软件RAID1(Debian Squeeze)
本指南介绍如何在已经运行的LVM系统(Debian Squeeze)上设置软件RAID1。 将配置GRUB2引导加载程序,以使系统仍然可以在其中一个硬盘驱动器发生故障(无论哪一个)中启动。
我不会保证这将为您工作!
1初步说明
在本教程中,我使用的Debian Squeeze系统有两个硬盘驱动器, / dev / sda
和/ dev / sdb
大小相同。 / dev / sdb
当前未使用,并且/ dev / sda
具有以下分区(这是默认的Debian Squeeze LVM分区方案 - 您应该在系统上找到类似的内容,除非您选择在系统安装期间手动分区):
-
/ dev / sda1
:/ boot
partition,ext2; -
/ dev / sda2
:extended,包含/ dev / sda5
; -
/ dev / sda5
:用于LVM(卷组server1
),并包含/
(卷根
)和交换(卷交换
)。
最后我想要有以下情况:
-
/ dev / md0
(由/ dev / sda1
和/ dev / sdb1组成
):/ boot
partition,ext2; -
/ dev / md1
(由/ dev / sda5
和/ dev / sdb5组成
):LVM(卷组server1
)包含/
(卷根)
和交换(卷交换
)。
这是现在的情况:
df -h
root@server1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/server1-root
4.5G 720M 3.6G 17% /
tmpfs 249M 0 249M 0% /lib/init/rw
udev 244M 104K 244M 1% /dev
tmpfs 249M 0 249M 0% /dev/shm
/dev/sda1 228M 16M 201M 8% /boot
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
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003717c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 32 653 4990976 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/dm-0: 4844 MB, 4844421120 bytes
255 heads, 63 sectors/track, 588 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
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 264 MB, 264241152 bytes
255 heads, 63 sectors/track, 32 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
Disk /dev/dm-1 doesn't contain a valid partition table
root@server1:~#
pvdisplay
root@server1:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name server1
PV Size 4.76 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 1218
Free PE 0
Allocated PE 1218
PV UUID 8p9j8i-cc9a-bAJq-LFP9-CBMF-JrPl-SDbx4X
root@server1:~#
vgdisplay
root@server1:~# vgdisplay
--- Volume group ---
VG Name server1
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.76 GiB
PE Size 4.00 MiB
Total PE 1218
Alloc PE / Size 1218 / 4.76 GiB
Free PE / Size 0 / 0
VG UUID m99fJX-gMl9-g2XZ-CazH-32s8-sy1Q-8JjCUW
root@server1:~#
lvdisplay
root@server1:~# lvdisplay
--- Logical volume ---
LV Name /dev/server1/root
VG Name server1
LV UUID 8SNLPE-gHqA-a2LX-BO9o-0QQO-DV2z-3WvTYe
LV Write Access read/write
LV Status available
# open 1
LV Size 4.51 GiB
Current LE 1155
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Name /dev/server1/swap_1
VG Name server1
LV UUID kYaKtb-vkkV-TDDE-me1R-nnER-dzN8-BcVTwz
LV Write Access read/write
LV Status available
# open 1
LV Size 252.00 MiB
Current LE 63
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
root@server1:~#
2安装mdadm
设置RAID的最重要的工具是mdadm
。 让我们像这样安装:
apt-get install initramfs-tools mdadm
根文件系统需要MD数组:
< - all
之后,我们加载了几个内核模块(以避免重启):
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 --force /dev/sdb
输出结果如下:
root@server1:~# sfdisk -d /dev/sda | sfdisk --force /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
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
New situation:
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdb1 * 2048 499711 497664 83 Linux
/dev/sdb2 501758 10483711 9981954 5 Extended
/dev/sdb3 0 - 0 0 Empty
/dev/sdb4 0 - 0 0 Empty
/dev/sdb5 501760 10483711 9981952 8e Linux LVM
Warning: partition 1 does not end at a cylinder boundary
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
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003717c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 32 653 4990976 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sdb5 32 653 4990976 8e Linux LVM
Disk /dev/dm-0: 4844 MB, 4844421120 bytes
255 heads, 63 sectors/track, 588 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
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 264 MB, 264241152 bytes
255 heads, 63 sectors/track, 32 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
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
警告:DOS兼容模式已弃用。
强烈建议
关闭模式(命令'c')并将显示单位更改为
扇区(命令'u')。
命令(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空24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39计划9 82 Linux交换/ So c1 DRDOS / sec(FAT-
2 XENIX根3c PartitionMagic 83 Linux c4 DRDOS / sec(FAT-
3 XENIX usr 40 Venix 80286 84 OS / 2隐藏C:c6 DRDOS /秒(FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux扩展c7 Syrinx
5扩展42 SFS 86 NTFS卷集da非FS数据
6 FAT16 4d QNX4.x 87 NTFS卷集db CP / M / CTOS /。
7 HPFS / NTFS 4e QNX4.x第二部分88 Linux纯文本戴尔实用程序
8 AIX 4f QNX4.x第3部分8e Linux LVM df BootIt
9 AIX可启动50 OnTrack DM 93变形虫e1 DOS访问
OS / 2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R / O
b W95 FAT32 52 CP / M 9f BSD / OS e4 SpeedStor
c W95 FAT32(LBA)53 OnTrack DM6 Aux a0 IBM Thinkpad Hi eb BeOS fs
e W95 FAT16(LBA)54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd(LBA)55 EZ-Drive a6 OpenBSD ef EFI(FAT-12/16 /
10 OPUS 56金弓a7 NeXTSTEP f0 Linux / PA-RISC b
11隐藏FAT12 5c Priam Edisk a8达尔文UFS f1 SpeedStor
12 Compaq diagnostics 61 SpeedStor a9 NetBSD f4 SpeedStor
14隐藏FAT16 <3 63 GNU HURD或Sys ab达尔文启动f2 DOS辅助
16 Hidden FAT16 64 Novell Netware af HFS / HFS + fb VMware VMFS
17隐藏HPFS / NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI交换fd Linux raid auto
1b隐藏W95 FAT3 75 PC / IX bb启动向导hid fe LANstep
1c隐藏W95 FAT3 80老Minix是Solaris启动ff BBT
1e隐藏W95 FAT1
十六进制代码(L型列表代码):
< - fd
更改系统类型的分区1到fd(Linux raid autodetect)
命令(m为帮助):
< - t
分区号(1-5):
< - 5
十六进制代码(L型列表代码):
< - fd
更改系统类型的分区5到fd(Linux raid autodetect)
命令(m为帮助):
< - w
分区表已被更改!
调用ioctl()重新读取分区表。
同步磁盘
root @ server1:〜#
命令
fdisk -l
现在应该显示/ dev / sdb1
和/ dev / sdb5
是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
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003717c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 32 653 4990976 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 32 248832 fd Linux raid autodetect
Partition 1 does not end on cylinder boundary.
/dev/sdb2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sdb5 32 653 4990976 fd Linux raid autodetect
Disk /dev/dm-0: 4844 MB, 4844421120 bytes
255 heads, 63 sectors/track, 588 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
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 264 MB, 264241152 bytes
255 heads, 63 sectors/track, 32 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
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/sdb5
如果以前的RAID安装没有任何遗漏,上述每个命令将会抛出一个这样的错误(这是不用担心的):
root@server1:~# mdadm --zero-superblock /dev/sdb1
mdadm: Unrecognised md component device - /dev/sdb1
root@server1:~#
否则命令根本不会显示任何内容。