ubuntu做软件磁盘陈列(RAID1)

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
7568846
帖子: 63
注册时间: 2008-10-09 10:04

ubuntu做软件磁盘陈列(RAID1)

#1

帖子 7568846 » 2009-10-30 12:21

ubuntu 8.04 server做软磁盘陈列RAID1

本指南介绍了如何在一个已经运行的系统上(ubuntu 8.04 server) 建立RAID1。并在GRUB引导程序将配置启动的方式,
无论那一块磁盘出现故障,都能保证系统正常运行。

注:关于RAID的介绍,大家可以去百度搜索,百科里讲的很详细。

在本教程中我们需要使用两块磁盘,并且两块磁盘的大小一样,现在它们两的分区情况。

磁盘A:
/dev/sda1为/boot 分区ext3
/dev/sda2为系统的swap交换分区
/dev/sda3为 / 系统文件 分区ext3

磁盘B还没有分区,我是先再磁盘A上装好系统后,再做RAID的

陈列磁盘的分区情况:
/dev/md0 为/dev/sda1与/dev/sdb1组成,/boot 分区ext3
/dev/md1 为/dev/sda2与/dev/sdb2组成, swap 交换分区
/dev/md2 为/dev/sda3与/dev/sdb3组成,/系统 分区ext3

请先在磁盘A上安装好系统,系统的安装这里不再强调。

系统装好后,请大家以root权限登录。

请执行:

sudo df -h

root@epfhk:~# sudo df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 4.8G 521M 4.1G 12% /
varrun 125M 44K 125M 1% /var/run
varlock 125M 0 125M 0% /var/lock
udev 125M 48K 125M 1% /dev
devshm 125M 0 125M 0% /dev/shm
/dev/sda1 236M 24M 200M 11% /boot

sudo fdisk -l

root@epfhk:~# sudo fdisk -l

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008f480

Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 83 Linux
/dev/sda2 32 153 979965 82 Linux swap / Solaris
/dev/sda3 154 783 5060475 83 Linux

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

上面显示了磁盘分区的信息,你会看到磁盘B还是在初始状态下

接下来我们安装mdadm软件,用于做RAID

apt-get install initramfs-tools mdadm

为了避免重启电脑,我们开启下列模块

modprobe md
modprobe linear
modprobe multipath
modprobe raid0
modprobe raid1
modprobe raid5
modprobe raid6
modprobe raid10

接下来运行:

cat /proc/mdstat

root@epfhk:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices: <none>

因为我们还没有做RAID,所以没有陈列磁盘的信息。

现在我们来格式B磁盘,我们要交B磁盘下的分区和A上的一致,我们可以使用磁盘复制分区的方法。

sfdisk -d /dev/sda | sfdisk /dev/sdb

root@epfhk:~# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now ...
OK

Disk /dev/sdb: 783 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 2457944 1959930 82 Linux swap / Solaris
/dev/sdb3 2457945 12578894 10120950 83 Linux
/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).)

我们再使用命令查看两个磁盘的分区:

sudo fdisk -l

root@epfhk:~# fdisk -l

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008f480

Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 83 Linux
/dev/sda2 32 153 979965 82 Linux swap / Solaris
/dev/sda3 154 783 5060475 83 Linux

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 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 153 979965 82 Linux swap / Solaris
/dev/sdb3 154 783 5060475 83 Linux

两个磁盘的分区一模一样,这是我们想要的结果。

接下来我们还要修改磁盘B上的分区类型,使其成为Linux raid autodetect 分区类型

fdisk /dev/sdb

root@epfhk:~# fdisk /dev/sdb

Command (m for help): m 这里输入“M”为显示帮助
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): t 这里办入“T”为修改系统分区类型
Partition number (1-4): 1 这里指定你的分区号
Hex code (type L to list codes): l 显示关于分区类型的代码

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / 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 hidden C: c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba 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 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3 75 PC/IX
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): w 这里有保存并写入磁盘
The partition table has been altered!

Calling ioctl() to re-read partition table.


sudo fdisk -l /dev/sdb

root@epfhk:~# fdisk -l /dev/sdb

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 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 153 979965 fd Linux raid autodetect
/dev/sdb3 154 783 5060475 fd Linux raid autodetect

如上显示则为下确。

为了确保没有以前的RAID设备仍然在/dev/sdb,我们执行以下命令

mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdb2
mdadm --zero-superblock /dev/sdb3

注:执行以上命令,它会出错,这个无须管它

好了,现在我们来创建RAID的/dev/md0,/dev/md1,/dev/md2.
它们的对应关系统为 /dev/md0=/dev/sdb1,/dev/md1=/dev/sdb2,/dev/md2=/dev/sdb3 RAID类开为1,磁盘个数为2.

mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb2
mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb3

接着我们在执行

cat /proc/mdstat

就会显示下面RAID信息

root@epfhk:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sdb3[1]
5060352 blocks [2/1] [_U]

md1 : active raid1 sdb2[1]
979840 blocks [2/1] [_U]

md0 : active raid1 sdb1[1]
248896 blocks [2/1] [_U]

unused devices: <none>

接下来,我们创建的文件系统的磁盘阵列

mkfs.ext3 /dev/md0
mkswap /dev/md1
mkfs.ext3 /dev/md2

我们不需要修改/etc/mdadm/mdadm.conf,请再修改之前做好备份

cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm/mdadm.conf

然后执行

cat /etc/mdadm/mdadm.conf
内容
root@epfhk:~# cat /etc/mdadm/mdadm.conf
# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays

# This file was auto-generated on Wed, 21 Oct 2009 05:15:31 -0400
# by mkconf $Id$
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=f7b5fc02:7403af43:5e6a6f81:fcc9bfbf
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=4dff2929:83c5256e:5e6a6f81:fcc9bfbf
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=5ae22f2f:b4ec4e9a:5e6a6f81:fcc9bfbf

然后我们需要挂载/dev/md0和/dev/md2

mkdir /mnt/md0
mkdir /mnt/md2
mount /dev/md0 /mnt/md0
mount /dev/md2 /mnt/md2

显示挂载息

mount

/dev/sda3 on / type ext3 (rw,relatime,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw)
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)

接下来我们要修改/etc/fstab文件里的uuid,将/dev/sda1改为/dev/md0,/dev/sda2改为/dev/md1,/dev/sda3改为/dev/md2.
请再修改前做好备份,
cp /etc/fstab /etc/fstab_back
sudo blkid 这条命令显示系统所有分区的UUID

root@epfhk:~# blkid
/dev/sda1: UUID="78b8d843-958a-49bd-9623-6ee65e3568d1" TYPE="ext3"
/dev/sda2: TYPE="swap" UUID="c05e3f80-f217-4470-b9ed-0625d27da67e"
/dev/sda3: UUID="d312f5de-2217-421d-b4ee-b0f51941be63" TYPE="ext3"
/dev/sdb1: UUID="02fcb5f7-43af-0374-816f-6a5ebfbfc9fc" TYPE="mdraid"
/dev/sdb2: UUID="2929ff4d-6e25-c583-816f-6a5ebfbfc9fc" TYPE="mdraid"
/dev/sdb3: UUID="2f2fe25a-9a4e-ecb4-816f-6a5ebfbfc9fc" TYPE="mdraid"
/dev/md0: UUID="f2a659f1-ab86-47b6-8dfb-5c0499ebb59e" TYPE="ext3"
/dev/md1: TYPE="swap" UUID="e957a518-c29c-4aa6-8519-eadca817fb9e"
/dev/md2: UUID="915c9bf0-a599-4edb-8cea-546399db6558" TYPE="ext3"

还要修改/etc/mtab文件,将/dev/sda1改成/dev/md0,/dev/sda3改成/dev/md2.
请再修改前做好备份
cp /etc/mtab /etc/mtab_back

现在该修改GRUB引导加载器,打开/boot/grub/menu.lst 并在“default 0” 的后面加上“fallback 1”

nano /boot/grub/menu.lst

[...]
default 0
fallback 1
[...]

修改好后,我们往下走,请文件的最后面,你会看到如下的信息。

## ## End Default Options ##

title Ubuntu 8.04, kernel 2.6.24-16-server
root (hd0,0)
kernel /vmlinuz-2.6.24-16-server root=UUID=d312f5de-2217-421d-b4ee-b0f51941be63 ro quiet splash
initrd /initrd.img-2.6.24-16-server
quiet

title Ubuntu 8.04, kernel 2.6.24-16-server (recovery mode)
root (hd0,0)
kernel /vmlinuz-2.6.24-16-server root=UUID=d312f5de-2217-421d-b4ee-b0f51941be63 ro single
initrd /initrd.img-2.6.24-16-server

title Ubuntu 8.04, memtest86+
root (hd0,0)
kernel /memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

总共有三段,我们只是修改第一段就可以,如下:

请将 root (hd0,0) 修改为 root (hd1,0)

请将 kernel /vmlinuz-2.6.24-16-server root=UUID=d312f5de-2217-421d-b4ee-b0f51941be63 ro quiet splash
修改 kernel /vmlinuz-2.6.24-16-server root=UUID=915c9bf0-a599-4edb-8cea-546399db6558 ro quiet splash

注:kernel 修改的主要为它的UUID 原来的UUID为/dev/sda3,现在我们要将UUID改为/dev/md2,可以用blkid去查看各自的UUID

接下来,我们调整我们的内存

update-initramfs -u

现在我们拷备/dev/sda1 和 /dev/sda3到/dev/md0 /dev/md2 并安装到/mnt/md0和/mnt/md2

cp -dpRx / /mnt/md2
cd /boot
cp -dpRx . /mnt/md0

接下来我们还要为第二个磁盘(/dev/sdb)设置GRUB启动

grub //进入GRUB的shell,在下输入:

root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)
quit

重新启动电脑

这时系统会以陈列启动,而实际磁盘为/dev/sdb

df -h

root@epfhk:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md2 4.8G 523M 4.1G 12% /
varrun 125M 48K 125M 1% /var/run
varlock 125M 0 125M 0% /var/lock
udev 125M 72K 125M 1% /dev
devshm 125M 0 125M 0% /dev/shm
/dev/md0 236M 24M 200M 11% /boot

cat /proc/mdstat

root@epfhk:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sdb3[1]
5060352 blocks [2/1] [_U]

md1 : active raid1 sdb2[1]
979840 blocks [2/1] [_U]

md0 : active raid1 sdb1[1]
248896 blocks [2/1] [_U]

unused devices: <none>

ARID1的磁盘数为两个,己有一个磁盘加入

现在我们需要修改磁盘A上的分区类型,为加入RAID1做准备,修改方法和B的一样,这里不再做详解。

root@epfhk:~# fdisk /dev/sda

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

现在将/dev/sda1,/dev/sda2,/dev/sda3加入到RAID中

mdadm --add /dev/md0 /dev/sda1
mdadm --add /dev/md1 /dev/sda2
mdadm --add /dev/md2 /dev/sda3

使用以下命令查看,磁盘同步:

watch cat /proc/mdstat

OK,同步完成

cat /proc/mdstat

出现以下的情况,说明成功

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sda3[0] sdb3[1]
5060352 blocks [2/2] [UU]

md1 : active raid1 sda2[0] sdb2[1]
979840 blocks [2/2] [UU]

md0 : active raid1 sda1[0] sdb1[1]
248896 blocks [2/2] [UU]

unused devices: <none>

我们需要将以前备份的mdadm.conf还原过来

cp /etc/mdadm/mdadm.conf_orig /etc/mdadm/mdadm.conf
mdadm --examine --scan >> /etc/mdadm/mdadm.conf

cat /etc/mdadm/mdadm.conf

root@epfhk:~# cat /etc/mdadm/mdadm.conf
# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays

# This file was auto-generated on Wed, 21 Oct 2009 05:15:31 -0400
# by mkconf $Id$
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=f7b5fc02:7403af43:5e6a6f81:fcc9bfbf
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=4dff2929:83c5256e:5e6a6f81:fcc9bfbf
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=5ae22f2f:b4ec4e9a:5e6a6f81:fcc9bfbf


接下来我们修改boot/grub/menu.lst

## ## End Default Options ##

title Ubuntu 8.04, kernel 2.6.24-16-server
root (hd1,0)
kernel /vmlinuz-2.6.24-16-server root=UUID=915c9bf0-a599-4edb-8cea-546399db6558 ro quiet splash
initrd /initrd.img-2.6.24-16-server
quiet

title Ubuntu 8.04, kernel 2.6.24-16-server (recovery mode)
root (hd0,0)
kernel /vmlinuz-2.6.24-16-server root=UUID=915c9bf0-a599-4edb-8cea-546399db6558 ro single
initrd /initrd.img-2.6.24-16-server

title Ubuntu 8.04, memtest86+
root (hd0,0)
kernel /memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

上次为修改第一段,现再我们须要修改第二段

请将第二段上的 kernel /vmlinuz-2.6.24-16-server root=UUID=d312f5de-2217-421d-b4ee-b0f51941be63 ro single
改为 kernel /vmlinuz-2.6.24-16-server root=UUID=915c9bf0-a599-4edb-8cea-546399db6558 ro single

下面是我电脑中,给大家参考:

## ## End Default Options ##

title Ubuntu 8.04, kernel 2.6.24-16-server (hd1)
root (hd1,0)
kernel /vmlinuz-2.6.24-16-server root=UUID=915c9bf0-a599-4edb-8cea-546399db6558 ro quiet splash
initrd /initrd.img-2.6.24-16-server
quiet

title Ubuntu 8.04, kernel 2.6.24-16-server (hd0)
root (hd0,0)
kernel /vmlinuz-2.6.24-16-server root=UUID=915c9bf0-a599-4edb-8cea-546399db6558 ro single
initrd /initrd.img-2.6.24-16-server

title Ubuntu 8.04, memtest86+
root (hd0,0)
kernel /memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST


kopt=root=UUID=d312f5de-2217-421d-b4ee-b0f51941be63 ro
修改为
#kopt=root=UUID=d312f5de-2217-421d-b4ee-b0f51941be63 ro
这样,如果不管你的那个磁盘坏了,都能保证你的系统能够正常启动。

update-initramfs -u
reboot

现在基本上,RAID1己经做完,接下来我们来模拟磁盘出现故障后如何解决
比方现在B磁盘损坏,我们需要更换一块新磁盘上去,现在我们删除故障磁盘。

mdadm --manage /dev/md0 --fail /dev/sdb1
mdadm --manage /dev/md1 --fail /dev/sdb2
mdadm --manage /dev/md2 --fail /dev/sdb3
mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm --manage /dev/md1 --remove /dev/sdb2
mdadm --manage /dev/md2 --remove /dev/sdb3

shutdown -h now

关机,把磁盘B拆下,换一块新磁盘上去,但要和磁盘A容量一样大,装好开机。
开机后,会出现很多错误找不磁盘B,这里不用管它。启动完成后,它会出现一个
“rccovery menu”恢复菜单,我们选择第二项,使用命令终端。

输入
fdisk -l
它显示磁盘B未做分区,我们使用分区复制方法.

sfdisk -d /dev/sda | sfdisk /dev/sdb

如有出现错误,请使用以下命令

sfdisk -d /dev/sda | sfdisk --force /dev/sdb

以上完成后,使用fdisk -l查看一下,看看/dev/sda和/dev/sdb是一样不。

请执行

mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdb2
mdadm --zero-superblock /dev/sdb3

然后添加磁盘B到RAID中

mdadm -a /dev/md0 /dev/sdb1
mdadm -a /dev/md1 /dev/sdb2
mdadm -a /dev/md2 /dev/sdb3


使用以下命令查看,磁盘同步:

watch cat /proc/mdstat

OK,同步完成

cat /proc/mdstat

出现以下的情况,说明成功

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sda3[0] sdb3[1]
5060352 blocks [2/2] [UU]

md1 : active raid1 sda2[0] sdb2[1]
979840 blocks [2/2] [UU]

md0 : active raid1 sda1[0] sdb1[1]
248896 blocks [2/2] [UU]

unused devices: <none>

还要修改GRUB
grub
root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)
quit
reboot

OK,打完收工
回复