User Tools

Site Tools


raspberry_pi_3_boot_to_usb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
raspberry_pi_3_boot_to_usb [2016/12/14 16:26] walkeradminraspberry_pi_3_boot_to_usb [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 20: Line 20:
 \\  \\ 
 \\  \\ 
-Go to the [[https://www.raspberrypi.org/downloads/raspbian/|Downloads]] page and install Raspbian onto an SD card using Win32DiskImager if you are on Windows, or dd if you are on Linux/Mac. Boot the Pi. +Go to the [[https://www.raspberrypi.org/downloads/raspbian/|Downloads]] page and install Raspbian onto an SD card using <color red>Win32DiskImager</color> if you are on Windows, or <color red>dd</color> if you are on Linux/Mac. Boot the Pi. 
- +\\  
- +\\  
- +First, prepare the /boot directory with experimental boot files 
- +\\  
- +<file> 
- +If on raspbian lite you need to install rpi-update before you can use it:
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
  
 +sudo apt-get update; sudo apt-get install rpi-update
 +sudo BRANCH=next rpi-update
 +</file>
 +\\ 
 +Then enable USB boot mode with this code:
 +\\ 
 +    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 Pi with sudo reboot, then check that the OTP has been programmed with:
 +\\ 
 +\\ 
 +    vcgencmd otp_dump | grep 17:
 +    17:3020000a
 +\\ 
 +Ensure the output <color red>0x3020000a</color> is correct.
 +\\ 
 +\\ 
 +If you wish, you can remove the <color red>program_usb_boot_mode</color> line from config.txt (make sure there is no blank line at the end) so that if you put the SD card in another Pi, it won't program USB boot mode. You can do this with <color red>sudo nano /boot/config.txt</color>, for example.
 +\\ 
 +\\ 
 +<color red>NOTE - If you use the SAME boot SD Card each time to make a bootable disk, you only need to perform the steps above ONCE</color>
 +\\ 
 +\\ 
 +==== Prepare the USB storage device  ====
 +\\ 
 +Now that your Pi is USB boot-enabled, we can prepare a USB storage device to boot from.\\ 
 +Start by inserting the USB storage device (which will be completely erased) into the Pi.\\ 
 +Rather than downloading the Raspbian image again, we will copy it from the SD card on the Pi.\\ 
 +The source device (sd card) will be <color red>/dev/mmcblk0</color> and the destination device (USB disk)\\ 
 +should be <color red>/dev/sda</color> assuming you have no other USB devices connected.
 +\\ 
 +\\ 
 +We will start by using Parted to create a 100MB FAT32 partition, followed by a Linux ext4 partition that will take up the rest of the disk.
 +\\ 
 +\\ 
 +<file>
 +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
 +      1049kB  99.6MB  98.6MB  primary  fat32        lba
 +      99.6MB  30.8GB  30.7GB  primary  ext4         lba
 +</file>
 \\  \\ 
 +Your <color red>parted</color> print output should look similar to the one above.
 \\  \\ 
 +\\ 
 +Create the boot and root file systems:
 +\\ 
 +\\ 
 +    sudo mkfs.vfat -n BOOT -F 32 /dev/sda1
 +    sudo mkfs.ext4 /dev/sda2
 +\\ 
 +\\ 
 +Mount the target file system and copy the running raspbian system to it:
 +\\ 
 +\\ 
 +<file>
 sudo mkdir /mnt/target sudo mkdir /mnt/target
 sudo mount /dev/sda2 /mnt/target/ sudo mount /dev/sda2 /mnt/target/
Line 58: Line 105:
 sudo apt-get update; sudo apt-get install rsync sudo apt-get update; sudo apt-get install rsync
 sudo rsync -ax --progress / /boot /mnt/target sudo rsync -ax --progress / /boot /mnt/target
 +</file> 
 +\\  
 +Regenerate ssh host keys: 
 +\\  
 +\\  
 +<file>
 cd /mnt/target cd /mnt/target
 sudo mount --bind /dev dev sudo mount --bind /dev dev
Line 70: Line 122:
 sudo umount sys sudo umount sys
 sudo umount proc sudo umount proc
 +</file>
 +\\ 
 +Edit <color red> /boot/cmdline.txt</color> 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 <color red>fstab:</color>
 +\\ 
 +\\ 
 +    sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /mnt/target/etc/fstab
 +\\ 
 +\\ 
 +Finally, unmount the target file systems, and power the Pi off.
 +\\ <file>
 +cd ~
 +sudo umount /mnt/target/boot 
 +sudo umount /mnt/target
 +sudo poweroff 
 +</file>
 +\\ 
 +Disconnect the power supply from the Pi, remove the SD card, and reconnect the power supply. If all has gone well, the Pi should begin to boot after a few seconds.
 +\\ 
 +\\ 
  
 +----
  
 +==== NOTE ====
 +\\ 
 +\\ 
 +Once you have done a couple, and you are comfortable with the sequence, you can copy and paste the commands in batches:
 +\\ 
 +\\ 
 +<file>
 +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
 +</file>
 +\\ 
 +<file>
 +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
 +</file>
 +\\ 
 +exit
 +\\ 
 +<file>
 +sudo umount dev
 +sudo umount sys
 +sudo umount proc
 +</file>
 +\\ 
 +<file>
 sudo sed -i "s,root=/dev/mmcblk0p2,root=/dev/sda2," /mnt/target/boot/cmdline.txt 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 sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /mnt/target/etc/fstab
 +</file> 
 +\\  
 +<file>
 cd ~ cd ~
 sudo umount /mnt/target/boot  sudo umount /mnt/target/boot 
 sudo umount /mnt/target sudo umount /mnt/target
-sudo poweroff  +</file> 
 +\\  
 +\\  
 +sudo poweroff 
 \\  \\ 
 \\  \\ 
  
raspberry_pi_3_boot_to_usb.1481732770.txt.gz · Last modified: 2023/03/09 22:35 (external edit)