03-initramfs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Build script for the single-purpose initramfs (Live CD).
  2. #
  3. # Copyright (c) 2017-2020 Matias Fonzo, <selk@dragora.org>.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. mkdir -p -- "${rootdir}/initrd"
  17. cd -- "${rootdir}/initrd"
  18. # Create essential directories for the image
  19. mkdir -p -m 755 proc sys dev UP
  20. cat << "EOF" > init
  21. #! /bin/busybox hush
  22. set -x
  23. /bin/busybox mount -n -o nosuid,noexec,nodev -t proc proc /proc
  24. /bin/busybox mount -n -o nosuid,noexec,nodev -t sysfs sysfs /sys
  25. /bin/busybox mount -n -t devtmpfs devtmpfs /dev
  26. /bin/busybox sleep 7
  27. # Mount tmpfs plus create directories
  28. /bin/busybox mount -n -w -o size=100% -t tmpfs tmpfs /UP
  29. /bin/busybox mkdir -p \
  30. /UP/cdrom /UP/squash /UP/rw /UP/workdir /UP/union
  31. # Mount ISO and system image
  32. /bin/busybox mount -n -r -t iso9660 LABEL="Dragora-@ARCH@" /UP/cdrom || \
  33. {
  34. /bin/busybox sleep 3
  35. /bin/busybox mount -n -r /dev/disk/by-label/Dragora-@ARCH@ /UP/cdrom
  36. }
  37. # Be the system or be dead!
  38. /bin/busybox mount -n -r -o loop -t squashfs /UP/cdrom/dragora.sfs /UP/squash || sleep 3323;
  39. # Merge Squashfs with OverlayFS
  40. /bin/busybox mount -n \
  41. -o lowerdir=/UP/squash,upperdir=/UP/rw,workdir=/UP/workdir \
  42. -t overlay overlay /UP/union
  43. # Move virtual file systems prior to switch_root
  44. /bin/busybox mount -n --move /dev /UP/union/dev
  45. /bin/busybox mount -n --move /proc /UP/union/proc
  46. /bin/busybox mount -n --move /sys /UP/union/sys
  47. : > /UP/union/fastboot
  48. exec /bin/busybox switch_root /UP/union /sbin/init
  49. EOF
  50. sed -i "s/@ARCH@/${arch}/" init
  51. chmod 750 init
  52. # Make initramfs
  53. rm -f ./initrd.img
  54. find . | sed -e 's!^./!!' | cpio -oC512 -H newc | \
  55. lzip -s16 -0c > initrd.img