debian.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. device=$1
  2. boot_dir=`mktemp -d /tmp/BOOT.XXXXXXXXXX`
  3. root_dir=`mktemp -d /tmp/ROOT.XXXXXXXXXX`
  4. linux_dir=tmp/linux-6.12
  5. linux_ver=6.12.52-xilinx
  6. # Choose mirror automatically, depending the geographic and network location
  7. mirror=http://deb.debian.org/debian
  8. distro=trixie
  9. arch=armhf
  10. passwd=changeme
  11. timezone=Europe/Brussels
  12. # Create partitions
  13. parted -s $device mklabel msdos
  14. parted -s $device mkpart primary fat16 4MiB 16MiB
  15. parted -s $device mkpart primary ext4 16MiB 100%
  16. boot_dev=/dev/`lsblk -ln -o NAME -x NAME $device | sed '2!d'`
  17. root_dev=/dev/`lsblk -ln -o NAME -x NAME $device | sed '3!d'`
  18. # Create file systems
  19. mkfs.vfat -v $boot_dev
  20. mkfs.ext4 -F -j $root_dev
  21. # Mount file systems
  22. mount $boot_dev $boot_dir
  23. mount $root_dev $root_dir
  24. # Copy files to the boot file system
  25. cp boot-rootfs.bin $boot_dir/boot.bin
  26. # Install Debian base system to the root file system
  27. debootstrap --foreign --arch $arch $distro $root_dir $mirror
  28. # Install Linux modules
  29. modules_dir=$root_dir/lib/modules/$linux_ver
  30. mkdir -p $modules_dir/kernel
  31. find $linux_dir -name \*.ko -printf '%P\0' | tar --directory=$linux_dir --owner=0 --group=0 --null --files-from=- -zcf - | tar -zxf - --directory=$modules_dir/kernel
  32. cp $linux_dir/modules.order $linux_dir/modules.builtin $modules_dir/
  33. depmod -a -b $root_dir $linux_ver
  34. # Add missing configuration files and packages
  35. cp /etc/resolv.conf $root_dir/etc/
  36. cp /usr/bin/qemu-arm-static $root_dir/usr/bin/
  37. rm $root_dir/etc/apt/sources.list
  38. cp -r debian/etc/apt $root_dir/etc/
  39. cp -r debian/etc/systemd $root_dir/etc/
  40. chroot $root_dir <<- EOF_CHROOT
  41. export LANG=C
  42. export LC_ALL=C
  43. export DEBIAN_FRONTEND=noninteractive
  44. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  45. /debootstrap/debootstrap --second-stage
  46. apt-get update
  47. apt-get -y upgrade
  48. apt-get -y install locales
  49. sed -i "/^# en_US.UTF-8 UTF-8$/s/^# //" etc/locale.gen
  50. locale-gen
  51. update-locale LANG=en_US.UTF-8
  52. ln -sf /usr/share/zoneinfo/$timezone etc/localtime
  53. dpkg-reconfigure tzdata
  54. apt-get -y install openssh-server ca-certificates chrony fake-hwclock \
  55. usbutils psmisc lsof parted curl vim wpasupplicant hostapd dnsmasq \
  56. firmware-atheros firmware-brcm80211 firmware-mediatek firmware-realtek \
  57. iw iptables dhcpcd-base ntfs-3g libubootenv-tool
  58. systemctl enable dhcpcd
  59. systemctl disable hostapd
  60. systemctl disable dnsmasq
  61. systemctl disable nftables
  62. systemctl disable wpa_supplicant
  63. sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' etc/ssh/sshd_config
  64. echo root:$passwd | chpasswd
  65. apt-get clean
  66. service chrony stop
  67. service ssh stop
  68. history -c
  69. sync
  70. EOF_CHROOT
  71. cp -r debian/etc $root_dir/
  72. rm $root_dir/etc/resolv.conf
  73. rm $root_dir/usr/bin/qemu-arm-static
  74. # Unmount file systems
  75. umount $boot_dir $root_dir
  76. rmdir $boot_dir $root_dir
  77. zerofree $root_dev