feelslikeautumn
Posts: 257
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

#!/bin/sh
# 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
EOF

# 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
kernel=vmlinuz
initramfs initrd.gz followkernel

[pi2]
device_tree=bcm2836-rpi-2-b.dtb
[pi3]
device_tree=bcm2837-rpi-3-b.dtb
[pi3+]
device_tree=bcm2837-rpi-3-b-plus.dtb
[all]

EOF

# 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
sync
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
EOF

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{ / } .
EOF

cat <<'STOP' > pi_late_command 
#!/bin/sh
# 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
fi

# 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'*)
		dtb="bcm2836-rpi-2-b.dtb"
	;;
	'Raspberry Pi 3 Model B Plus'*)
		dtb="bcm2837-rpi-3-b-plus.dtb"
	;;
	'Raspberry Pi 3 Model B'*)
		dtb="bcm2837-rpi-3-b.dtb"
	;;
	*)
		logger -t late_command "Unknown model"
		exit 1
esac

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
EOF

# 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
fi
umount /target/dev || true

logger -t late_command "flash-kernel successful"
STOP

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

dearch
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+?

feelslikeautumn
Posts: 257
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.

User avatar
boomonster
Posts: 70
Joined: Fri May 11, 2018 11:18 pm

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

Thu Nov 29, 2018 12:26 am

Instead of the buster netinst, I downloaded the stretch stable netinst & the stretch stable DVD 1. I want to use
the DVD, so I do not need to use the internet. However, the DVD is over 4 gb, so I cannot copy the file to the usb
drive...

Is there any workaround?

Thanks,
Boomonster

feelslikeautumn
Posts: 257
Joined: Wed Aug 09, 2017 9:51 pm

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

Thu Nov 29, 2018 9:13 am

I'm not massively familiar with Debian CDs/dvds, but I would expect you only need the dvd. Instead of copying the iso file you can extract it's contents to the usb drive. For example if the usb drive is mounted at /mnt:

Code: Select all

sudo cp -rT /tmp/installer-iso /mnt
Any references to "hd-media" in the script will need to be replaced with "cdrom".

Note, it is possible to use wi-fi with the Debian installer if an Ethernet connection is the issue.

Hope that helps!

code_exec
Posts: 135
Joined: Sun Sep 30, 2018 12:25 pm

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

Fri Nov 30, 2018 6:19 am

boomonster wrote:
Thu Nov 29, 2018 12:26 am
Instead of the buster netinst, I downloaded the stretch stable netinst & the stretch stable DVD 1. I want to use
the DVD, so I do not need to use the internet. However, the DVD is over 4 gb, so I cannot copy the file to the usb
drive...

Is there any workaround?

Thanks,
Boomonster
It's most likely the ISO that is 4GB in total, and not one of the files on the ISO. Simply mount the ISO to a temporary folder and then copy the contents of the ISO across. Copying the ISO file itself and nothing else isn't good enough.
Pi386 lets you run 32-bit x86 software on the Raspberry Pi, including WINE!

https://www.raspberrypi.org/forums/viewtopic.php?t=226376

feelslikeautumn
Posts: 257
Joined: Wed Aug 09, 2017 9:51 pm

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

Fri Nov 30, 2018 9:10 am

code_exec wrote:
Fri Nov 30, 2018 6:19 am
Copying the ISO file itself and nothing else isn't good enough.
The above script extracts the kernel/initrd/dtb files from the iso. With these and the pi's bootloader files you can boot the iso file without extracting everything. A bit like how you can boot a 'live' desktop iso using grub2's loopback feature. The Debian installer scans drives looking for an iso file. A way around the 4gb file size would be to place it on another usb drive that is formatted in something other than fat.
Simply mount the ISO to a temporary folder and then copy the contents of the ISO across.
This works too. The one 'gotcha' is often you need a hidden '.disk' folder so you must make sure you copy that. As I posted above, if you are using the script's preseed files then you need to edit out hd-media.

code_exec
Posts: 135
Joined: Sun Sep 30, 2018 12:25 pm

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

Fri Nov 30, 2018 1:02 pm

But who needs Debian armhf, when you can run Debian ARM64 on the Pi 3?

I had to compile the Pi's kernel for 64-bit, use debootstrap to install a minimal Debian ARM64 base, edit the /etc/fstab file to point to the correct locations, and install the kernel modules. After that, Debian ARM64 booted successfully and I was able to install the XFCE desktop with an Ethernet connection.

Image

Expect an image to be released soon preloaded with Debian ARM64.
Pi386 lets you run 32-bit x86 software on the Raspberry Pi, including WINE!

https://www.raspberrypi.org/forums/viewtopic.php?t=226376

User avatar
boomonster
Posts: 70
Joined: Fri May 11, 2018 11:18 pm

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

Tue Dec 04, 2018 2:49 am

I need armhf because my pi is still the "old" & "outdated" Pi 2 B!

code_exec
Posts: 135
Joined: Sun Sep 30, 2018 12:25 pm

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

Tue Dec 04, 2018 10:00 am

boomonster wrote:
Tue Dec 04, 2018 2:49 am
I need armhf because my pi is still the "old" & "outdated" Pi 2 B!
Oh okay. I'll see if I can build a Debian armhf image that works on the Pi 2 (as well as the Pi 3) in the upcoming days.

I don't own a Pi 2, so I'll test the image on my Pi 3B. Once the image is released, feedback from Pi 2 users would be appreciated!
Pi386 lets you run 32-bit x86 software on the Raspberry Pi, including WINE!

https://www.raspberrypi.org/forums/viewtopic.php?t=226376

User avatar
boomonster
Posts: 70
Joined: Fri May 11, 2018 11:18 pm

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

Wed Dec 05, 2018 12:40 am

I find installing OSes fun!
P.S. I possibly won't test your (futuristic) image, because
I want to use the DVD so I don't have to use so much internet!
I have the DVD, and I don't like downloading so many big files...

Return to “Debian”