Install Bubba 2 on RAID-1 volumes

From BubbaWiki
Revision as of 00:30, 12 November 2011 by Charles Leclerc (talk | contribs)
Jump to navigation Jump to search

Introduction

As you may know, Bubba devices support RAID for home storage. However the install procedure does not offer the possibility to have your system partitions (root and swap) on raid. Besides the technical challenge, there are a few good reasons to raidify the system partitions. First it protects your fine-and-many-hours-spent tuned configuration of your device from hard drive failure. And second it gives your bubba a much better fault-tolerant design.

The goal of this how-to is to perform a plain standard software system installation on your bubba. You will have however the possibility to copy the data from your home partition. So with a backup of your settings from the web interface, you should get everything back.

Big red warning

This procedures involves commands changing u-boot variables. U-boot is the bootloader of the bubba device, located on a flash chip of the board. Although everything explained here has been carefully tested (at least by myself), you might mess things up and not be able to boot your bubba without a serial console cable (USB rescue rescue system won't fix it). Don't worry though, you will have plenty of verifications before doing the sensible stuff, and the risk is quite low. Nevertheless, you've been warned !!

Prerequisites

This how-to has been tested only on Bubba Two. It would probably work on a bubba 3, with a proper configuration of u-boot stuff. I anyone owns a B3 and have validated that part, you're welcome to add it to this page.

This how-to applies to the bubba release 2.4RC1 for the bubba 2. I think it will probably work with future releases too. You will need :

  • A working bubba two with 2.4RC1 software
  • An install/rescue USB stick with 2.4RC1 software on it
  • An external esata hard drive, ideally the same model as your system disk (or at least the same size)
  • Screwdrivers to open the bubba and the external disk box (we will need to swap them).

Principles

The procedure is divided in several parts :

  • Preparing the new disk to receive the raid volumes, create them and copy the software and data on it.

In this step, from the running bubba system, we will partition the new hard drive with the 3 standard bubba partitions (root, 10Go, swap 1go and data for the rest). Then we will create the three RAID-1 arrays with the newly created partitions ; these arrays will be in a degraded state because we will add the other disk later. We won't change the kernel or the initrd, so the arrays will need to be configured to allow the kernel to dectect them directly during its boot sequence.

After creating the LVM volume for the data, we will format the arrays and extract the bubba filesystem from the install USB key on them. All these steps are greatly inspired by the standard install script from excito (apart from the raid part).

Then we will need to adjust /etc/fstab to reflect the disk configuration

  • Modifying the boot behavior of the device

The boot modification is quite simple : we just need to change the kernel boot parameter root=/dev/sda1 to root=/dev/md0. It is stored in the u-boot environnment as the diskdev parameter.

  • Powering off, physically swapping the disks and reboot

I didn't manage to get u-boot to boot from a differend disk than the one plugged inside the bubba. So we need to place our newly configured disk inside the device. The old disk will go inside the external disk box. After everyhing is closed and plugged, we restart the bubba which should boot on the newly created RAID arrays.

  • Reconfiguring the old system disk and add it to the RAID arrays.

The final step is to repartition the old disk and add the partitions to the RAID arrays. The system will then automatically sync the drives, which concludes the setup.

Tasks

All the commands below need to be run in a ssh session as root.

Preparing the new disk

Partitions and raid arrays

  • Plug/turn on the external disk. We assume from now that it has been detected as /dev/sdb.
  • Create the partitions with the following command :
root@b2:~# sfdisk -uM /dev/sdb << EOF
,10240,fd
,1024,fd
,,fd
EOF
  • Create the three arrays with the previously created partition :
root@b2:~# mdadm --create --metadata=0.9 --level 1 --raid-devices=2 /dev/md0 /dev/sdb1 missing
mdadm: array /dev/md0 started.
root@b2:~# mdadm --create --metadata=0.9 --level 1 --raid-devices=2 /dev/md1 /dev/sdb2 missing
mdadm: array /dev/md1 started.
root@b2:~# mdadm --create --metadata=0.9 --level 1 --raid-devices=2 /dev/md2 /dev/sdb3 missing
mdadm: array /dev/md2 started.
  • Create the LVM data volume :
root@b2:~# pvcreate /dev/md2
Physical volume "/dev/md2" successfully created
root@b2:~# vgcreate bubba2 /dev/md2
Volume group "bubba2" successfully created
root@b2:~# lvcreate -l 100%FREE --name storage bubba
Logical volume "storage" created

Filesystem and data

  • Format the swap array :
root@b2:~# mkswap /dev/md1
  • Format and mount the system array:
root@b2:~# mkfs.ext3 -q -L "Bubba root" /dev/md0
root@b2:~# tune2fs -c0 -i0 /dev/md0
root@b2:~# mkdir /mnt/bubba
root@b2:~# mount /dev/md0 /mnt/bubba
  • Format and mount the data array:
root@b2:~# mkfs.ext3 -q -L "Bubba home" /dev/mapper/bubba2-storage
root@b2:~# tune2fs -c0 -i0 /dev/mapper/bubba2-storage 
root@b2:~# mkdir /mnt/bubba/home
root@b2:~# mount /dev/mapper/bubba2-storage /mnt/bubba/home
  • Plug in the USB install/rescue key. Assuming it is /dev/sdc, mount it and extract the OS :
root@b2:~# mkdir /mnt/usb
root@b2:~# mount /dev/sdc1 /mnt/usb
root@b2:~# tar zxf /mnt/usb/install/payload/*.tar.gz -C /mnt/bubba

Adjusting configuration

  • Edit /mnt/bubba/etc/fstab with your favorite editor so it contains :
/dev/md0        /       ext3    noatime,defaults        0       1
/dev/mapper/bubba2-storage      /home   ext3    defaults                0       2
/dev/md1        none    swap    sw                      0       0
usbfs           /proc/bus/usb   usbfs   defaults        0       0
/proc           /proc   proc    defaults                0       0

Changing u-boot variables

  • Install the uboot-envtools package :
root@b2:~# aptitude install uboot-envtools
  • Create the configuration file for the uboot env tools :
root@b2:~# cat > /etc/fw_env.config << EOF 
# MTD device name       Device offset   Env. size       Flash sector size
/dev/mtd0               0x050000        0x002000        0x002000
/dev/mtd0               0x060000        0x002000        0x002000
EOF
  • Test the uboot configuration :
root@b2:~# fw_printenv

The command should output something like :

baudrate=115200
loads_echo=1
......

Bold text

Swapping disks and first boot