convertendo uma instalacao normal em RAID1

19, March, 2009

Adicionando um segundo hd, juntando tudo num RAID1, e com alguma sorte não perdendo nada.

1 – adicionar o segundo hd

root@ubuntu:/home/caio# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00008f89

Device Boot Start End Blocks Id System
/dev/sda1 * 1 993 7976241 83 Linux
/dev/sda2 994 1044 409657+ 5 Extended
/dev/sda5 994 1044 409626 82 Linux swap / Solaris

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

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

2 – instalar suporte a raid

root@ubuntu:/home/caio# apt-cache search mdadm
mdadm – tool to administer Linux MD arrays (software RAID)
root@ubuntu:/home/caio# apt-get install mdadm
Reading package lists… Done
Building dependency tree
Reading state information… Done
Recommended packages:
mail-transport-agent
The following NEW packages will be installed:
mdadm
0 upgraded, 1 newly installed, 0 to remove and 266 not upgraded.
Need to get 220kB of archives.
After unpacking 627kB of additional disk space will be used.
Get:1 http://br.archive.ubuntu.com gutsy/main mdadm 2.6.2-1ubuntu2 [220kB]
Fetched 220kB in 2s (99.3kB/s)
Preconfiguring packages …
Selecting previously deselected package mdadm.
(Reading database … 92659 files and directories currently installed.)
Unpacking mdadm (from …/mdadm_2.6.2-1ubuntu2_i386.deb) …
Setting up mdadm (2.6.2-1ubuntu2) …
Generating mdadm.conf… done.
Removing any system startup links for /etc/init.d/mdadm-raid …
update-initramfs: deferring update (trigger activated)
* Starting MD monitoring service mdadm –monitor [ OK ]

Processing triggers for initramfs-tools …
update-initramfs: Generating /boot/initrd.img-2.6.22-14-generic

3 – clonar a a tabela de particao e salvar backup da tabela no arquivo setores-sdb.bak

root@ubuntu:/home/caio# sfdisk -d /dev/sda | sfdisk /dev/sdb -O setores-sdb.bak
Checking that no-one is using this disk right now …
OK

Disk /dev/sdb: 1044 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 15952544 15952482 83 Linux
/dev/sdb2 15952545 16771859 819315 5 Extended
/dev/sdb3 0 – 0 0 Empty
/dev/sdb4 0 – 0 0 Empty
/dev/sdb5 15952608 16771859 819252 82 Linux swap / Solaris
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).)

4 – setar tipos de todas as particoes de /dev/sdb para FD (Linux raid autodetect), exceto a particao extendida

root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 1 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 3 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 4 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 5 FD
Done

5 – criar RAID devices (modo degradado). md0 para a raiz e md1 para swap

root@ubuntu:/home/caio# mdadm -C /dev/md0 –level=raid1 –raid-devices=2 missing /dev/sdb1
mdadm: array /dev/md0 started.
root@ubuntu:/home/caio# mdadm -C /dev/md1 –level=raid1 –raid-devices=2 missing /dev/sdb5
mdadm: array /dev/md1 started.
root@ubuntu:/home/caio# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
7976128 blocks [2/1] [_U]

md1 : active raid1 sdb5[1]
409536 blocks [2/1] [_U]

unused devices:

6 – criar swap no /dev/md1

root@ubuntu:/home/caio# mkswap /dev/md1
Setting up swapspace version 1, size = 419360 kB
no label, UUID=9e18cec6-63a5-434a-9581-f99b58fbaadd
root@ubuntu:/home/caio# swapon /dev/md1
root@ubuntu:/home/caio# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 409616 0 -1
/dev/md1 partition 409528 0 -2

7 – criar sistema de arquivos no md0

root@ubuntu:/home/caio# mkfs -t ext3 /dev/md0
mke2fs 1.40.2 (12-Jul-2007)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
997472 inodes, 1994032 blocks
99701 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2042626048
61 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

8 – copiar todos arquivos para o novo device RAID

root@ubuntu:/home/caio# mkdir /mnt/md0
root@ubuntu:/home/caio# mount /dev/md0 /mnt/md0/
root@ubuntu:/# find . -xdev -print0 | cpio -0pdvum –sparse /mnt/md0

9 – alterar fstab

# /dev/sda1
#antes
#UUID=e40d8ae6-03c1-4519-91d9-2d2b17a23832 / ext3 defaults,errors=remount-ro 0 1
#depois
/dev/md0 / ext3 defaults,errors=remount-ro 0 1

# /dev/sda5
#antes
#UUID=e596805b-c899-4c46-981e-56d6dc6ae600 none swap sw 0 0
#depois
/dev/md1 /swap sw 0 0

10 – editar menu.lst

title Ubuntu 7.10, kernel 2.6.22-14-generic RAID
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=/dev/md0 ro quiet nosplash
initrd /boot/initrd.img-2.6.22-14-generic-raid
quiet

11 – instalar o grub

grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)
Checking if “/boot/grub/stage1” exists… yes
Checking if “/boot/grub/stage2” exists… yes
Checking if “/boot/grub/e2fs_stage1_5” exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 17 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded
Done.
grub> quit

12 – criar novo initrd para o RAID

cd /mnt/md0
mount -o bind /proc ./proc
mount -o bind /dev ./dev
chroot /mnt/md0
mkinitramfs -r /dev/md0 -o initrd.img-2.6.22-14-generic-raid

13 – testar boot

entrar no grub, setar root como hd1,0
definir configfile como /boot/grub/menu.lst
bootar.
o sistema deve bootar normalmente mas pelo RAID (ainda em modo degraded)

14 – configurar as particoes do sda para RAID

root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 1 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 3 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 4 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 5 FD
Done

15 – Adicionar os sda ao RAID

root@ubuntu:/home/caio# mdadm /dev/md0 -a /dev/sda1
mdadm: added /dev/sda1
root@ubuntu:/home/caio# mdadm /dev/md1 -a /dev/sda5
mdadm: Cannot open /dev/sda5: Device or resource busy

ops, o sda5 esta sendo usado para swap

root@ubuntu:/home/caio# swapon /dev/md1
root@ubuntu:/home/caio# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 409616 0 -1
/dev/md1 partition 409528 0 -2
root@ubuntu:/home/caio# swapoff /dev/sda5
root@ubuntu:/home/caio# swapon -s
Filename Type Size Used Priority
/dev/md1 partition 409528 0 -2

root@ubuntu:/home/caio# mdadm /dev/md1 -a /dev/sda5
mdadm: added /dev/sda5

agora sim. neste momento o RAID está sendo sincronizado.
verifique o status com:

root@ubuntu:/home/caio# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sda5[0] sdb5[1]
409536 blocks [2/2] [UU]

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

unused devices:

16 – reinstalar grub

grub>
device (hd0) /dev/sda
root (hd0,0)
setup (hd0)
quit

17 – bootar e certificar que tudo funciona e que o raid está integro

caio@ubuntu:~$ cat /proc/mounts
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec 0 0
none /proc proc rw,nosuid,nodev,noexec 0 0
udev /dev tmpfs rw 0 0
fusectl /sys/fs/fuse/connections fusectl rw 0 0
/dev/md0 / ext3 rw,data=ordered 0 0
/dev/md0 /dev/.static/dev ext3 rw,data=ordered 0 0
tmpfs /var/lock tmpfs rw,nosuid,nodev,noexec 0 0
tmpfs /lib/modules/2.6.22-14-generic/volatile tmpfs rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
tmpfs /var/run tmpfs rw,nosuid,nodev,noexec 0 0
tmpfs /var/lock tmpfs rw,nosuid,nodev,noexec 0 0
securityfs /sys/kernel/security securityfs rw 0 0
caio@ubuntu:~$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sda5[0] sdb5[1]
409536 blocks [2/2] [UU]

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

unused devices: <none>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: