現有系統上安裝 raid 1

[1.] 環境: Fedora Core release 6

[2.] 硬碟分割資訊:
df -h

Filesystem             Size    Used   Avail  Use%   Mounted on
/dev/hda3              77G   946M    73G      2%   /
/dev/hda1              99M    9.9M    84M    11%   /boot
tmpfs                    125M         0  125M      0%   /dev/shm

fdisk -l

Disk /dev/hda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End           Blocks     Id  System
/dev/hda1   *           1            13         104391    83  Linux
/dev/hda2              14            78         522112+  82  Linux swap / Solaris
/dev/hda3              79       10443    83256862+  83  Linux

Disk /dev/hdb: 171.7 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/hdb doesn’t contain a valid partition table

[3.] 套件: mdadm

[4.] 載入模組:
modprobe linear
modprobe multipath
modprobe raid0
modprobe raid1
modprobe raid5
modprobe raid6
modprobe raid10

more /proc/mdstat

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices: <none>

[5.] 將 /dev/hda 的 partition 複製至 /dev/hdb
sfdisk -d /dev/hda | sfdisk /dev/hdb

Checking that no-one is using this disk right now …
OK

Disk /dev/hdb: 20886 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/hdb: 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/hdb1   *            63        208844         208782  83  Linux
/dev/hdb2         208845      1253069       1044225  82  Linux swap / Solaris
/dev/hdb3       1253070  167766794   166513725  83  Linux
/dev/hdb4                   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).)

複製後的 partition

Disk /dev/hda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start           End            Blocks    Id  System
/dev/hda1   *            1             13          104391   83  Linux
/dev/hda2               14             78        522112+   82  Linux swap / Solaris
/dev/hda3               79       10443    83256862+   83  Linux

Disk /dev/hdb: 171.7 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start          End            Blocks    Id  System
/dev/hdb1   *           1             13          104391   83  Linux
/dev/hdb2              14             78        522112+   82  Linux swap / Solaris
/dev/hdb3              79       10443    83256862+   83  Linux

[6.] 更改 partition’s system id 為 Linux raid autodetect
fdisk /dev/hdb

> t > 1 > fd
> t > 2 > fd
> t > 3 > fd
> w

fdisk -l /dev/hdb

Disk /dev/hdb: 171.7 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start          End            Blocks   Id   System
/dev/hdb1   *           1             13          104391   fd   Linux raid autodetect
/dev/hdb2              14             78        522112+   fd   Linux raid autodetect
/dev/hdb3              79       10443    83256862+   fd   Linux raid autodetect

[7.] 清空 md  superblock
mdadm –zero-superblock /dev/hdb1
mdadm –zero-superblock /dev/hdb2
mdadm –zero-superblock /dev/hdb3

如果沒有保留之前的 RAID 的話,會看到

mdadm: Unrecognised md component device – /dev/hdb1
mdadm: Unrecognised md component device – /dev/hdb2
mdadm: Unrecognised md component device – /dev/hdb3

[8.] 建立 RAID 1,因為已有系統在跑,所以要多個 missing 參數,而 –auto=md 為如果沒有 /dev/md0 檔案存在自動建立
mdadm –create /dev/md0 –level=1 –raid-disks=2 missing /dev/hdb1 –auto=md
mdadm –create /dev/md1 –level=1 –raid-disks=2 missing /dev/hdb2 –auto=md
mdadm –create /dev/md2 –level=1 –raid-disks=2 missing /dev/hdb3 –auto=md

more /proc/mdstat

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 hdb3[1]
83256768 blocks [2/1] [_U]

md1 : active raid1 hdb2[1]
522048 blocks [2/1] [_U]

md0 : active raid1 hdb1[1]
104320 blocks [2/1] [_U]

unused devices: <none>

[9.] 格式化
mkfs.ext3 /dev/md0
mkswap /dev/md1
mkfs.ext3 /dev/md2

[10.]
mkdir -p /etc/mdadm
mdadm –examine –scan >> /etc/mdadm/mdadm.conf

[11.]
mkdir /mnt/md0
mkdir /mnt/md2
mount /dev/md0 /mnt/md0
mount /dev/md2 /mnt/md2

df -h

Filesystem              Size  Used  Avail Use%  Mounted on
/dev/hda3              77G  984M   72G     2%   /
/dev/hda1              99M  9.9M    84M  11%   /boot
tmpfs                   125M        0  125M    0%   /dev/shm
/dev/md0               99M  5.6M    89M    6%   /mnt/md0
/dev/md2               79G  184M   75G    1%    /mnt/md2

mount

/dev/hda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)

[12.] vi /etc/fstab

#LABEL=/                 /                       ext3    defaults        1 1
#LABEL=/boot             /boot                   ext3    defaults        1 2
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
sysfs                   /sys                    sysfs   defaults        0 0
#LABEL=SWAP-hda2         swap                    swap    defaults        0 0

/dev/md2                /                       ext3    defaults,errors=remount-ro 0       1
/dev/md0                /boot                   ext3    defaults        0       2
/dev/md1                none                    swap    sw              0       0

vi /etc/mtab

/dev/hda3 / ext3 rw 0 0 改為 /dev/md2 / ext3 rw,errors=remount-ro 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/hda1 /boot ext3 rw 0 0 改為 /dev/md0 /boot ext3 rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/dev/md0 /mnt/md0 ext3 rw 0 0
/dev/md2 /mnt/md2 ext3 rw 0 0

vi /boot/grub/grub.conf

default=0
fallback=1
# 以上的設定為第一個 kernel 開機失敗的話,會使用第二個,即為 0 開機不行,就用 1 的
# 0 指的是 title Fedora Core (2.6.18-1.2798.fc6) raid1
# 1 指的是 title Fedora Core (2.6.18-1.2798.fc6)# 複製一份新的修改紅字部份,root (hd1,0) 指的是 /dev/hdb,已為磁碟陣列了
title Fedora Core (2.6.18-1.2798.fc6) raid1
root (hd1,0)
kernel /vmlinuz-2.6.18-1.2798.fc6 ro root=/dev/md2
initrd /initrd-2.6.18-1.2798.fc6.imgtitle Fedora Core (2.6.18-1.2798.fc6)
root (hd0,0)
kernel /vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=/
initrd /initrd-2.6.18-1.2798.fc6.img

[13.] 安裝 bootloader 給 /dev/hdb
grub
xxx

[14.] reboot
df -h

Filesystem             Size   Used    Avail  Use%   Mounted on
/dev/md2               77G  971M     72G      2%   /
tmpfs                   125M         0  125M      0%   /dev/shm
/dev/md0               99M   5.6M    89M      6%   /boot

more /proc/mdstat

Personalities : [raid1]
md1 : active     raid1 hdb2[1]
522048  blocks [2/1] [_U]

md2 : active        raid1 hdb3[1]
83256768 blocks [2/1] [_U]

md0 : active    raid1 hdb1[1]
104320 blocks [2/1] [_U]

unused devices: <none>

[15.] /dev/hda 一樣改為 linux  raid autodetect
fdisk /dev/hda

> t > 1 > fd
> t > 2 > fd
> t > 3 > fd
> w

[16.] 增加 /dev/hda1、/dev/hda2、/dev/hda3 給個別的 RAID 陣列
mdadm –add /dev/md0 /dev/hda1
mdadm –add /dev/md1 /dev/hda2
mdadm –add /dev/md2 /dev/hda3

(未完…)

http://www.howtoforge.com/software-raid1-grub-boot-debian-etch-p3

Related posts 相關文章
WD 新策略 ? 將在 3 年後提示你的硬碟需要更換了
More...
Linux 更新 Kernel 支援 MegaRAID SAS 硬碟
More...
救援一顆變成 RAW 格式的硬碟
More...
CentOS 8 不支援 PERC 6/i MegaRAID SAS 硬碟
More...

作者

留言

angelwind 

我先fdisk -l 出先/dev/sdb是主碟 /dev/sda是新加入碟 我用sudo mdadm –create –verbose /dev/md0 –level=1 –raid-devices=2 /dev/sdb /dev/sda 結果出現Device or resource busy 請問該怎辦呢?…..是要加missing參數嗎??要怎加呢???

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。