├── README.md ├── stage1.sh ├── stage2.sh └── stage3.sh /README.md: -------------------------------------------------------------------------------- 1 | # Debian64Pi 2 | 64-bit Debian Buster images for the Raspberry Pi 3 and 4. 3 | 4 | There is no 'universal' image that supports both the Pi 3 and 4, you must download the Pi 3 image to run it on a Pi 3B/B+/A+ or the Pi 4 image if you want to run it on the Pi 4B. Hopefully I will be able to find a fix soon for this. 5 | 6 | The source code includes three stage scripts: stage1.sh sets up the image, installs Debian, modifies fstab, hostname, and sources.list, and installs the bootloader and kernel. stage2.sh installs core Debian packages into the image as well as WiFi drivers for the Pi's wireless capabilities. stage3.sh unmounts the mount points for the image, allowing the image to be flashed to your SD card. 7 | 8 | Default username: debian 9 | Default password: debian 10 | 11 | ## Build instructions 12 | 13 | Use qemu-img to create a blank image of at least 3.5GB (more needed if you intend on preinstalling a desktop environment with the image): 14 | 15 | qemu-img create debian-rpi64.img 3.5G 16 | 17 | sudo losetup -f -P --show debian-rpi64.img 18 | 19 | You will be given the name of the loopback device (eg, /dev/loop0). Open it in gparted: 20 | 21 | sudo gparted /dev/loop0 22 | 23 | Click device in the top menu of the window, then create partition table and select DOS. Then, for the first partition create a FAT32 partition about 70MB. For the second partition, create an ext4 partition taking up the rest of the image. Then click apply. 24 | 25 | Close the window and run: 26 | 27 | sudo mount /dev/loop0p2 /mnt 28 | 29 | sudo mkdir /mnt/boot 30 | 31 | sudo mount /dev/loop0p1 /mnt/boot 32 | 33 | Then, it's time to start the first script. Ensure your terminal session is working in the folder the image builder scripts are (using cd), and run: 34 | 35 | sudo ./stage1.sh 36 | 37 | By default, this script will setup the Pi 4 kernel, meaning it will not work on the Pi 3. To change it to the Pi 3, comment all the Pi 4 kernel install lines in the script and uncomment all the Pi 3 kernel install lines. This will break Pi 4 functionality however, as there is no current universal build support. 38 | 39 | The script will setup a minimal Debian installation as well as the kernel and everything on the image. Once it's finished, you will be in the chroot environment, so run: 40 | 41 | ./stage2.sh 42 | 43 | At some point you will be prompted for the keyboard configuration and to choose the password for the default user. You can tweak around if you want in stage2.sh, so if you're building a custom image for personal use you can change the username to something more personal and choose your own password when prompted. If building for public distribution you'll just want a username and password like debian. 44 | 45 | There is a commented line in stage2.sh allowing for the XFCE desktop task to be installed, including XFCE and recommended PC software. You can uncomment this if you want or change it to another desktop task (eg, task-lxde-desktop). You will need a large image for this though, as this will install a lot of software as well as the desktop as it is a task package. 46 | 47 | Once the script's finished you will not be automatically exited from the chroot, just in case you want to make any more customisations to your image. Once done, do exit the chroot with the 'exit' command. 48 | 49 | Finally, once exited, run: 50 | 51 | sudo ./stage3.sh 52 | 53 | This will setup Pi-specific WiFi drivers and unmount any mount points. After that, you can use an image flashing tool to flash to your microSD card 54 | 55 | -------------------------------------------------------------------------------- /stage1.sh: -------------------------------------------------------------------------------- 1 | # Setup ext4 root filesystem 2 | 3 | qemu-debootstrap --arch=arm64 buster /mnt 4 | 5 | mount -o bind /proc /mnt/proc 6 | mount -o bind /dev /mnt/dev 7 | mount -o bind /dev/pts /mnt/dev/pts 8 | mount -o bind /sys /mnt/sys 9 | 10 | # Make internet available from within the chroot, and setup fstab, hostname, and sources.list 11 | 12 | cp /etc/resolv.conf /mnt/etc/resolv.conf 13 | rm /mnt/etc/fstab 14 | rm /mnt/etc/hostname 15 | rm /mnt/etc/apt/sources.list 16 | echo "proc /proc proc defaults 0 0 17 | /dev/mmcblk0p1 /boot vfat defaults 0 2 18 | /dev/mmcblk0p2 / ext4 defaults,noatime 0 1" >> /mnt/etc/fstab 19 | 20 | echo "debian-rpi64" >> /mnt/etc/hostname 21 | 22 | echo "deb http://deb.debian.org/debian/ buster main contrib non-free 23 | #deb-src http://deb.debian.org/debian/ buster main contrib non-free 24 | 25 | deb http://deb.debian.org/debian/ buster-updates main contrib non-free 26 | #deb-src http://deb.debian.org/debian/ buster-updates main contrib non-free 27 | 28 | deb http://deb.debian.org/debian-security buster/updates main contrib non-free 29 | #deb-src http://deb.debian.org/debian-security buster/updates main contrib non-free 30 | 31 | deb http://ftp.debian.org/debian buster-backports main 32 | #deb-src http://ftp.debian.org/debian buster-backports main" >> /mnt/etc/apt/sources.list 33 | 34 | # Setup bootloader and kernel 35 | 36 | wget http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-bootloader_1.20190925-2_armhf.deb 37 | mkdir /tmp/pi-bootloader/ 38 | dpkg-deb -x raspberrypi-bootloader_1.20190925-2_armhf.deb /tmp/pi-bootloader/ 39 | cp /tmp/pi-bootloader/boot/* /mnt/boot/ 40 | rm raspberrypi-bootloader_1.20190925-2_armhf.deb 41 | 42 | wget https://github.com/sakaki-/bcm2711-kernel/releases/download/4.19.93.20200107/bcm2711-kernel-4.19.93.20200107.tar.xz 43 | mkdir /tmp/pi-kernel 44 | tar xf bcm2711-kernel-4.19.93.20200107.tar.xz -C /tmp/pi-kernel/ 45 | cp -r /tmp/pi-kernel/boot/* /mnt/boot/ 46 | mv /mnt/boot/kernel*.img /mnt/boot/kernel8.img 47 | mkdir /mnt/lib/modules 48 | cp -r /tmp/pi-kernel/lib/modules /mnt/lib/ 49 | rm bcm2711-kernel-4.19.93.20200107.tar.xz 50 | rm -r /tmp/pi-kernel 51 | 52 | ## Comment or remove completely the above kernel setup and uncomment the kernel setup below to setup the image to run on the Pi 3 instead of the Pi 4. 53 | 54 | #wget https://github.com/sakaki-/bcmrpi3-kernel/releases/download/4.19.89.20191224/bcmrpi3-kernel-4.19.89.20191224.tar.xz 55 | #mkdir /tmp/pi-kernel 56 | #tar xf bcmrpi3-kernel-4.19.89.20191224.tar.xz -C /tmp/pi-kernel/ 57 | #cp -r /tmp/pi-kernel/boot/* /mnt/boot/ 58 | #mkdir /mnt/lib/modules 59 | #cp -r /tmp/pi-kernel/lib/modules /mnt/lib/ 60 | #rm bcmrpi3-kernel-4.19.89.20191224.tar.xz 61 | #rm -r /tmp/pi-kernel 62 | 63 | # Setup config.txt and cmdline.txt 64 | 65 | echo "disable_overscan=1 66 | #dtoverlay=vc4-fkms-v3d" >> /mnt/boot/config.txt 67 | 68 | echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait" >> /mnt/boot/cmdline.txt 69 | 70 | # Copy stage2 to chroot environment 71 | 72 | cp stage2.sh /mnt/ 73 | echo "Run stage2.sh in chroot for stage 2." 74 | chroot /mnt 75 | -------------------------------------------------------------------------------- /stage2.sh: -------------------------------------------------------------------------------- 1 | # Apt install core packages 2 | 3 | apt update 4 | apt upgrade -y 5 | apt install console-setup keyboard-configuration sudo ssh curl wget dbus usbutils ca-certificates crda less fbset debconf-utils avahi-daemon fake-hwclock nfs-common apt-utils man-db pciutils ntfs-3g apt-listchanges -y 6 | apt install wpasupplicant wireless-tools firmware-atheros firmware-brcm80211 firmware-libertas firmware-misc-nonfree firmware-realtek dhcpcd5 net-tools -y 7 | 8 | # Uncomment one of these to install a Desktop Environment 9 | 10 | #apt install task-xfce-desktop -y # For XFCE 11 | #apt install task-gnome-desktop -y # For GNOME 12 | #apt install task-kde-desktop-y # For KDE Plasma 13 | #apt install task-mate-desktop -y # For MATE 14 | #apt install task-lxde-desktop -y # For LXDE 15 | #apt install task-lxqt-desktop -y # For LXQT 16 | 17 | # Setup default user; this step does require a bit of user interaction for password and user info 18 | 19 | adduser debian 20 | usermod -aG sudo,video,audio,cdrom debian 21 | echo "Now, exit the chroot and run stage3.sh." 22 | -------------------------------------------------------------------------------- /stage3.sh: -------------------------------------------------------------------------------- 1 | # Install Pi-compatible WiFi drivers to image 2 | 3 | mkdir wifi-firmware 4 | cd wifi-firmware 5 | wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43430-sdio.bin 6 | wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43430-sdio.clm_blob 7 | wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43430-sdio.txt 8 | wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.bin 9 | wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.clm_blob 10 | wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.txt 11 | cp *sdio* /mnt/lib/firmware/brcm/ 12 | cd .. 13 | rm -rf wifi-firmware 14 | 15 | # Remove stage2.sh from root and unmount filesystem and mount points 16 | 17 | rm /mnt/stage2.sh 18 | umount /mnt/proc 19 | umount /mnt/sys 20 | umount /mnt/dev/pts 21 | umount /mnt/dev -l 22 | umount /mnt/boot 23 | umount /mnt -l --------------------------------------------------------------------------------