├── Instructions.md
└── README.md
/Instructions.md:
--------------------------------------------------------------------------------
1 | # Building Debian image yourself
2 |
3 | You can build the image yourself using debootstrap if you're building on an ARM64 host and qemu-debootstrap if you're building on a x64 host.
4 |
5 | ## Building root filesystem
6 |
7 | First of all, you'll need to install the dependencies for building:
8 |
9 | sudo apt install debootstrap
10 |
11 | sudo apt install debian-archive-keyring
(only run this command if you are on an Ubuntu host)
12 |
13 | If you're on a x64 host, you'll also need to install QEMU User Mode Emulation packages:
14 |
15 | sudo apt install qemu-user-static binfmt-support
16 |
17 | After this, you’ll need to create a blank image file. This tutorial assumes that you want to create a minimal Debian install that does not have a desktop environment by default.
18 |
19 | dd if=/dev/zero of=debian-rpi3.img iflag=fullblock bs=1M count=3800 status=progress
20 |
21 | Adjust the size by replacing 3800 with the amount of megabytes you want your image to be. For example, to create an image for use on an 8GB storage device, run:
22 |
23 | dd if=/dev/zero of=debian-rpi3.img iflag=fullblock bs=1M count=7800 status=progress
24 |
25 | Now, mount the image as a loopback device:
26 |
27 | sudo losetup -f -P --show debian-rpi3.img
28 |
29 | The output will tell you the name of the loopback device (eg, /dev/loop13).
30 |
31 | If you don’t have GParted installed, install the gparted package with apt. Then, run:
32 |
33 | sudo gparted /dev/[name of loopback device]
34 |
35 | After that, you’ll need to create a partition table and then create partitions. Select the unallocated space on the loopback device, and click on the Device menu, and then create a partition table. Leave the partition table type as msdos. The first partition must be formatted as FAT32 or FAT16 and will contain the bootloader files needed for the Pi to boot. The second one must be formatted as ext4 and will contain the Debian filesystem. Apply the operations and exit GParted.
36 |
37 | Now, mount the loopback device:
38 |
39 | sudo mount /dev/[name of loopback device]p2 /mnt
40 |
41 | sudo mkdir /mnt/boot
42 |
43 | sudo mount /dev/[name of loopback device]p1 /mnt/boot
44 |
45 | By default, loopback devices are mounted as noexec, meaning that you cannot execute commands within them. Remount the device with the ‘exec’ and ‘dev’ flags to remove this restriction:
46 |
47 | sudo mount -i -o remount,exec,dev /mnt
48 |
49 | Now, install a minimal Debian system onto the ext4 partition. If you’re building on ARM64, run:
50 |
51 | sudo debootstrap --arch=arm64 stretch /mnt
52 |
53 | If you’re building on x64, run:
54 |
55 | sudo qemu-debootstrap --arch=arm64 stretch /mnt
56 |
57 | This will take a bit of time depending on your internet connection.
58 |
59 | Once it’s done, chroot into your ext4 filesystem:
60 |
61 | sudo mount -o bind /proc /mnt/proc
62 |
63 | sudo mount -o bind /sys /mnt/sys
64 |
65 | sudo mount -o bind /dev /mnt/dev
66 |
67 | sudo mount -o bind /dev/pts /mnt/dev/pts
68 |
69 | sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
70 |
71 | sudo chroot /mnt
72 |
73 | Install ca-certificates, dbus, sudo packages:
74 |
75 | apt install ca-certificates dbus sudo
76 |
77 | Restart the dbus service:
78 |
79 | service dbus restart
80 |
81 | Now, replace /etc/fstab with the following:
82 |
83 | proc /proc proc defaults 0 0
84 |
85 | /dev/mmcblk0p1 /boot vfat defaults 0 2
86 |
87 | /dev/mmcblk0p2 / ext4 defaults,noatime 0 1
88 |
89 | If you plan on using this image on a USB stick or hard drive rather than a microSD card, you’ll need to have programmed the OTP to boot from a USB external device if no microSD is found beforehand (this is unnecessary on the Pi 3B+ as USB booting is already on by default). To configure Debian to boot from USB, put the following in your /etc/fstab instead:
90 |
91 | proc /proc proc defaults 0 0
92 |
93 | /dev/sda1 /boot vfat defaults 0 2
94 |
95 | /dev/sda2 / ext4 defaults,noatime 0 1
96 |
97 | Install firmware and networking packages:
98 |
99 | apt install wpasupplicant wireless-tools firmware-atheros firmware-brcm80211 firmware-libertas firmware-misc-nonfree firmware-realtek dhcpcd5 net-tools
100 |
101 | Some of the WiFi firmware included in the firmware-brcm80211 package are incompatible with the Pi. Pi-compatible WiFi drivers can be downloaded by following the instructions on the Ubuntu Wiki.
102 |
103 | Now, run the following commands to enable networking:
104 |
105 | systemctl enable systemd-networkd.service
106 |
107 | systemctl enable systemd-resolved.service
108 |
109 | After that, create a user. If you’re creating an image for distribution purposes, use a username such as debian. If you’re creating an image for personal use and do not plan on distributing it, use a personal username:
110 |
111 | adduser [username]
112 |
113 | usermod –aG sudo [username]
114 |
115 | By default, debootstrap sets the hostname of your filesystem to the same hostname as the host you're building on. To change your image's hostname to something else, run the following:
116 |
117 | nano /etc/hostname
118 |
119 | and replace your host's hostname with something else (such as debian-rpi3).
120 |
121 | You may optionally install a desktop environment as well:
122 |
123 | apt install xfce4 # For XFCE
124 |
125 | apt install lxde # For LXDE
126 |
127 | apt install mate-desktop-environment # For MATE
128 |
129 | apt install kde-plasma-desktop # For KDE Plasma
130 |
131 | Once done, exit the chroot environment with the ‘exit’ command.
132 |
133 | ## Building ARM64 kernel
134 |
135 | The first thing the Raspberry Pi does upon boot is try to locate a FAT partition that contains the bootloader files, and then loads these files. The bootloader search for an ext4 partition and then tries to load the Linux OS from it.
136 |
137 | You can download the latest firmware by running one the following commands:
138 |
139 | git clone https://github.com/raspberrypi/firmware.git
140 |
141 | The bootloader files are stored in firmware/boot. Copy all of these files across to the FAT partition found at /mnt/boot. After that, you’ll need to compile a 64-bit kernel and install kernel modules. There’s a nice guide for this here: https://devsidestory.com/build-a-64-bit-kernel-for-your-raspberry-pi-3/
142 |
143 | ## Installing and booting Debian
144 |
145 | Once you’ve compiled the kernel and copied it to the FAT partition, and installed the kernel modules to the ext4 partition, you should be good to go! Unmount the ext4 and FAT partitions with the following commands:
146 |
147 | sudo umount /mnt/boot
148 |
149 | sudo umount /mnt
150 |
151 | sudo losetup –d debian-rpi3.img
152 |
153 | Now, flash the Debian image file to your Pi’s microSD card or USB storage device. First, find out what the device name of your microSD card or USB storage device. To find out, run sudo fdisk –l and look for the device that has similar properties to your storage device. For example, if you have an 8GB storage device, a 7.9GB device may be your storage device.
154 |
155 | Once you’ve found out the device name of your storage device, flash the image file to it with the following command:
156 |
157 | sudo dd if=debian-rpi3.img of=/dev/[device name] bs=4M status=progress
158 |
159 | Once the image has finished being flashed, remove the storage device from your PC and put it into the Pi, and plug in the Pi’s power supply. The Pi should boot to the login prompt, where you can sign into the user account you created earlier.
160 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Debian64Pi
2 | 64-bit Debian Stretch for the Raspberry Pi 3
3 |
4 | These images are various flavours of Debian Stretch that run on the Pi. These are built upon the Debian ARM64 base and are not based on Raspbian. These images will work on the Pi 3B, 3B+, and revision 1.2 of the Pi 2.
5 |
6 | ## Status
7 | *Keyboard, mouse, Wi-Fi, and Ethernet are working.
8 |
9 | *MATE desktop loaded successfully and can load applications such as Chromium and LibreOffice.
10 |
11 | *Multiarch in dpkg works -- can add armhf as a secondary architecture and load armhf programs.
12 |
13 | *Snaps can be installed after installing snapd.
14 |
15 | ## Desktop Environment
16 | Currently, images with the MATE and XFCE desktop environments are available from the Releases section of this page. I plan on releasing images pre-loaded with the following desktop environments in the future:
17 |
18 | *LXDE
19 |
20 | *LXQT
21 |
22 | *KDE Plasma
23 |
24 | ## Troubleshooting
25 |
26 | ### My Pi hangs on the rainbow screen.
27 |
28 | This is the issue you face when you are using an unsupported Pi model. Your Pi model MUST have the BCM2837 SoC for this image to work.
29 |
--------------------------------------------------------------------------------