03-initramfs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Build script for the single-purpose initramfs (Live CD).
  2. #
  3. # Copyright (c) 2017-2020, 2022 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 proc sys dev UP
  20. chmod 755 proc sys dev UP
  21. cat << "EOF" > init
  22. #! /bin/busybox hush
  23. set -x
  24. /bin/busybox mount -n -o nosuid,noexec,nodev -t proc proc /proc
  25. /bin/busybox mount -n -o nosuid,noexec,nodev -t sysfs sysfs /sys
  26. /bin/busybox mount -n -t devtmpfs devtmpfs /dev
  27. /bin/busybox sleep 5
  28. # Mount tmpfs plus create directories
  29. /bin/busybox mount -n -w -o size=100% -t tmpfs tmpfs /UP
  30. /bin/busybox mkdir -p \
  31. /UP/cdrom /UP/squash /UP/rw /UP/workdir /UP/union
  32. # Mount ISO and system image
  33. /bin/busybox mount -n -r -t iso9660 LABEL="Dragora_@ARCH@" /UP/cdrom
  34. # Be the system or be dead!
  35. /bin/busybox mount -n -r -o loop -t squashfs \
  36. /UP/cdrom/dragora.sfs /UP/squash || /bin/busybox sleep 3323;
  37. # Merge Squashfs with OverlayFS
  38. /bin/busybox mount -n \
  39. -o lowerdir=/UP/squash,upperdir=/UP/rw,workdir=/UP/workdir \
  40. -t overlay overlay /UP/union
  41. # Move virtual file systems prior to switch_root
  42. /bin/busybox mount -n --move /dev /UP/union/dev
  43. /bin/busybox mount -n --move /proc /UP/union/proc
  44. /bin/busybox mount -n --move /sys /UP/union/sys
  45. : > /UP/union/fastboot
  46. exec /bin/busybox switch_root /UP/union /sbin/init
  47. EOF
  48. sed -i "s/@ARCH@/${package_arch}/" init
  49. chmod 750 init
  50. # Make initramfs
  51. rm -f ./initrd.img
  52. find . | sed -e 's!^./!!' | cpio -oC512 -H newc | \
  53. lzip -s16 -0c > initrd.img