03-initramfs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Build script for the single-purpose initramfs (Live CD).
  2. #
  3. # Copyright (c) 2017-2018 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 dev proc sys .UP
  20. cat << "EOF" > init
  21. #! /bin/busybox ash
  22. /bin/busybox mount -n -o nosuid,noexec,nodev -t proc proc /proc
  23. /bin/busybox mount -n -o nosuid,noexec,nodev -t sysfs sysfs /sys
  24. /bin/busybox mount -n -t devtmpfs devtmpfs /dev
  25. /bin/busybox sleep 2
  26. /bin/busybox mount -n -o rw,size=100% -t tmpfs tmpfs /.UP
  27. /bin/busybox mkdir /.UP/cdrom /.UP/squash /.UP/rw /.UP/work /.UP/union
  28. # Mount ISO and system image
  29. /bin/busybox mount -n -t iso9660 LABEL=DragoraLiveCD /.UP/cdrom
  30. /bin/busybox mount -n -o loop -t squashfs /.UP/cdrom/dragora.sfs /.UP/squash
  31. # Merge Squashfs with OverlayFS
  32. /bin/busybox mount -n \
  33. -o lowerdir=/.UP/squash,upperdir=/.UP/rw,workdir=/.UP/work \
  34. -t overlay overlay /.UP/union
  35. # Move virtual file systems prior to switch_root
  36. /bin/busybox mount --move /dev /.UP/union/dev
  37. /bin/busybox mount --move /proc /.UP/union/proc
  38. /bin/busybox mount --move /sys /.UP/union/sys
  39. exec /bin/busybox switch_root /.UP/union /sbin/init
  40. EOF
  41. chmod 750 ./init
  42. # Make initramfs
  43. rm -f ./initrd.img
  44. find . | sed 's!^./!!' | cpio -oC512 -H newc | \
  45. lzip -s16 -0c > initrd.img