[GUIDE] Root on USB RAID1 array

Post Reply
Posts: 21
Joined: Sun Apr 26, 2015 2:17 am
languages_spoken: english, slovak, czech

[GUIDE] Root on USB RAID1 array

Unread post by kbs1 » Sun Jun 21, 2015 8:55 am

This guide was written for Debian Jessie image [2], but should work in ubuntu with small modifications. Lines / steps marked with * are for debian jessie ONLY. Do not carry them out or apply them in ubuntu. If ubuntu specific instructions should be followed, they will be written directly under the jessie-specific line or step marked with an asterisk (*).

0. Build or download a SD card image, burn it and insert it into your ODROID C1 ;-)

1. Change your hostname to a final one. This is because built MD arrays will have the hostname as a part of their name, and during boot process, this is checked to see if it corresponds with the current host name.
If not, the system might not boot.
- edit /etc/hostname
- edit /etc/hosts
- reboot

* 2. Disable the usbmount-start service, as it might conflict with our desired USB disks usage as a md raid1 array.
insserv --remove usbmount-start
umount the disks if necessary
umount /dev/sda1
umount /deb/sdb1

3. Wipe out the USB disks you are going to use as the root filesystem. This ensures they contain nothing valid, and that mdadm (or kernel!!!) won't automatically assemble them at boot.

dd if=/dev/zero of=/dev/sda bs=16M
dd if=/dev/zero of=/dev/sdb bs=16M
wipefs -a -f /dev/sda
wipefs -a -f /dev/sdb

To view dd progress, use
kill -USR1 `pidof dd`

If you are certain there were no previous raid arrays on the disks, you can append count=10 to the above dd commands and have it done much quicker.

Reboot to reload kernel's partition table.

4. Resize your sd card partition to full size, to add room for new packages to be installed.

fdisk /dev/mmcblk0
p, enter
Note the *start* od /dev/mmcblk0p2 partition, in my case it's 80325.
d, enter, 2, enter
n, enter, enter, enter, type 80325 as start sector - CAREFUL: default is hihger, and if you make a mistake here, you'll destroy your filesystem!, enter, enter.
w, enter


resize2fs /dev/mmcblk0p2

5. Install mdadm.

apt-get install mdadm
answer all arrays have to be started

* update-initramfs will complain about /boot mounted as read only. This is OK as we will update initramfs later.

6. Partition your USB disks [1]

fdisk /dev/sda
n, enter, enter, enter, enter, enter
t, enter, fd, enter
a, enter
w, enter

Repeat for /dev/sdb.

If you get this message for either /dev/sda or /dev/sdb saying:
Re-reading the partition table failed.: Device or resource busy
just complete the fdisk steps for both /dev/sda and /dev/sdb and reboot your system.

7. Initialise the array [1]

mdadm --zero-superblock /dev/sda1 /dev/sdb1

If you have thoroughly erased your disks, you will see messages like
mdadm: Unrecognised md component device - /dev/sdb1
These are OK and not to be worried about.

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1

Ignore warning messages about superblock format, continue creating the array.

8. Configure mdadm
- remove any ARRAY declarations that are in the file /etc/mdadm/mdadm.conf
- run the following commands [1]
cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm/mdadm.conf
dpkg-reconfigure mdadm
answer all, yes, yes, root

* Do not worry about update-initramfs complaining /boot is read only again.

9. Create the USB raid filesystem [1]
mkfs.ext4 /dev/md0
mkdir -p /media/md0
mount /dev/md0 /media/md0

10. Append required initramfs modules into initramfs-tools/modules [1]
printf "\nraid1\nmd_mod\next4\n" >> /etc/initramfs-tools/modules

* 11. Update your initramfs using the update-initramfs.sh script.

12. Update your boot.ini
* mount -o remount,rw /boot
* nano /boot/boot.ini
--> for ubuntu nano /media/boot/boot.ini
replace original root=................ argument
with root=/dev/md0

13. Copy contents of your system to your new MD array [1]
cp -afxv / /media/md0

14. Reboot into your new system! :)

- initramfs and kernel update scripts for debian Jessie ONLY. Ubuntu image automatically updates itself using apt-get.

[1] http://blog.drewwithers.com/2013/11/ras ... ition.html - I basically followed this giude for my Raspberry Pi 2. However for odroid, this was not applicable.
[2] http://forum.odroid.com/viewtopic.php?f=114&t=8084 - Minimal Debian Jessie / wheeze by Tomuta - thanks for your wonderful Debian Jessie minimal distribution.

[The extension sh has been deactivated and can no longer be displayed.]

[The extension sh has been deactivated and can no longer be displayed.]

Posts: 21
Joined: Sun Apr 26, 2015 2:17 am
languages_spoken: english, slovak, czech

Re: [GUIDE] Root on USB RAID1 array

Unread post by kbs1 » Sat Jul 09, 2016 10:08 am

This also works for RAID10, confirmed. You just have to insert raid10 instead of raid1 in /etc/initramfs-tools/modules. Also you can use wipefs -a to wipe your filesystems instead of overwriting them.

When updating initramfs in latest debian distros from mjdjr, image is automatically built for you, so you don't have to use my script. You just have to dpkg-reconfigure mdadm & it's correctly updated. But DO NOT forget to change MODULES=most to MODULES=dep in /etc/initramfs-tools/initramfs.conf!! Otherwise uInitrd will be > 4MB and it will NOT be loaded into memory. There's a hard limit of 8MB coded in u-boot C code I read once, but uInitrd > 4MB do NOT work as well. Yes it's just about the size. With MODULES=dep it will be around ~2.7MB and will load and boot correctly.

Post Reply

Return to “Ubuntu (All Linux'es)”

Who is online

Users browsing this forum: No registered users and 1 guest