Forked from G-UK/Debootstrap Debian Arm64 OS for Raspberry Pi 3 & 4.md
Last active
March 21, 2022 14:04
-
-
Save nexus166/751ed863028f028621d41b2d50a4caa5 to your computer and use it in GitHub Desktop.
Build a 64bit Debian OS for the Raspberry Pi using Debootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -xeo pipefail; | |
| IMAGE_SIZE=2000M | |
| BOOT_SIZE=256M | |
| IMAGE_ARCH=arm64 | |
| while getopts "s:" option; do | |
| case $option in | |
| a) | |
| IMAGE_ARCH="${OPTARG}"; | |
| ;; | |
| b) | |
| BOOT_SIZE="${OPTARG}"; | |
| ;; | |
| s) | |
| IMAGE_SIZE="${OPTARG}"; | |
| ;; | |
| :) | |
| echo "option ${OPTARG} requires an argument"; | |
| ;; | |
| ?) | |
| exit 1; | |
| ;; | |
| esac; | |
| done | |
| shift $(($OPTIND - 1)); | |
| _rname=$(openssl rand -hex 8); | |
| truncate -s${IMAGE_SIZE} ${_rname}.img; | |
| sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${_rname}.img | |
| p | |
| o # delete all | |
| n # NEW /boot /dev/xxx1 | |
| p # primary partition | |
| 1 # partition number 1 | |
| # auto first sector | |
| +${BOOT_SIZE} # arg size /boot part | |
| a # make partition bootable | |
| p | |
| n # NEW / /dev/xxx2 | |
| p # primary partition | |
| 2 # partion number 2 | |
| # auto first sector | |
| # auto part2 size 100% | |
| p | |
| w # write the partition table | |
| q | |
| EOF | |
| unset EOF; | |
| _lofree=$(losetup -f); | |
| losetup -P ${_lofree} ${_rname}.img; | |
| trap 'umount -r ./mnt; umount -r ${_lofree}; losetup -d ${_lofree}; rm -vf ${_rname}.img' ERR; | |
| mkfs.vfat "${_lofree}p1"; | |
| mkfs.ext4 "${_lofree}p2"; | |
| partprobe ${_lofree}; | |
| fdisk -l ${_lofree}; | |
| rm -vrf ./mnt; | |
| mkdir mnt; | |
| mount ${_lofree}p2 ./mnt; | |
| mkdir -vp mnt/boot; | |
| mount ${_lofree}p1 ./mnt/boot; | |
| debootstrap --include=apt-utils,ca-certificates,gnupg,less,locales,nano,netbase,ntp,ifupdown,inetutils-ping,iproute2,irqbalance,openssh-server,passwd,psmisc,sudo,sysvinit-core,wget,whiptail,wpasupplicant --arch="${IMAGE_ARCH}" buster ./mnt "http://deb.debian.org/debian"; | |
| if [[ "${IMAGE_ARCH}" == "arm64" ]]; then | |
| cp -v $(which qemu-aarch64-static) ./mnt/usr/bin/; | |
| else | |
| cp -v $(which qemu-${IMAGE_ARCH}-static) ./mnt/usr/bin/; | |
| fi | |
| mount -t proc /proc ./mnt/proc/; | |
| mount -t sysfs /sys ./mnt/sys/; | |
| mount -o bind /dev ./mnt/dev/; | |
| printf 'deb http://deb.debian.org/debian stable main contrib non-free | |
| deb http://deb.debian.org/debian stable-updates main contrib non-free | |
| deb http://security.debian.org/ stable/updates main contrib non-free' | tee ./mnt/etc/apt/sources.list; | |
| cat <<EOF | LANG=C.UTF-8 TERM=xterm DEBIAN_FRONTEND=noninteractive chroot ./mnt /bin/bash | |
| apt-get update; | |
| apt-get dist-upgrade -y; | |
| apt-get install -y binutils byobu curl xz-utils; | |
| EOF | |
| unset EOF; | |
| printf 'auto lo | |
| iface lo inet loopback | |
| iface lo inet6 loopback | |
| auto eth0 | |
| iface eth0 inet dhcp | |
| iface eth0 inet6 auto | |
| allow-hotplug wlan0 | |
| iface wlan0 inet dhcp | |
| wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf' | tee ./mnt/etc/network/interfaces; | |
| printf 'nameserver 1.1.1.1 | |
| nameserver 1.0.0.1' | tee ./mnt/etc/resolv.conf; | |
| printf 'proc\t/proc\tproc\tdefaults\t0\t0 | |
| /dev/mmcblk0p1\t/boot\tvfat\tdefaults\t0\t2 | |
| /dev/mmcblk0p2\t/\text4\tdefaults,noatime\t0\t1' | tee ./mnt/etc/fstab; | |
| cat <<EOF | LANG=C.UTF-8 TERM=xterm DEBIAN_FRONTEND=noninteractive chroot ./mnt /bin/bash | |
| apt-get install -y crda fake-hwclock firmware-brcm80211 firmware-linux-free firmware-linux-nonfree net-tools usb-modeswitch ssh; | |
| mkdir -vp /lib/firmware/bcrm; | |
| cd /lib/firmware/bcrm; | |
| wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43455-sdio.txt; | |
| wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43455-sdio.clm_blob; | |
| wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43430-sdio.txt; | |
| wget -O brcmfmac43430-sdio.raspberrypi,3-model-b.txt https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43430-sdio.raspberrypi-rpi.txt; | |
| useradd -s /bin/bash -d /home/pi -G sudo pi; | |
| echo pi:raspberry | chpasswd; | |
| wget -O /usr/local/bin/rpi-update https://raw.githubusercontent.com/Hexxeh/rpi-update/master/rpi-update; | |
| chmod -v +x /usr/local/bin/rpi-update; | |
| yes | WANT_PI4=1 /usr/local/bin/rpi-update; | |
| EOF | |
| unset EOF; | |
| printf 'dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait net.ifnames=0' | tee ./mnt/boot/cmdline.txt | |
| printf 'kernel=kernel8.img\ngpu_mem=16\narm_64bit=1\ndtoverlay=vc4-fkms-v3d' | tee ./mnt/boot/config.txt | |
| umount -r ./mnt; | |
| umount -f ${_lofree}; | |
| losetup -d ${_lofree}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment