The Raspberry Pi is a great all-round kit capable of doing projects as diverse as controlling a media center for use as a broadcast radio. But it has one obvious drawback: the inability to boot from USB.

Well, it still is.

Raspberry Pi 3 filmed

If you are using Raspberry Pi 3 you can now choose not to boot from microSD and instead boot your computer from a USB device. It can be a flash drive, an SSD with a USB adapter, or even a full-sized USB hard drive. This is an important event, so let’s see how you can set up your Raspberry Pi 3 to boot from USB.

Getting Started: Install Raspbian and Add New Files

It’s best to start this project with a fresh copy of Raspbian, so download the latest version (we’re using Raspbian Jessie ), and install it the usual way. Once this is done, safely remove the card from the PC, insert it into the powered off Raspberry Pi and boot up, remote connection via SSH. as soon as it loads.

Log in (unless you changed your default credentials. ), then run the following commands which will replace the files start.elf and bootcode.bin default to the alternatives just loaded:

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

This update delivers two files to the directory /boot . After downloading the files, switch to USB download mode with:

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

This command adds a statement program_usb_boot_mode=1 to the end of the file config.txt .

Linux Raspberry Pi 3 Boot Terminal with USB

You will need to reboot your Pi once this is done.

The next step is to verify that the OTP — One Time Programmable Memory — has been modified. Check it out with:

 vcgencmd otp_dump | grep 17: 

If the result is representative of the address 0x3020000a (for example, 17:3020000a ), so far so good. At this point, if you want to remove the line program_usb_boot_mode=1 from a file config.txt can you do this. The Pi now has USB boot enabled and you can use the same microSD card in another Raspberry Pi 3 with the same image, so removing the line is a good idea.

Raspberry Pi 3 Linux Boot Terminal with USB Nano Edit

This is easy to do by editing config.txt in nano:

 sudo nano /boot/config.txt 

Delete or comment out the corresponding line (preceded by #).

Prepare a bootable USB device

Next, plug the formatted (or ready to remove) USB stick into the spare port on the Raspberry Pi 3. After that, we will continue copying the OS.

Start by identifying your flash drive with lsblk commands lsblk .

Linux Raspberry Pi 3 boot terminal with USB LSBLK command

In this example, the SD card is − mmcblk0 and the USB stick is sda (formatted partition — sda1 ). If you have other USB storage devices connected, the USB drive can be sdb, sdc, etc. After setting the name of the USB drive, unmount the drive and use a partitioned tool to create a 100MB (FAT32) partition and a Linux partition:

 sudo umount /dev/sda sudo parted /dev/sda 

At the (parted) prompt, enter:

 mktable msdos 

You may be informed that the disk is busy. If so, select Ignore and then pay attention to the warning that the data on the disk will be destroyed. As explained earlier, this should be a drive that you are happy to delete or format, so go along with it.

If you run into any problems, you may need to switch to the desktop (manually or via VNC. ) and make sure the drive is offline before entering the mktable msdos command in the window command line.

Continue in parting with the following:

 mkpart primary fat32 0% 100M mkpart primary ext4 100M 100% print 

This will print out some information regarding the disk and new partitions. Navigate to the parted exit with Ctrl + C before creating the boot filesystem and root filesystem:

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

You then need to mount the target filesystems before copying your current Raspbian OS to the USB device.

 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 

This last command is the last command that copies everything and will take some time to complete. Time to make coffee!

Linux Raspberry Pi 3 boot terminal with USB copy

Next, you need to update your SSH host keys to keep the connection to the reconfigured Raspberry Pi after the inevitable reboot:

 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 

Linux Raspberry Pi 3 boot terminal with USB SSH

Note that after sudo chroot (fifth command above) you switch to root, so the user will change from pi@raspberrypi on the root@raspberrypi until you type exit on line 8.

Get ready to reboot from USB!

A few more things to figure out before your Raspberry Pi is ready to boot from USB. We need to edit again cmdline.txt from the command line:

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

Similarly, the following changes need to be made to fstab:

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

You are then ready to unmount the filesystems before shutting down the Pi:

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

Note that a new command is used here poweroff as an alternative shutdown .

When the Pi is turned off, turn off the power before removing the SD card. Then reconnect the power supply — your Raspberry Pi should now boot from the USB device! And for more help with your Pi, check out How to Set Up Wi-Fi and Bluetooth on Your Raspberry Pi 3

Ready to try Raspberry Pi 4 ? Check out its features and specifications.

Похожие записи