I’ve decided to boot my pi from USB because I’m serving content from my pi now and (as mentioned in my previous post) SD cards can become corrupted when used in this way. I will give you the benefit of my experience over the course of this weekend.

Before we start…some issues I ran into:

Read only file system AKA Corrupt SD card

This was due to a corrupt SD card. It seems I have an SD card that is on it’s way out. Frustrating to discover it like this.

I went through setting up the SSH access and localisation only to find that, after completing these, the system disk had changed to read only. After several attempts I reached for a new SD card. This was the fix.

Incorrect code

If you should happen to see an incorrect code when you run vcgencmd otp_dump | grep 17: you may have to run the following:

sudo apt-get install rpi-update
sudo BRANCH=next rpi-update
sudo reboot

msata under powered

I was about to try to set up the msata but I couldn’t get it to power up. lsblk showed nothing, I tested a regular usb and lsblk was able to detect this. I figured it must be a lack of power causing the problem so I connected the msata straight to the mac from the shield and the mac detected it so I knew the drive was ok. After some reading of reviews, on the site I bought the shield from, it was suggested that I should try a 2A 5v supply. I tried this and still didn’t have any joy.

I eventually got this working using a 2.1A power supply.

"target is busy" warning

Not sure what caused this, but I know that it didn’t work after I removed the SD card.

Things I learned:

  • It’s better to start from a fresh raspbian install
  • It’s no problem to reload from SD if something goes wrong
  • If you see any errors in the whole process…you’re gonna have a bad time




So now, without further ado, we can start the process.

Having taken a backup of my pi SD card in my previous post I’m now ready to attempt to boot my pi from my msata flash drive in place of an SD card. (I have a shield already and an msata drive on order, when it arrives, I will continue.

01 The msata drive arrived!

02 Spotty banana for scale

I purchased a new Raspberry Pi3 so that I wouldn’t have to bring down the current running pi whilst I was experimenting. When it arrived, I installed the shield on the pi and the msata drive into the shield and then started reading about the process of switching the boot drive.

03 The msata attached to the pi

I used this guide to complete this setup.

I started by installing debian jessie lite on an sd card (using apple pi baker) and putting it in the pi.

The pi booted and resized the card.

I logged in using the usual pi username and password (pi, raspberry).

Then I wanted to connect the pi to my network so I could update it and connect over ssh (so I could shoot a screen capture of the process for use later in a youtube video).

I managed to get the wifi network connected by completing the following:

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

add the following:

network={
    ssid="ssid_of_my_network"
    psk="my_wifi_password"
}

check to see if you have an ip via

ifconfig wlan0

if you don’t have one try:

sudo ifdown wlan0

then

sudo ifup wlan0

Anyway, after getting the wifi network up I continued:

sudo apt-get update

enable usb boot mode:

echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
sudo reboot

04 Screen capture

when the pi comes back up:

vcgencmd otp_dump | grep 17:

should come back with:

17:3020000a

05 Screen capture

Now we’re supposed to remove the program_usb_boot_mode from /boot/config.txt so that it won’t put any other pis into usb boot mode should you happen to put it in one. However, I just put mine to one side after I’d finished with it. Maybe I should sort that out.

I have plugged the USB drive in and now we need to use parted to create a 100MB FAT32 partition:

sudo parted /dev/sda

  sudo parted /dev/sda
  (parted) mktable msdos
  (parted) mkpart primary fat32 0% 100M
  (parted) mkpart primary ext4 100M 100%
  (parted) print

What I can see after the print statement is:

Model: Liteon
Disk /dev/sda: 31.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start End Size  Type  File system Flags
1 1049kB  99.6MB  primary fat32  lba
2 99.6MB  31.0GB  primary ext4  lba

type quit to exit parted

(parted) quit

Now we need to create the boot and root file systems:

sudo mkfs.vfat -n BOOT -F 32 /dev/sda1
sudo mkfs.ext4 /dev/sda2

Now mount the target file system and copy the running raspbian to it

sudo mkdir /mnt/target
sudo mount /dev/sda2 /mnt/target/
sudo mkdir /mnt/target/boot
sudo mount /dev/sda1 /mnt/target/boot/
sudo apt-get update; sudo apt-get install rsync
sudo rsync -ax --progress / /boot /mnt/target

If all goes well you should see a lot of text flying by your screen:

06 Rsync in progress

After the rsync has completed, regenerate the SSH host keys:

cd /mnt/target
sudo mount --bind /dev dev
sudo mount --bind /sys sys
sudo mount --bind /proc proc
sudo chroot /mnt/target
rm /etc/ssh/ssh_host*
dpkg-reconfigure openssh-server
exit
sudo umount dev
sudo umount sys
sudo umount proc

Edit /boot/cmdline.txt so that it uses the USB storage device as the root file system, instead of the SD card.

sudo sed -i "s,root=/dev/mmcblk0p2,root=/dev/sda2," /mnt/target/boot/cmdline.txt

The same needs to be done for fstab:

sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /mnt/target/etc/fstab

Finally, unmount the target file systems, and power the Raspberry Pi off.

cd ~
sudo umount /mnt/target/boot
sudo umount /mnt/target
sudo poweroff

Disconnect the power supply from the Raspberry Pi, remove the SD card, and reconnect the power supply. If all has gone well, the Raspberry Pi should begin to boot after a few seconds.

I decided to go with the clean install as copying my current image over seemed to cause too many problems. I will migrate things slowly after testing to see if this is a stable solution.