Raspberry Pi – M.2 SSD drive setup with an SD card

  Uncategorized

Useful on setting up something like this M.2 SSD on this Raspberry Pi:

Aluminium Pi 4 NAS Case with Low-Profile ICE Tower Cooler

# Raspberry Pi setup for a new M.2 SSD drive, by first booting off 
# an SD card, and then cloning the SD card to the M.2 SSD card
sudo apt install rpi-imager
rpi-imager

# also see: https://www.youtube.com/watch?v=a8nzkLryGmM

# ssh from an Ubuntu system to the Raspberry Pi, use -X for window forwarding
ssh -X pi@10.1.10.246

# update boot loader
sudo rpi-eeprom-update -d -a

# if you see this: EEPROM updates pending. Please reboot to apply the update.
# then reboot
sudo reboot

# log in after reboot
ssh -X pi@10.1.10.246

# ideally we'd like to run gnome-utils and piclone as root, 
# using: sudo -E env DISPLAY=:0 gnome-disks
# but this may not work

sudo su
passwd
# change the root password so that you know what it is


# edit sshd config
sudo nano /etc/ssh/sshd_config

# add temporary root login with password - at the bottom of the file add:
PermitRootLogin yes

# restart ssh
sudo systemctl restart ssh

# ssh as root with password
ssh -X root@10.1.10.246

# to test if ssh -X works, install apps such as xclock
sudo apt install x11-apps

# test it
xclock

# if it comes up, you can ssh with X forwarding, as root

# next, run gnome-disks
sudo apt-get install gnome-disk-utility
gnome-disks

# format the SSD drive as FAT
# if successful, exit program

# Next, run the Raspberry Pi SD Card Copier GUI, 
# which is actually just "piclone"
piclone

# clone the small boot card to the SSD drive, you need to 
# select the checkbox: New Partition UUIDs, click Start

# let it finish, even if there are "fdisk: write error" 
# messages. If it's a large SSD, it'll take a while.

# this can take 10 minutes

# SD card is now cloned onto M.2 SSD disk

# tell pi to boot from SSD instead
sudo raspi-config
	Advanced Options
	Bootloader Version
	Latest
	Reset boot ROM to defaults? select NO!

# then select boot order

	Advanced Options
	Boot Order
	NVMe/USB Boot
	
# Reboot? -> Select NO	
	
# shut down manually without rebooting
sudo shutdown now

# remove power cable

# remove SD card

# power up pi - it'll boot using the M.2 SSD

# undo the root login setup from earlier

# edit sshd config
sudo nano /etc/ssh/sshd_config

# Remove this line
PermitRootLogin yes

# restart ssh
sudo systemctl restart ssh