Install Ubuntu on USB within VirtualBox

0

In order to test the stability of Btrfs-RAID1 I wanted to install Ubuntu on two USB sticks from within Virtualbox.

What I would like to achieve:

  • Having a btrfs-based RAID1-System that boots on either of the USB sticks. I use the 15.04 amd64-image.

Where I am stuck now:

  • I can install and boot it on a single USB stick just fine. Whenever I try to add a second USB stick, adding it within Ubuntu to the btrfs-pool and changing the redundancy levels to RAID1, the system becomes unbootable, showing 'BTRFS: open_ctree failed' and subsequently 'mount: mounting /dev/disk/by-uuid/UUID on /root failed: Invalid argument'.

I have tried at least a dozen times now to set it up properly, but without avail. Things I tried

  • Passing the USB sticks as such via the USB-controller
  • Passing the raw USB disks as virtual vmdks on either SATA or IDE controller
  • Using the whole disk as a single Btrfs partition with and without partition table
  • Setting up a biosgrub partition and/or a '/boot'-ext4-partition in front of the btrfs partition
  • Partitioning only one stick with 'single' redundancy mode and later add the other one

Kapt.Brackbier

Posted 2015-08-07T13:44:05.447

Reputation: 13

Answers

0

Which commands did you use exactly?

Generally, assuming you have two usb drives (same size) available in your VM, the system is installed on the first one, here's what you could do:

Boot a live system, like the Ubuntu install disc. The first usb drive, where Ubuntu is installed, might be /dev/sda, the second one, which is still empty, might be /dev/sdb. I'm assuming, there's a separate /boot partition (sda1) and your btrfs filesystem is on sda2, so you want to create an identical sdb2 as RAID1 mirror.

Copy the partition table to the new usb drive: dd if=/dev/sda of=/dev/sdb bs=512 count=1
The new drive now contains empty partitions, so you have your /dev/sdb2.

sda (FIRST USB DRIVE)  <- your Ubuntu installation
  sda1 /boot           <- your Ubuntu boot partition
  sda2 /               <- your Ubuntu root partition
sdb (SECOND USB DRIVE) <- new usb drive, to be used for mirror
  sdb1                 <- empty fake copy of boot partition
  sdb2 (btrfs...)      <- will be second device in sda2 mirror

Create a new btrfs filesystem: mkfs.btrfs /dev/sdb2
(Use -f if necessary.)

Either mount your old btrfs filesystem (which should be turned into a mirror) using mount /dev/sda2 /mnt or reboot the live system and start the actual Ubuntu system (mountpoint would be / instead of /mnt).

Add the new partition as second device to your btrfs filesystem: btrfs device add /dev/sdb2 /mnt
Replace /mnt if you've mounted it elsewhere (or if you've already rebooted).
Double-check (you should get a list of 2 partitions, sda2 and sdb2 which is still empty): btrfs filesystem show /mnt

Turn your 2-drive btrfs filesystem into a mirror: btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt

Now reboot and see what happens. Run btrfs fi show again to confirm that sda2 and sdb2 are used.

Note that /dev/sdb1 is an empty partition the same size as /dev/sda1 (your boot partition), but as long as you can still boot from sda, you don't need to copy it. For a full copy, if your second usb drive should replace the first usb drive, you should copy sda1 to sdb1 as well (dd command, see above).

basic6

Posted 2015-08-07T13:44:05.447

Reputation: 2 032