Raspberry 4 with SSD

AJA • March 29, 2020

raspberry

Raspbian is a free operating system based on Debian, optimised for the Raspberry Pi hardware. The raspberry 4 doesn’t yet support SSD booting, we present a workaround to use a SSD disk devices as your rootfs device.

Rasbian image

From the Raspberry Pi website download the latest version with desktop and recommended software.

Flash the SD card

Download and launch the portable version of Balena Etcher select the previously downloaded image and flash your SD card.

Enable SSH

To enable SSH you need to place an empty file named ssh (no extension) in the root of the boot disk on the SD card.

Flash the SSD disk

Next flash the same image to the SSD but do not connect the SSD.

Connect with putty

First connect in SSH with putty using pi as user and raspberry as password.

Connect your SSD disk

Once connected with putty plug in your SSD disk.

Change the SSD PARTUUID

We need to change the PARTUUID of our SSD’s partitions so the Pi doesn’t get confused about what device to boot from. Right now the partitions on both the SD card and the SSD are an exact match and we need them to be different so we can tell the Pi to boot specifically from our SSD’s partition.

First we use blkid to locate the block devices attributes.

sudo blkid

/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="9969-E3D2" TYPE="vfat" PARTUUID="97709164-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="8f2a74a4-809c-471e-b4ad-a91bfd51d7c3" TYPE="ext4" PARTUUID="97709164-02"
/dev/mmcblk0: PTUUID="97709164" PTTYPE="dos"
/dev/sda1: LABEL_FATBOOT="boot" LABEL="boot" UUID="9969-E3D2" TYPE="vfat" PARTUUID="97709164-01"
/dev/sda2: LABEL="rootfs" UUID="8f2a74a4-809c-471e-b4ad-a91bfd51d7c3" TYPE="ext4" PARTUUID="97709164-02"

Next we are going to use fdisk to change the SSD’s PARTUUID to the hexadecimal d33dd34f to make our SSD easy to identify.

sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 465,8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: SSD 860 EVO 500G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x97709164

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1         8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/sda2       532480 14303231 13770752  6,6G 83 Linux

Command (m for help):x

Expert command (m for help): i

Enter the new disk identifier: 0xd33dd34f

Disk identifier changed from 0x97709164 to 0xd33dd34f.

Expert command (m for help): r

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Verify the change with blkid.

sudo blkid

/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="9969-E3D2" TYPE="vfat" PARTUUID="97709164-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="8f2a74a4-809c-471e-b4ad-a91bfd51d7c3" TYPE="ext4" PARTUUID="97709164-02"
/dev/sda1: LABEL_FATBOOT="boot" LABEL="boot" UUID="9969-E3D2" TYPE="vfat" PARTUUID="d33dd34f-01"
/dev/sda2: LABEL="rootfs" UUID="8f2a74a4-809c-471e-b4ad-a91bfd51d7c3" TYPE="ext4" PARTUUID="d33dd34f-02"
/dev/mmcblk0: PTUUID="97709164" PTTYPE="dos"

Update /boot/cmdline.txt

We are going to change cmdline.txt to point to the SSD for booting instead of the SD card. First make a backup of your existing cmdline.txt and edit it with nano then change PARTUUID. Next change the PARTUUID with the new value d33dd34f-02 adn reboot.

sudo cp /boot/cmdline.txt /boot/cmdline.txt.bak
sudo nano /boot/cmdline.txt

Change the PARTUUID with the new value.

console=serial0,115200 console=tty1 root=PARTUUID=d33dd34f-02 rootfstype=ext4 e$

Shudown the raspberry

sudo shutdown -h 0

Enable SSH again

To enable SSH again you need to place an empty file named ssh (no extension) in the root of the boot disk on the SD card.

Remove the SD card, add the ssh file at the root of the boot disk and boot again.

First boot

The first boot with your SSD can be slow due to running fsck on the drive.

Verify the SSD

After connecting to the raspberry using putty verify that the SSD is being used.

findmnt -n -o SOURCE /

 /dev/sda2

Configure the raspberry

sudo raspi-config

Change passaword.

In Networdk Options change hostname.

In interfacing options add SSH and VNC.

Reboot the raspberry

sudo reboot

Update /etc/fstab

We are now ready to edit the /etc/fstab file to point to our updated drive and reboot.

sudo nano /etc/fstab

proc                  /proc  proc  defaults  0  0
PARTUUID=97709164-01  /boot  vfat  defaults  0  2
PARTUUID=d33dd34f-02  /      ext4  defaults,noatime  0  1

Reboot the raspberry

sudo reboot

Resize the filesystem

With fdisk delete the second partition and recreate it keeping the same First sector and the default Last sector.

sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 465,8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: SSD 860 EVO 500G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x97709164

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1         8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/sda2       532480 14303231 13770752  6,6G 83 Linux

Command (m for help): d
Partition number (1,2, default 2):2

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (532480-976773167, default 589815): 532480
Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-976773167, default 976773167):

Created a new partition 2 of type 'Linux' and of size 465,5 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): w

The partition table has been altered.
Syncing disks.

Reboot the raspberry

sudo reboot

Resize the file system

Next resize the file system and check the new size.

sudo resize2fs /dev/sda2

resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 30
The filesystem is already 122030086 (4k) blocks long.

Verify the new file system size with df

df -h

Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
/dev/root          459G    5,8G  434G   2% /
devtmpfs           841M       0  841M   0% /dev
tmpfs              970M       0  970M   0% /dev/shm
tmpfs              970M    8,6M  962M   1% /run
tmpfs              5,0M    4,0K  5,0M   1% /run/lock
tmpfs              970M       0  970M   0% /sys/fs/cgroup
/dev/mmcblk0p1     253M     53M  200M  21% /boot
tmpfs              194M       0  194M   0% /run/user/1000
/dev/sda1          253M     53M  200M  21% /media/pi/boot
/dev/mmcblk0p2      15G    5,7G  8,1G  42% /media/pi/rootfs

Run apt-get upadte and dist-upgrade

sudo apt-get update
sudo apt-get dist-upgrade

Connect with vncviewer

Launch the raspbian config and activate VNC from the interfacing options menu using raspi-config.

sudo raspi_config

Download vncviewer and connect to the raspberry using your local IP address.

Run setup wizard

The setup wizard should start, if not run piwiz.

sudo piwiz