Posts: 250
Joined: Wed Aug 09, 2017 9:51 pm

HOWTO: Install debian armhf on Pi 2/3

Fri Jun 15, 2018 10:46 pm

There doesn't seem to be a lot of information on how to do this, and what there is seems very out of date (I'm looking at you debian wiki pages!). I'm not a debian user, this is just a happy spin off of the installers I have previously made for ubuntu (viewtopic.php?f=56&t=209763 ) and raspbian (viewtopic.php?t=195162 ).

Below is a script that you can use to create debian installation media. It downloads the latest released pi bootloader files, the buster netinst.iso, and generates the preseed and config files to make it all work. Once all files have been downloaded/created, copy them to a fat formatted usb drive.

To temporarily enable usb booting on the pi 2 or on the pi3, copy the bootcode.bin file to an SD card. You must still have bootcode.bin on the usb drive as it is used by the installer. Place the SD card and usb drive in the pi and turn on.

The pi3B+ has usb booting enabled by default, but at the time of writing there is no dtb file for the pi 3B+.

The debian-installer will start eventually after a long pause at the rainbow screen and you can install to the SD card, or another usb drive.

No swap partition is created by default. Using a swapfile or using zram are better, but you'll have to sort them out yourself. As you will getting wifi/bluetooth to work (see https://wiki.ubuntu.com/ARM/RaspberryPi#WiFi for wifi). The package flash-kernel is used to copy the kernel,initrd and dtb file to the fat partition (mounted at /boot/firmware). This is usually combined with u-boot, but that isn't done here, but it is something else you could set up if you wish.

Code: Select all

# Construct a debian armhf installer for the Pi2 and Pi3B.

set -e

# Download the latest pi bootloader files
wget http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-bootloader_1.20180417-1_armhf.deb
dpkg-deb -x raspberrypi-bootloader_1.20180417-1_armhf.deb /tmp/pi-bootloader

mkdir pi-installer
cd pi-installer

# Copy the bootloader files
sudo cp /tmp/pi-bootloader/boot/* .

# The cmdline.txt (adjust as necessary)
cat <<'EOF' > cmdline.txt
file=/hd-media/preseed/pi.seed --- quiet net.ifnames=0

# The config.txt
cat <<'EOF' > config.txt
# For more options and information see:
# https://www.raspberrypi.org/documentation/configuration/config-txt/README.md

# Kernel and initramfs
initramfs initrd.gz followkernel



# Run 'unix2dos config.txt' if you want it readable in windows

# Download iso
wget https://cdimage.debian.org/cdimage/weekly-builds/armhf/iso-cd/debian-testing-armhf-netinst.iso

# Extract kernel, initrd and device tree files from iso 
# These are also available at http://ftp.uk.debian.org/debian/dists/buster/main/installer-armhf/current/images/ 
mkdir /tmp/installer-iso
sudo mount -o loop,ro debian-testing-armhf-netinst.iso /tmp/installer-iso
cp /tmp/installer-iso/install/hd-media/vmlinuz .
cp /tmp/installer-iso/install/hd-media/initrd.gz .
cp /tmp/installer-iso/install/device-tree/bcm2836-rpi-2-b.dtb .
cp /tmp/installer-iso/install/device-tree/bcm2837-rpi-3-b.dtb .
#cp /tmp/installer-iso/install/device-tree/bcm2837-rpi-3-b-plus.dtb
sudo umount /tmp/installer-iso

# Create preseed files
mkdir preseed
cd preseed

cat <<'EOF' > pi.seed 
# The partitioning scheme to be used
d-i partman-partitioning/default_label select msdos
d-i partman-auto/expert_recipe_file string /hd-media/preseed/pi_recipe

# Kernel options to be used for the insalled system (added to those used with the installer)
d-i debian-installer/add-kernel-opts string ro elevator=deadline fsck.repair=yes rootwait cma=64M

# We'll use the pi's own bootloader
d-i grub-installer/skip boolean true

# Don't pause for the "No boot loader installed" message
d-i nobootloader/confirmation_common note

# Setup fat partition (replicates the work of flash-kernel-installer)
d-i preseed/late_command string /hd-media/preseed/pi_late_command

cat <<'EOF' > pi_recipe 
raspberrypi ::

128 128 128 fat32
	$primary{ }
	$bootable{ }
	method{ format }
	format{ }
	use_filesystem{ }
	filesystem{ fat32 }
	label{ boot-part }
	mountpoint{ /boot/firmware } .

900 10000 -1 $default_filesystem
	$lvmok{ }
	$primary{ }
	method{ format }
	format{ }
	use_filesystem{ }
	$default_filesystem{ }
	label{ root-part }
	mountpoint{ / } .

cat <<'STOP' > pi_late_command 
# Install Raspberry Pi firmware.  Written by Adam Smith

set -e

findfs () {
	mount | grep "on /target${1%/} " | tail -n1 | cut -d' ' -f1

logger -t late_command "Removing cups-filters.conf"

# The Pi doesn't have a parallel port
rm /target/etc/modules-load.d/cups-filters.conf || true

logger -t late_command "Copying bootloader files"

# Copy bootloader files
cp /hd-media/bootcode.bin /target/boot/firmware/
cp /hd-media/fixup*.dat /target/boot/firmware/
cp /hd-media/start*.elf /target/boot/firmware/
cp /hd-media/config.txt /target/boot/firmware/

# Update config.txt
sed -i 's/^kernel=.*/kernel=vmlinuz/g' /target/boot/firmware/config.txt
sed -i 's/^initramfs .*/initramfs initrd.img followkernel/g' /target/boot/firmware/config.txt

# Create cmdline.txt file
user_params="$(echo $(user-params))" || true
vol_id=$(blkid -o value -s UUID $(findfs /))
echo "root=UUID=$vol_id $user_params" > /target/boot/firmware/cmdline.txt

logger -t late_command "Running flash-kernel ..."

if ! apt-install flash-kernel u-boot-tools; then
	logger -t late_command "error: apt-install flash-kernel u-boot-tools failed"
	exit 1

# Add entry to flash-kernel database
machine="$(cat /proc/device-tree/model)"

# Make a guess about the dtb file to use
case "$machine" in
	'Raspberry Pi 2 Model B'*)
	'Raspberry Pi 3 Model B Plus'*)
	'Raspberry Pi 3 Model B'*)
		logger -t late_command "Unknown model"
		exit 1

cat <<EOF >> /target/etc/flash-kernel/db

# Automatically added by the installer
Machine: $machine
DTB-Id: $dtb
Boot-DTB-Path: /boot/firmware/$dtb
Boot-Kernel-Path: /boot/firmware/vmlinuz
Boot-Initrd-Path: /boot/firmware/initrd.img

# Use flash-kernel to copy kernel, initrd.img, dtb file, etc to the boot partition
mount -o bind /dev /target/dev
if ! in-target flash-kernel; then
	# Run out of space on boot partition or missing dtb file?
	logger -t late_command "error: flash-kernel failed"
	umount /target/dev || true
	exit 1
umount /target/dev || true

logger -t late_command "flash-kernel successful"

# Finished!
# Copy all files in the pi-installer directory (including the iso file) to a fat formatted usb drive.

Posts: 1
Joined: Sat Jun 23, 2018 3:51 pm

Re: HOWTO: Install debian armhf on Pi 2/3

Sun Jun 24, 2018 9:37 am

at the time of writing there is no dtb file for the pi 3B+.
Does that mean that this guide doesn't currently work for the Pi 3B+?

Posts: 250
Joined: Wed Aug 09, 2017 9:51 pm

Re: HOWTO: Install debian armhf on Pi 2/3

Sun Jun 24, 2018 11:13 am

Yep, but you could provide your own dtb file and adjust the script.

Return to “Debian”