buildInitramFs.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh -xe
  2. #Build initramfs image
  3. # This file is part of PrawnOS (http://www.prawnos.com)
  4. # Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
  5. # PrawnOS is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 2
  7. # as published by the Free Software Foundation.
  8. # PrawnOS is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
  14. outmnt=$(mktemp -d -p `pwd`)
  15. outdev=/dev/loop7
  16. KVER=$1
  17. ROOT_DIR=`pwd`
  18. build_resources=$ROOT_DIR/resources/BuildResources
  19. if [ ! -f $ROOT_DIR/PrawnOS-*-c201-libre-2GB.img-BASE ]
  20. then
  21. echo "No base filesystem, run 'make filesystem' first"
  22. exit 1
  23. fi
  24. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  25. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  26. cleanup() {
  27. set +e
  28. umount -l $outmnt > /dev/null 2>&1
  29. rmdir $outmnt > /dev/null 2>&1
  30. losetup -d $outdev > /dev/null 2>&1
  31. set +e
  32. umount -l $outmnt > /dev/null 2>&1
  33. rmdir $outmnt > /dev/null 2>&1
  34. losetup -d $outdev > /dev/null 2>&1
  35. }
  36. trap cleanup INT TERM EXIT
  37. losetup -P $outdev $ROOT_DIR/PrawnOS-*-c201-libre-2GB.img-BASE
  38. #mount the root filesystem
  39. mount -o noatime ${outdev}p3 $outmnt
  40. #mount the initramfs partition
  41. mount -o noatime ${outdev}p2 $outmnt/boot
  42. #make a skeleton filesystem
  43. initramfs_src=$outmnt/InstallResources/initramfs_src
  44. rm -rf $initramfs_src*
  45. mkdir -p $initramfs_src
  46. mkdir $initramfs_src/bin
  47. mkdir $initramfs_src/dev
  48. mkdir $initramfs_src/etc
  49. mkdir $initramfs_src/newroot
  50. mkdir $initramfs_src/proc
  51. mkdir $initramfs_src/sys
  52. mkdir $initramfs_src/sbin
  53. mkdir $initramfs_src/run
  54. mkdir $initramfs_src/lib
  55. mkdir $initramfs_src/lib/arm-linux-gnueabihf
  56. #install the few tools we need, and the supporting libs
  57. cp $outmnt/bin/busybox $outmnt/sbin/cryptsetup $initramfs_src/bin/
  58. cp $outmnt/lib/arm-linux-gnueabihf/libblkid.so.1 $initramfs_src/lib/arm-linux-gnueabihf/
  59. cp $outmnt/lib/arm-linux-gnueabihf/libuuid.so.1 $initramfs_src/lib/arm-linux-gnueabihf/
  60. cp $outmnt/lib/arm-linux-gnueabihf/libc.so.6 $initramfs_src/lib/arm-linux-gnueabihf/
  61. cp $outmnt/lib/ld-linux-armhf.so.3 $initramfs_src/lib/
  62. cp $outmnt/sbin/blkid $initramfs_src/bin/
  63. #add the init script
  64. cp $build_resources/initramfs-init $initramfs_src/init
  65. chmod +x $initramfs_src/init
  66. #compress and install
  67. rm -rf $outmnt/boot/PrawnOS-initramfs.cpio.gz
  68. cd $initramfs_src
  69. ln -s busybox bin/cat
  70. ln -s busybox bin/mount
  71. ln -s busybox bin/sh
  72. ln -s busybox bin/switch_root
  73. ln -s busybox bin/umount
  74. find . -print0 | cpio --null --create --verbose --format=newc | gzip --best > $outmnt/boot/PrawnOS-initramfs.cpio.gz
  75. cd $ROOT_DIR
  76. [ ! -d build ] && mkdir build
  77. cd build
  78. # store for kernel building
  79. cp $outmnt/boot/PrawnOS-initramfs.cpio.gz .