You are on page 1of 2

Feature

BOOTING
FROM USB
Wxuq#d#XVE#ľdvk#gulyh#lqwr#d#errw#gulyh#dqg#vwduw#xs#|rxu#Udvsehuu|#Sl

n this tutorial we’re going to look at booting of 2errw2frqĽj1w{w (you can check it with cat
You’ll I d#Udvsehuu|#Sl#6#xvlqj#d#XVE#ľdvk#gulyh1 ŵ„‘‘–ŵ…‘º‰Ŝ–š–). Reboot the Pi with sudo reboot,
Need You can use any MSD (mass storage
device) to boot the Raspberry Pi, which includes USB
then check that the OTP has been programmed with:

> Raspberry Pi 3 ľdvk#gulyhv#dqg#kdug#gulyhv1 vcgencmd otp_dump | grep 17:


> USB drive
You will, however, need a microSD card to set 17:3020000a
xs#wkh#Udvsehuu|#Sl#lq#wkh#Ľuvw#lqvwdqfh1#Vwduw#e|#
> microSD card
ľdvklqj#d#plfurVG#fdug#zlwk#Udvseldq1 Ensure the output 0x3020000a is correct.
If you’re running Raspbian Lite, you will need to
run an rpi-update: Prepare the USB storage device
Attach a USB storage device (which will be
sudo apt-get update; sudo apt-get install completely erased) to the Raspberry Pi.
rpi-update Rather than downloading the Raspbian image
again, we will copy it from the SD card still in the
Now you need to switch the update branch from Raspberry Pi. The source device (SD card) will be
the default (master) to next: /dev/mmcblk0 and the destination device (USB disk)
should be /dev/sda, assuming you have no other USB
sudo BRANCH=next rpi-update devices connected.

Then we need to enable USB boot mode by sudo umount /dev/sda


dgmxvwlqj#wkh#frqĽj1w{w#Ľoh=
Note the command ‘umount’, not ‘unmount’.
Below Here we
have a Raspberry echo program_usb_boot_mode=1 | sudo tee -a Next, you need to open Parted, pointing to the drive:
Pi running just ŵ„‘‘–ŵ…‘º‰Ŝ–š–
an attached USB
drive mounted sudo parted /dev/sda
on /dev/sda This adds ‘program_usb_boot_mode=1’ to the end
You’ll see a ‘Welcome to GNU Parted!’ message.
You’ll also see (parted) instead of the $ symbol on the
command line, indicating that you’re in Parted. Enter:

mktable msdos

You’ll see: ‘Warning: The existing disk label


on /dev/sda will be destroyed and all data on
this disk will be lost. Do you want to continue?’
Enter ‘yes’.
Now create the two partitions: a FAT32 taking up
100MB of space, the second ext4 taking up the rest.

mkpart primary fat32 0% 100M


mkpart primary ext4 100M 100%

Use print to view the details of the partitions.

70 October 2016 raspberrypi.org/magpi


BOOT YOUR RASPBERRY PI Feature
Ours says: Now regenerate your SSH host keys:
Prgho=#XIG#513#Vlolfrq0Srzhu;J#+vfvl,
Glvn#2ghy2vgd=#;387PE cd /mnt/target
Vhfwru#vl}h#+orjlfdo2sk|vlfdo,=#845E2845E sudo mount --bind /dev dev
Sduwlwlrq#Wdeoh=#pvgrv sudo mount --bind /sys sys
Glvn#Iodjv=# sudo mount --bind /proc proc
Qxpehu### 4# 5 sudo chroot /mnt/target
Vwduw#### 437<nE# <<19PE rm /etc/ssh/ssh_host*
End <<19PE# ;387PE †’‰Ş”‡…‘º‰—”‡‘’‡••ŠŞ•‡”˜‡”
Vl}h##### <;19PE# :<87PE exit
W|sh###### sulpdu|# sulpdu| sudo umount dev
Iloh#v|vwhp### idw65# h{w7# sudo umount sys
Iodjv# lba lba sudo umount proc

Your Parted print output should look similar to the Edit 2errw2fpgolqh1w{w so that it uses the USB storage
rqh#deryh1#Fuhdwh#wkh#errw#dqg#urrw#Ľoh#v|vwhpv= ghylfh#dv#wkh#urrw#Ľoh#v|vwhp#lqvwhdg#ri#wkh#VG#fdug=

•—†‘ˆ•Ŝ˜ˆƒ–ސŞ ɪɩŵ†‡˜ŵ•†ƒɨ sudo sed -i "s,root=/dev/mmcblk0p2,root=/


•—†‘ˆ•Ŝ‡š–ɫŵ†‡˜ŵ•†ƒɩ †‡˜ŵ•†ƒɩřɑŵ–ŵ–ƒ”‰‡–ŵ„‘‘–ŵ…†Ž‹‡Ŝ–š–

Our disk is formatted. It’s time to mount the target The same needs to be done for fstab:
Ľoh#v|vwhpv#rq#vgd4#dqg#vgd5=
sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /
sudo mkdir /mnt/target mnt/target/etc/fstab
sudo mount /dev/sda2 /mnt/target/
sudo mkdir /mnt/target/boot Ilqdoo|/#xqprxqw#wkh#wdujhw#Ľoh#v|vwhpv/#dqg#srzhu#
sudo mount /dev/sda1 /mnt/target/boot/ rļ#wkh#Sl=

Now we need to copy the running Raspbian system cd ~


to the target. We’re going to download a program sudo umount /mnt/target/boot
called rsync and use it to copy Raspbian across. sudo umount /mnt/target
sudo poweroff
sudo apt-get update; sudo apt-get install rsync
sudo rsync -ax --progress / /boot /mnt/target Disconnect the power supply from the Pi, remove
the SD card, and reconnect the power supply.
Wkh#Ľohv#zloo#eh#glvsod|hg#rq#wkh#vfuhhq#dv#wkh|#duh# If all has gone well, the Raspberry Pi will begin
copied across. The copy process may take some time. to boot after a few seconds.

USB BOOT OVERVIEW

>STEP-01 – SWITCH TO NEXT >STEP-02 – COPY RASPBIAN >STEP-03 – UPDATE SSH


First, you need to install Raspbian using cåƻƋØƼŅƚ±ƋƋ±ÏʱŽ„ā±ŸĘÚųĜƴå±ĹÚ Finally, you need to regenerate the SSH keys on
an SD card and open it on a Raspberry use Parted to format it and create two ƼŅƚųŽ„ā±ŸĘÚųĜƴåÆƼÚåĬåƋĜĹčƋĘåŅĬÚĀĬ埱ĹÚ
Pi 3. Switch updates from the master partitions: FAT32 for booting and ext4 for ųåÏŅĹĀčƚųĜĹčŅŞåĹŸŸĘěŸåųƴåųţkŞåń„BĜŸƚŸåÚ
branch to the next branch. This enables Raspbian. Then use rsync to duplicate the ƋŅŸåÏƚųåXĜĹƚƻرĹÚƋĘĜŸƵĜĬĬåűÆĬåƋĘåĹåƵā±ŸĘ
you to run the beta features, including the entire Raspbian image on the SD card to drive to run. Now when you reboot the Raspberry Pi,
new boot modes. ƋĘåā±ŸĘÚųĜƴåţ ƼŅƚϱĹÆŅŅƋÚĜųåÏƋĬƼüųŅĵƋĘ厄ā±ŸĘÚųĜƴåţ

raspberrypi.org/magpi October 2016 71

You might also like