I have not booted from a stick, but I can get you close with the following
procedures, if you are running Raspbian Jessie. Get the latest updates.
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo reboot
If you have not programmed the USB boot mode, now would be the time to do so, also see Program USB Boot Mode https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md for the Raspberry Pi 3.
$ echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
$ sudo reboot
With the stick installed, determine which USB sd? that you will use. In my case it would be sdb
.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 14.9G 0 disk
└─sdb1 8:17 1 14.9G 0 part /media/pi/USB30FD
sda 8:0 0 931.5G 0 disk
├─sda2 8:2 0 931.4G 0 part /
└─sda1 8:1 0 100M 0 part /media/pi/boot
mmcblk0 179:0 0 29.7G 0 disk
├─mmcblk0p2 179:2 0 29.7G 0 part /media/pi/root
└─mmcblk0p1 179:1 0 41M 0 part /boot
If sdb?
is mounted, unmount it. Format partitions.
$ sudo umount /dev/sdb?
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 14.9 GiB, 16000221184 bytes, 31250432 sectors
Device Boot Start End Sectors Size Id Type
/dev/sdb1 48 31250431 31250384 14.9G c W95 FAT32 (LBA)
$ sudo fdisk /dev/sdb
Changes will remain in memory only, until you decide to write them.
Command (m for help): o
Created a new DOS disklabel with disk identifier 0x553f5f69.
Command (m for help): n
Partition type
Select (default p): [Enter]
Partition number (1-4, default 1): [Enter]
First sector (2048-31250431, default 2048): [Enter]
Last sector (2048-31250431, default 31250431): +100M
Command (m for help): t
Hex code (type L to list all codes): c
Command (m for help): n
Select (default p): [Enter]
Partition number (2-4, default 2): [Enter]
First sector (206848-31250431, default 206848): [Enter]
Last sector (206848-31250431, default 31250431): [Enter]
Command (m for help): w
Syncing disks.
Make filesystems, directors, and mount the filesystems.
$ sudo mkfs.vfat -n boot /dev/sdb1
$ sudo mkfs.ext4 -L root /dev/sdb2
$ sudo mkdir /mnt/d1 /mnt/d2
$ sudo mount /dev/sdb1 /mnt/d1
$ sudo mount /dev/sdb2 /mnt/d2
Copy your running system to the new filesystems on the USB stick. In my case, I do not wish to copy any of the data in the Project
directory. Check it when it
finishes with the df
command.
$ sudo rsync -axvHAXW /boot/ /mnt/d1/
$ sudo rsync -axvHAXW --exclude 'Projects/*' / /mnt/d2/
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 917G 76G 795G 9% /
devtmpfs 442M 0 442M 0% /dev
tmpfs 446M 0 446M 0% /dev/shm
tmpfs 446M 6.2M 440M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 446M 0 446M 0% /sys/fs/cgroup
/dev/mmcblk0p1 41M 21M 20M 52% /boot
tmpfs 90M 0 90M 0% /run/user/1000
/dev/sda1 100M 21M 79M 22% /media/pi/boot
/dev/mmcblk0p2 30G 3.9G 24G 14% /media/pi/root
/dev/sdb1 100M 21M 79M 22% /mnt/d1
/dev/sdb2 15G 3.9G 9.9G 28% /mnt/d2
These steps will only test that root is running on the stick. The boot will still be from your regular boot SD card (/dev/mmcblk0p1). If this does not run root on the stick, something is wrong and you can recover without much effort. The only change to the boot SD card is putting the USB stick root PARTUUID as the root device. To recover, put the orginal root device back to the boot SD card.
$ sudo cp /boot/cmdline.txt /boot/cmdline.txt.bak
Get the PARTUUID from the stick and put them in the stick boot cmdline.txt
, in the stick etc/fstab
, and in the Pi /boot/cmdline.txt
.
$ sudo blkid /dev/sdb*
/dev/sdb: PTUUID="553f5f69" PTTYPE="dos"
/dev/sdb1: SEC_TYPE="msdos" LABEL="boot" UUID="360A-15E4" TYPE="vfat" PARTUUID="553f5f69-01"
/dev/sdb2: LABEL="root" UUID="99c067b7-16e9-4afe-a339-0261864e958c" TYPE="ext4" PARTUUID="553f5f69-02"
$ sudo vi /mnt/d1/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=553f5f69-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
$ sudo vi /mnt/d2/etc/fstab
proc /proc proc defaults 0 0
PARTUUID=553f5f69-01 /boot vfat defaults 0 2
PARTUUID=553f5f69-02 / ext4 defaults 0 1
$ sudo vi /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=553f5f69-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
A reboot will boot from the Pi boot SD and root will be running on the USB stick.
$ sudo reboot
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 14.9G 0 disk
├─sdb2 8:18 1 14.8G 0 part /
└─sdb1 8:17 1 100M 0 part /boot
sda 8:0 0 931.5G 0 disk
├─sda2 8:2 0 931.4G 0 part /media/pi/root
└─sda1 8:1 0 100M 0 part /media/pi/boot
mmcblk0 179:0 0 29.7G 0 disk
├─mmcblk0p2 179:2 0 29.7G 0 part /media/pi/root1
└─mmcblk0p1 179:1 0 41M 0 part /media/pi/boot1
If this works and you have already added program_usb_boot_mode=1
to the end of
/boot/config.txt
and rebooted (sudo reboot
) previous, then power off (shutdown -h now + uplug power
) and remove the Pi SD card and power on should get the USB stick boot.