HOW TO - Raspberry Pi3 boot from SSD - Install openHAB to USB or SSD and boot

I have been running openHAB for about 2 years and have suffered 2 SD card failures. The first card lasted about 14 months and the next only about 7 months or so. During these situations I got burned a bit with backup/restore and so I decided to install on a SSD hard drive for better reliability.

I am currently documenting the process for installing latest openhabian image onto a USB drive and set my Raspberry Pi 3b to boot from USB. (Without needing to use a card in the sd card slot (not even for /boot)

Assumptions:

  • Main Computer - Linux - Ubuntu (or you can use Windows and Putty to execute commands over ssh)
  • Hardware running openhab2 (Raspberry Pi 3b)

Pre step: . From main computer, use ETCHER to flash latest openhabian image to micro SD card and follow initial setup. ssh into raspberry pi (can watch the install) - You can skip this step if you already have access to the running raspberryPiā€¦

First, check status of current value for option to boot_From_USB in the OTP (one-time programmable memory) of the pi.

openhabian@openHABianPi:~$ vcgencmd otp_dump | grep 17:

The goal is to see a value of: 17:3020000a If you see this value, you can skip the next steps (your Pi already has this set and will attempt to boot from USB in the absence of sd card)

To enable USB boot mode, type the following:

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

This adds program_usb_boot_mode=1 to the end of /boot/config.txt.

Reboot the Raspberry Pi:

sudo reboot now

Once the Pi boots, it will read the new line from the /boot/config.txt file and enable the BOOT_FROM_USB option in the OTP memory. We should now see a value of 17:3020000a if set successfully, we can check again with the code:

$ vcgencmd otp_dump | grep 17:

You should see the new value of 17:3020000a which means the rpi will now check USB slots for bootable medium if one is not found in the memory card slot. (This is a permanent setting). You can now remove the last line from your /boot/config.txt file which we set above. (program_usb_boot_mode=1)

We can now shut down the raspberry pi and remove the SD card and insert our USB stick which has a new image of openhabian flashed using ETCHER.

sudo shutdown now

Remove SD card and plug in your USB now. unplug and re-plug the power adapter to your Pi. This initiate the first time boot from the USB stick or SSD drive.

After about 30 seconds you can watch the installation over ssh from your host computer by logging into the pi with:

ssh openhabian@x.x.x.x  

(default pass = openhabian) where x.x.x.x is the local IP address of your raspberry pi. This setup will take about 30-60 minutes.

Update: Dec 26th. Shortly after writing this, I decided to use a 240GB SSD. I followed the same process above and had absolutely no trouble. I used a powered USB adapter (as suggested below) with my drive inside the enclosure. This has been working great for a couple of weeks.

I hope you find this helpful.

Further Reading:
Raspberry Pi 3- Configure to boot from USB via OTP

Be sure to use a fast USB stickā€¦(or better, use a Solid State Hard Drive - SSD)

I tried to follow this using a USB stick and it took over 2 hours and then finally failed on one of the last steps (updating openhab to latest stable). It seems to be writing much slower and I decided to abortā€¦ I came across a website with benchmark resultsā€¦ tuns out this one get a ā€œterrible average benchā€ ā€¦ I am using a 64GB Kingston DataTraveler 100 G3ā€¦ So take note, and you may want to find a faster card!

USB Benchmark Results - Terrible Average Bench

9 Likes

I havnĀ“t tried. But I wonder if you could write the image directly to an SSD and then boot I thin it should be possible if you have en Rpi3B+ since it can boot from USB by default.

I just did this last week with a 120GB SSD and my Raspberry Pi 3

Below is how I did it. It is not meant to be a tutorial and I take no responsibility for any omisions or errors!

I imaged my SD card with WinDisk32Imager. I then set the write once bit by adding program_usb_boot_mode=1 to the bottom of /boot/config.txt on the SD card. Then I rebooted to allow the bit to be written.

I then used Etcher to write the SD image I created to my 120GB SSD.

I removed the SD card from my RPi and connected the SSD using a powered SATA to USB lead.

Once it booted I sshd to the RPi and expanded the file system using the command line as raspi-config canā€™t do it with SSDs. To do this I did the following;

The commands below suited my SD image but may not suite yours

sudo fdisk /dev/sda

Enter p to see the partitions - take a note of the start of partition 2
Press d and then 2 to delete the main partition (I didnā€™t have a swap partition so nothing else to delete)
Press n then p and then 2 to create a new primary partition, next you need to enter the start of the partition by entering the start number from the old partition that you noted in step one.
For the end of the partition just press enter to accept the default.

If asked to remove ext4 signature select no.

If you are sure you have done everthing ok press w to write the new partition table.

REBOOT

ssh back in and enter sudo resize2fs /dev/sda2

When finished check using df -h.

The SSD and cable I used are;

Kingston 120GB SSD
Powered SATA to USB

5 Likes

That is a neat cable! Thanks for sharing.

Perhaps my issues are indeed are indeed power relatedā€¦ I will look into trying this type of powered USB cable.

I am using a 2.5A power supply to run the Pi and had previously mounted this drive and test creating a couple of files so I thought that might suggest I would be okay.

I am currently running off of SD card but will try again over the holidays to get the SSD based installation running. Will update this post once I do so.

I am also using a 2.5A psu. After my RPi failed to boot with the SSD I left it connected but booted from SD card. I could see the SSD details in the syslog so it was being seen. I never tried to mount it.

With the powered SATA to usb the Pi booted with no problem.

1 Like

Note that I have had success in writing the openhabian image directly to the SSD, rather than needing to use the microSD first.

How??

I had the SSD in an external USB case. I simply plugged that into my computer, and used Etcher to write the image to that disk. You need to go into settings and enable ā€œunsafe modeā€ to be able to select non-flash media.

Yep - this is how I did it as well. checking ā€œunsafe modeā€ was the key step.

Just be careful not to overwrite your existing hard drive!!! I had to triple check as my SSD was the same as the one running my rig!

Ahh okayā€¦ I use Win32DiskImagerā€¦ Maybe thats the reason I couldnĀ“t get it to work.

Okay, so i picked up a powered SATA to USB connector and sure enough everything worked great.

I had flashed the image using Etcher and it booted and installed without any problems. Will work on updating this tutorial. Thank you for getting me over this hump!

1 Like

Did you remember to expand the file system?

Just to give more options.:grinning:

Iā€™ve been running my RPI on SSD without SD card for a while now. If you prefer to use something other than a powered adapter this https://www.amazon.com/gp/product/B06Y5CJSVW/ref=oh_aui_detailpage_o01_s01?ie=UTF8&psc=1 works very well with the RPI.

Thanks - I first bought this exact one, but could not seem to get it to boot. Though, looking back it could have been user error as in earlier testing I was able to read and write files to the drive using that enclosure and cable.

The file system appears to have been resized automatically on first boot. (I used openhabian)

1 Like

Iā€™m going down this road to after my regular SD-card is showing strange behaviour again.
Any tips how to partition the SSD drive?
Iā€™m coming from a 8gig SD_card and now Iā€™ll have a 60gig SSD drive available. Whatā€™s the best practise in using different partitions? A ā€˜smallā€™ root partition and a huge one for the data?

If your planning to flash the openhabian image to the SSD via Etcher then you wonā€™t need to partition the SSD it will work out of the box like the SD card.

If you plan to partition the drive then yes use a small partition for the boot and partition the rest however you like.

Thanks for sharing your knowledge :slight_smile:

Just two questions:

  • Do you have a Raspberry 3B or 3B+ ?
  • Is it still possible to boot from microSD if no SSD is connected via USB?

Just to verify the advises given by @openhab2 and @Scotsman, I run the same setup on a RPi 3B+. Resulting in:
openhabian@openHABianPi:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 111G 2.4G 104G 3% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.8M 482M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 42M 22M 20M 53% /boot
tmpfs 98M 0 98M 0% /run/user/1000

openhabian@openHABianPi:~$ sudo fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 111.8 GiB, 120040980480 bytes, 234455040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xce8985f2

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        8192     93802     85611  41.8M  c W95 FAT32 (LBA)
/dev/sda2       98304 234455039 234356736 111.8G 83 Linux

My system (Stretch) did not resize on reboot but the procedure for re-partitioning outlined by @Scotsman works like charm.

And, yes, the system will boot from my SD-card if I unplug the SSD and insert the SD-card.

very helpful - thank you!

i have now openhabian on a 128 gb ssd for 17 euro :slight_smile:
i used Etcher + Unsafe Mode to get the openhabian.image onto my SSD