Skip to main content

How To move your BOOT partition to a USB flash drive or external HDD under Xbian

I wanted to try this to see if my 1.0.5a Frodo 12.2 Xbian build would boot any faster with the Xbian boot partition on a USB2 flash drive or portable hard drive.

As my video library was already on a Western Digital 320GB 2.5" portable HDD, it made sense to just create another partition on there to support the boot process. What follows is how I achieved this.

First off, credit to @Jameson for this post which is what all my effort was based on, thank you. But wait, before you get started and waste 30 minutes of your life, please be aware that it was no faster than booting from my 4GB Class 10 Strontium SD Card. The boot times I got are listed below:

  • Boot from 4GB Class 10 Strontium SD Card > 45s
  • Boot from USB2 4GB Flash Drive > 60s
  • Boot from USB2 4GB HDD partition > 64s
Some are saying there may be benefits in using a USB3 drive even under USB2 on the Pi but I haven't tested that yet. I'll update this post when I do.

What you'll need if you still want to try it:
  • A USB flash drive or portable HDD with a partition formatted in FAT or FAT32 (others may be supported but not tested) that is at least the same size as your SD Card.
  • A computer you can SSH into your Pi from and a SD card slot or reader just in case things go wonky.
  • Knowledge of how to SSH into your XBMC build.
  • The ability to use Nano to edit two files on your Pi.
As my media drive was fully formatted with NTFS for my library, I removed all content, deleted the main partition under Windows and created two new partitions; one at 4GB, the same size as my SD card. The rest of the drive was reformatted as NTFS so I could move my library back. I also tried this with a 4GB USB2 thumb drive and the steps are the same albeit the drive letter is different under Linux (/dev/sda1 vs. /dev/sda2).

Now assuming your Pi is all connected up and working and you can SSH into it, follow these steps. All commands that you need to type are in bold and italics.
  1. Hook up your external drive. Run lsusb to ensure it populates on that list. If it doesn't, it may pay just your reboot XBMC to see if it gets recognised.
  2. Run df -h to define what the paritions are for your external drive.
    1. If it's a USB drive, it should report back as /dev/sda1
    2. If it's a 2nd parition on an external drive (like mine), it will report as /dev/sda2.
  3. Assuming your USB stick is /dev/sda1 (usually is…), run sudo dd if=/dev/mmcblk0p2 of=/dev/sda1 bs=512. This will copy your SD card boot partition to your external drive. This took about 15 minutes to execute on my system.
  4. When the SSH session has returned you to the command prompt, run: sudo nano /boot/cmdline.txt 
  5. Edit where it says root=/dev/mmcblk0p2 to /dev/sda1 if you're using a thumb drive (with one partition) or in my case /dev/sda2
  6. Next, run: sudo nano /etc/fstab 
  7. Edit the line that says /dev/mmcblk0p2 to /dev/sda1 or in my case (you guessed it), /dev/sda2.
  8. Reboot by typing (sudo shutdown -r now). 
  9. You should now be booting on your USB stick!
Some points to note:

  • If it fails to boot for any reason, you can insert the SD Card back into your PC/MAC and edit the cmdline.txt file manually to restore the boot line back to root=/dev/mmcblk0p2. Your PI should now boot even though the /etc/fstab is incorrectly pointing to your external drive. SSH back into your device and follow steps 4 and 5 again to change your fstab file back to the defaults.
  • If you modify sudo nano /etc/fstab for /dev/sda1, df -h will no longer be able to see the external drive/s if you change the cmdline.txt back to root=/dev/mmcblk0p2 for any reason, at least that was my experience.
  • Even though the boot partition may only be consuming 1GB of the 3.7GB available, your external drive must be the same size or larger than the whole boot partition size.
  • To use Nano, edit the line you need and on a Windows machine type ALT+X to close the editing process, Type Y when prompted to confirm the edit and just hit Enter to accept that file name that is presented.
Good luck.

Comments

  1. Nice and simple thanks. What's the best way to confirm that its running from the USB drive and not the sd card?
    I copied the whole sd card (both partitions) to my flash drive, not just /root
    Here's my dh -h

    $ df -h

    Filesystem Size Used Avail Use% Mounted on
    rootfs 934M 738M 140M 85% /
    udev 10M 4.0K 10M 1% /dev
    tmpfs 188M 192K 188M 1% /run
    /dev/sda2 934M 738M 140M 85% /
    none 5.0M 0 5.0M 0% /run/lock
    none 188M 0 188M 0% /run/shm
    none 100M 0 100M 0% /run/user
    /dev/sda2 934M 738M 140M 85% /home
    /dev/sda1 34M 11M 24M 32% /boot
    /dev/sda2 934M 738M 140M 85% /media/xbian-root-btrfs-67c085e4-91f4-431c-bd89-404d4625de17

    ReplyDelete
  2. Very informative and well written post! I like your post. It is very helpful and informative. Thank you so much for writing such a good post.I could get lot more knowledge from your article.. thanks for sharing.

    ReplyDelete

Post a Comment

Popular posts from this blog

Using ESPEasy with Home Assistant via MQTT

Preface: I've just started playing around with Home Assistant on a Raspberry Pi and exploring the world of MQTT to control devices on the network. Learning curve is a bit steep but worth the effort as MQTT is very fast. The hardware and software tools I'm using are as follows: 2 x Sonoff relay units 2 x NodeMCU Boards ESPEasy firmware (must be version 121 or above as that contains the MQTT 'retain' flag option. Home Assistant software on Raspberry Pi2 MQTT Test Software: PC: MQTT.fx Android: MQTT Dashboard

My Notepad++ tricks when editing YAML files in Home Assistant

To comment out a whole section in one go: Highlight the text you want to comment out and use CTRL + Q. If you do this at the start of a line, it will only comment that line. CTRL + Q is toggle mode (comment on/off). CTRL + K will allow you to add multiple comments one after the other.

How to check what entities are filling up your Home Assistant database

If you use the Home Assistant MariaDB add-on, this tip will show you how to query the database so see what Home Assistant entity states are triggering the most, filling up your database. What were going to do: Install the phMyAdmin add-on for MariaDB. Query the MariaDB database. See what entity state changes have the most action. Paste the code below into the SQL query box:  select entity_id,count( * ) from states group by entity_id order by count ( * ) desc; And if you're using the internal home-assistant_v2.db instead, you can use the SQLite Web add-on to achieve the same thing.