Boot RPi3 From USB

树莓派(3B)支持从USB启动, 参考官方文档进行操作.

Update Firmware

需下载一个约50M的固件, 请耐心等待...

$ sudo apt-get update
$ sudo apt-get install -y rpi-update rsync
$ echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
$ sudo BRANCH=next rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12022  100 12022    0     0   5423      0  0:00:02  0:00:02 --:--:--  5422  
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 4.4.11-v7+
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168    0   168    0     0     58      0 --:--:--  0:00:02 --:--:--    58  
100 51.2M  100 51.2M    0     0  26544      0  0:33:43  0:33:43 --:--:-- 27252  
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.4.17-v7+
 *** depmod 4.4.17+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to ff8b6b07ec8f203e04bb4a7b67e1fdb5e91f98b7
 *** A reboot is needed to activate the new firmware

$ sudo reboot
$ vcgencmd otp_dump | grep 17:
17:3020000a

$ sed -i '/program_usb_boot_mode/d' /boot/config.txt

Once programmed it can’t be reversed. In future releases of Rasbian it could be enabled without any notice or action by the user ...

Format USB Device

  • 使用SanDisk(CZ43)酷豆USB闪存盘(64G), 小巧玲珑!

    • Model: SanDisk Ultra Fit (scsi)
    • Disk /dev/sdb: 62.1GB
    • 失败
  • 使用SanDisk(CZ71)金属USB闪存盘(8G), 实验成功.

    • Model: SanDisk Cruzer Force (scsi)
    • Disk /dev/sda: 8004MB
    • 成功
sudo parted /dev/sda

(parted) mktable msdos
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?  
Yes/No? Yes  
(parted) mkpart primary fat32 0% 100M
(parted) mkpart primary ext4 100M 100%
(parted) print
Model: SanDisk Ultra (scsi)  
Disk /dev/sda: 30.8GB  
Sector size (logical/physical): 512B/512B  
Partition Table: msdos  
Disk Flags:

Number  Start   End     Size    Type     File system  Flags  
 1      1049kB  99.6MB  98.6MB  primary  fat32        lba
 2      99.6MB  30.8GB  30.7GB  primary  ext4         lba
(parted) quit
Information: You may need to update /etc/fstab.  
sudo mkfs.vfat -n BOOT -F 32 /dev/sda1  
sudo mkfs.ext4 /dev/sda2  

Transfer Files (SD Card -> USB Device)

需传输约42,000个文件(1GB), 请耐心等待...

sudo mkdir /mnt/target  
sudo mount /dev/sda2 /mnt/target/  
sudo mkdir /mnt/target/boot  
sudo mount /dev/sda1 /mnt/target/boot/  
sudo rsync -ax --progress / /boot /mnt/target  
sudo sed -i "s,root=/dev/mmcblk0p2,root=/dev/sda2," /mnt/target/boot/cmdline.txt  
sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /mnt/target/etc/fstab  

Re-generate sshd 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  

关机/拔卡/启动

sudo poweroff  

关机后, 断电, 拔掉SD卡, 通电, 再启动.