buildDebianFs.sh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh -xe
  2. # Build fs, image
  3. KVER=4.9.30
  4. outmnt=$(mktemp -d -p `pwd`)
  5. inmnt=$(mktemp -d -p `pwd`)
  6. outdev=/dev/loop6
  7. indev=/dev/loop7
  8. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  9. #Without this, a reboot is required to properly clean the loop devices and ensure a clean build
  10. cleanuptwice() {
  11. cleanup
  12. cleanup
  13. }
  14. cleanup() {
  15. set +e
  16. umount -l $inmnt > /dev/null 2>&1
  17. rmdir $inmnt > /dev/null 2>&1
  18. losetup -d $indev > /dev/null 2>&1
  19. umount -l $outmnt > /dev/null 2>&1
  20. rmdir $outmnt > /dev/null 2>&1
  21. losetup -d $outdev > /dev/null 2>&1
  22. }
  23. trap cleanuptwice INT TERM EXIT
  24. create_image() {
  25. # it's a sparse file - that's how we fit a 16GB image inside a 2GB one
  26. dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
  27. parted --script $1 mklabel gpt
  28. cgpt create $1
  29. cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
  30. start=$((8192 + 65536))
  31. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  32. size=$(($end - $start))
  33. cgpt add -i 2 -t data -b $start -s $size -l Root $1
  34. # $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  35. losetup -P $2 $1
  36. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal ${2}p2 $(($size / 2))
  37. # mount the / partition
  38. mount -o noatime ${2}p2 $5
  39. }
  40. # create a 2GB image with the Chrome OS partition layout
  41. create_image debian-stretch-c201-libre-2GB.img $outdev 50M 40 $outmnt
  42. # INCLUDES=apt-utils,libc6,libdebconfclient0,awk,libz2-1.0,libblzma5,libselinux1,tar,libtinfo5,zlib1g,udev,kmod,net-tools,traceroute,iproute2,isc-dhcp-client,wpasupplicant,iw,alsa-utils,cgpt,vim-tiny,less,psmisc,netcat-openbsd,ca-certificates,bzip2,xz-utils,unscd,lightdm,lightdm-gtk-greeter,xfce4,xorg,ifupdown,nano,wicd,wicd-curses
  43. # install Debian on it
  44. qemu-debootstrap --arch=armhf --foreign stretch --variant minbase --include=systemd,systemd-sysv,dbus $outmnt http://deb.debian.org/debian
  45. chroot $outmnt passwd -d root
  46. #echo -n debsus > $outmnt/etc/hostname
  47. #install -D -m 644 80disable-recommends $outmnt/etc/apt/apt.conf.d/80disable-recommends
  48. cp -f /etc/resolv.conf $outmnt/etc/
  49. chroot $outmnt apt update
  50. chroot $outmnt apt install -y udev kmod net-tools inetutils-ping traceroute iproute2 isc-dhcp-client wpasupplicant iw alsa-utils cgpt vim-tiny less psmisc netcat-openbsd ca-certificates bzip2 xz-utils unscd ifupdown nano apt-utils python python-urwid
  51. chroot $outmnt apt-get autoremove --purge
  52. chroot $outmnt apt-get clean
  53. chroot $outmnt apt-get install -d -y wicd-daemon wicd wicd-curses
  54. #sed -i s/^[3-6]/\#\&/g $outmnt/etc/inittab
  55. #sed -i s/'enable-cache hosts no'/'enable-cache hosts yes'/ -i $outmnt/etc/nscd.conf
  56. rm -f $outmnt/etc/resolv.conf
  57. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  58. # firmware in /lib/firmware
  59. dd if=linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  60. make -C linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  61. rm -f $outmnt/lib/modules/3.14.0/{build,source}
  62. install -D -m 644 open-ath9k-htc-firmware/target_firmware/htc_9271.fw $outmnt/lib/firmware/htc_9271.fw
  63. # create a 16GB image
  64. create_image debian-stretch-c201-libre-16GB.img $indev 512 30785536 $inmnt
  65. # copy the kernel and / of the 2GB image to the 16GB one
  66. dd if=${outdev}p1 of=${indev}p1 conv=notrunc
  67. cp -a $outmnt/* $inmnt/
  68. umount -l $inmnt
  69. rmdir $inmnt
  70. losetup -d $indev
  71. # move the 16GB image inside the 2GB one
  72. cp -f debian-stretch-c201-libre-16GB.img $outmnt/
  73. echo "DONE!"
  74. cleanup