The purpose of this HOW-To is to show how you can migrate your existing openSUSE server into a mirrored RAID1 solution.
This is not a easy migration, you could leave your server into a non booting and unrecoverable state.
We highly suggest you backup all your data before going into this documentation.
This documentation will setup 2 disks in to a mirrored array, meaning both disks will have same data content.
Partition Scheme:
/dev/sda - Installed non-RAID system disk
/dev/sda1 - swap partition
/dev/sda2 - root partition
/dev/sdb - First empty disk for the RAID mirror
/dev/md0 - Mirrored swap partition
/dev/md1 - Mirrored root partition
* Prepare the non-RAID Disk
- Backup everything
- Make sure that both disks are the same size
-
# cat /proc/partitions
-
-
8 0 2097152 sda
-
8 1 514048 sda1
-
8 2 1582402 sda2
-
8 16 2097152 sdb
It is recommended the migration be performed in run level 1 to minimize corruption possibilities.
Change the default run level to 1.
-
# init 1
-
# vi /etc/inittab
-
id:1:initdefault:
Make sure that your devices do not have labels and that you are referencing the disks by device name.
-
# cat /etc/fstab
-
/dev/sda2 / reiserfs defaults 1 1
-
/dev/sda1 swap swap pri=42 0 0
-
-
# cat /boot/grub/menu.lst
-
default 0
-
timeout 8
-
title openSUSE 10.2
-
root (hd0,1)
-
kernel /boot/vmlinuz-2.6.16.46-0.12-default root=/dev/sda2 resume=/dev/sda1 showopts
-
initrd /boot/initrd-2.6.16.46-0.12-default.orig
Change the partition type on the existing non-RAID disk to type ‘fd’ (Linux raid autodetect).
-
# fdisk /dev/sda
-
-
Command (m for help): p
-
-
Disk /dev/sda: 2147 MB, 2147483648 bytes
-
255 heads, 63 sectors/track, 261 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sda1 1 64 514048+ 82 Linux swap
-
/dev/sda2 * 65 261 1582402+ 83 Linux
-
-
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): p
-
-
Disk /dev/sda: 2147 MB, 2147483648 bytes
-
255 heads, 63 sectors/track, 261 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sda1 1 64 514048+ fd Linux raid autodetect
-
/dev/sda2 * 65 261 1582402+ 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.
* Copy the non-RAID disk’s partition table to the empty disk.
-
# sfdisk -d /dev/sda > partitions.txt
-
# sfdisk /dev/sdb < partitions.txt
-
Checking that no-one is using this disk right now …
-
OK
-
-
Disk /dev/sdb: 261 cylinders, 255 heads, 63 sectors/track
-
-
sfdisk: ERROR: sector 0 does not have an msdos signature
-
/dev/sdb: unrecognized partition
-
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 1028159 1028097 fd Linux raid autodetect
-
/dev/sdb2 * 1028160 4192964 3164805 fd Linux raid autodetect
-
/dev/sdb3 0 - 0 0 Empty
-
/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).)
-
-
# cat /proc/partitions
-
major minor #blocks name
-
-
8 0 2097152 sda
-
8 1 514048 sda1
-
8 2 1582402 sda2
-
8 16 2097152 sdb
-
8 17 514048 sdb1
-
8 18 1582402 sdb2
* Reboot the server.
* Create a Degraded Array
Create the degraded array on the empty disk, but leave out the existing system disk for now.
-
# mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sdb1 missing
-
mdadm: array /dev/md0 started.
-
-
# mdadm –create /dev/md1 –level=1 –raid-devices=2 /dev/sdb2 missing
-
mdadm: array /dev/md1 started.
-
-
# cat /proc/mdstat
-
Personalities : [raid1]
-
md1 : active raid1 sdb2[0]
-
1582336 blocks [2/1] [U_]
-
-
md0 : active raid1 sdb1[0]
-
513984 blocks [2/1] [U_]
-
-
unused devices:
* Format the degraded array devices.
-
# mkswap /dev/md0
-
Setting up swapspace version 1, size = 526315 kB
-
-
# mkreiserfs /dev/md1
-
–snip–
-
ReiserFS is successfully created on /dev/md1.
Backup the original initrd.
-
# ls -l /boot/initrd*
-
lrwxrwxrwx 1 root root 29 Apr 2 12:03 initrd -> initrd-2.6.16.46-0.12-default
-
-rw-r–r– 1 root root 2930512 Apr 2 10:15 initrd-2.6.16.46-0.12-default
-
# mv initrd-2.6.16.46-0.12-default initrd-2.6.16.46-0.12-default.orig
Recreate the initrd with Software RAID1 support.
Add “raid1″ on your INITRD_MODULES list.
-
# vi /etc/sysconfig/kernel
-
INITRD_MODULES="raid1 mptscsih reiserfs"
-
-
# mkinitrd
-
-
Root device: /dev/sda2 (mounted on / as reiserfs)
-
Module list: raid1 mptspi reiserfs
-
Kernel image: /boot/vmlinuz-2.6.5-7.311-default
-
Initrd image: /boot/initrd-2.6.5-7.311-default
-
Shared libs: lib/ld-2.3.3.so lib/libblkid.so.1.0 lib/libc.so.6
-
lib/libpthread.so.0 lib/libselinux.so.1 lib/libuuid.so.1.2
-
Modules: kernel/drivers/scsi/scsi_mod.ko
-
kernel/drivers/scsi/sd_mod.ko
-
kernel/drivers/md/raid1.ko
-
kernel/drivers/message/fusion/mptbase.ko
-
kernel/drivers/message/fusion/mptscsih.ko
-
kernel/drivers/message/fusion/mptspi.ko
-
kernel/fs/reiserfs/reiserfs.ko
-
Including: udev raidautorun
We finish doing a mkinitrd command for preventing that the md0 partition will get detected on next boot.
-
# mkinitrd -f md -d /dev/md0
-
-
Root device: /dev/sda2 (mounted on / as reiserfs)
-
Module list: piix mptspi ide-generic processor thermal fan reiserfs edd
-
(xennet xenblk)
-
Kernel image: /boot/vmlinuz-2.6.16.46-0.12-default
-
Initrd image: /boot/initrd-2.6.16.46-0.12-default
-
Shared libs: lib/ld-2.4.so lib/libacl.so.1.1.0 lib/libattr.so.1.1.0
-
lib/libc-2.4.so lib/libdl-2.4.so lib/libhistory.so.5.1 lib/libncurses.so.5.5
-
lib/libpthread-2.4.so lib/libreadline.so.5.1 lib/librt-2.4.so
-
lib/libuuid.so.1.2 lib/libnss_files-2.4.so lib/libnss_files.so.2
-
lib/libgcc_s.so.1
-
Driver modules: ide-core ide-disk scsi_mod sd_mod piix scsi_transport_spi
-
mptbase mptscsih mptspi ide-generic processor thermal fan edd raid0 raid1
-
xor raid5 linear libata ahci ata_piix
-
Filesystem modules: reiserfs
-
Including: initramfs mdadm fsck.reiserfs
-
Bootsplash: SuSE-SLES (800×600)
-
13481 blocks
-
-
# ls -l /boot/initrd*
-
lrwxrwxrwx 1 root root 29 Apr 2 12:15 initrd -> initrd-2.6.16.46-0.12-default
-
-rw-r–r– 1 root root 3045558 Apr 2 12:15 initrd-2.6.16.46-0.12-default
-
-rw-r–r– 1 root root 2930512 Apr 2 10:15 initrd-2.6.16.46-0.12-default.orig
If you attempt to boot the degraded array, without referencing an initrd that contains the raid1 driver or raidautorun,
then you will get a message that the /dev/md1 device is not found, and the server hangs. If this happens, reboot into the non-RAID configuration and rebuild the initrd properly.
* Setup Grub so it can boot into your new RAID1 system.
vi /boot/grub/menu.lst
-
title openSUSE 10.2 LinuxRAID1
-
root (hd0,1)
-
kernel /boot/vmlinuz-2.6.16.46-0.12-default root=/dev/md1 resume=/dev/md0 showopts
-
initrd /boot/initrd-2.6.16.46-0.12-default
* Copy the System Disk to the Degraded Array
Mount the degraded array system device to a temporary mount point on the non-RAID system disk.
Copy the non-RAID system disk to the degraded array file system.
-
# mkdir -p /mnt/newroot
-
# mount /dev/md1 /mnt/newroot
-
# mount | grep newroot
-
cp -ax / /mnt/newroot
-
chkconfig mdadmd on
* Modify the /mnt/newroot/etc/fstab file on the degraded array so the system boots properly.
-
# cat /mnt/newroot/etc/fstab
-
/dev/sda2 / reiserfs defaults 1 1
-
/dev/sda1 swap swap pri=42 0 0
-
-
# vi /mnt/newroot/etc/fstab
-
-
/dev/md1 / reiserfs defaults 1 1
-
/dev/md0 swap swap pri=42 0 0
* Reboot and select the degraded array “LinuxRAID1″.
* Build the Finished Array
At this point you should be running your system from the degraded array, and the non-RAID disk is not even mounted.
-
# mount
-
/dev/md1 on / type reiserfs (rw,acl,user_xattr)
-
proc on /proc type proc (rw)
-
sysfs on /sys type sysfs (rw)
-
debugfs on /sys/kernel/debug type debugfs (rw)
-
udev on /dev type tmpfs (rw)
-
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
-
-
# mdadm –detail /dev/md1
Create a RAID configuration file.
-
# cat << EOF > /etc/mdadm.conf
-
> DEVICE /dev/sdb1 /dev/sdb2 /dev/sda1 /dev/sda2
-
> ARRAY /dev/md0 devices=/dev/sdb1,/dev/sda1
-
> ARRAY /dev/md1 devices=/dev/sdb2,/dev/sda2
-
> EOF
-
-
# cat /etc/mdadm.conf
-
DEVICE /dev/sdb1 /dev/sdb2 /dev/sda1 /dev/sda2
-
ARRAY /dev/md0 devices=/dev/sdb1,/dev/sda1
-
ARRAY /dev/md1 devices=/dev/sdb2,/dev/sda2
Add the non-RAID disk partitions into their respective RAID array.
-
# mdadm /dev/md0 -a /dev/sda1
-
mdadm: hot added /dev/sda1
-
-
# mdadm /dev/md1 -a /dev/sda2
-
mdadm: hot added /dev/sda2
Now, check how the RAID1 is mirroring from one disk to the other, you will see % completed going and depending of your disk
sizes will take longer to complete.
-
cat /proc/mdstat
Install GRUB onto both disks. You will need to do this manually.
-
# grub
-
-
grub> find /boot/grub/stage1
-
(hd0,1)
-
(hd1,1)
-
-
grub> root (hd0,1)
-
grub> setup (hd0)
-
-
grub> root (hd1,1)
-
grub> setup (hd1)
If you do not reinstall GRUB, after rebooting you will get a GRUB error. If that happens, boot from the safe disk. Once the system is up, follow the steps above to install GRUB onto both drives.
* Remove the original initrd. It is useless at this point.
-
# rm /boot/initrd-2.6.16.46-0.12-default.orig
Change back to your default run level.
-
vi /etc/inittab
-
id:3:initdefault:
Congratulations! You are now using your openSUSE server with RAID1.
-
# df -h
-
Filesystem Size Used Avail Use% Mounted on
-
/dev/md1 1.6G 421M 1.1G 28% /
-
tmpfs 126M 8.0K 126M 1% /dev/shm
2 Responses to “HOW-TO Migrate a existing openSUSE Server into a RAID1 solution”
Leave a Reply
You must be logged in to post a comment.
Thanks for this excellent tutorial.
The only problem I had was grub unable to setup (hd1), this was because I had no entry for (hd1) in /boot/grub/device.map
So I edited the file so that it looked this :
(hd0) /dev/sda
(hd1) /dev/sdb
3submitted…
…