build.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #!/bin/sh
  2. #
  3. # Ersoy Kardesler Minimal Linux System build script
  4. # Copyright (C) 2016-2021 John Davidson
  5. # 2021-2022 Erdem Ersoy and Ercan Ersoy
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Set script parameters
  20. set -ex
  21. # Linux-libre Package
  22. LINUX_LIBRE_VERSION_NOT_GNU=5.10.147
  23. LINUX_LIBRE_VERSION=${LINUX_LIBRE_VERSION_NOT_GNU}-gnu1
  24. LINUX_LIBRE_NAME_AND_VERSION=linux-libre-${LINUX_LIBRE_VERSION}
  25. LINUX_LIBRE_NAME_AND_VERSION_NOT_LIBRE_AND_GNU=linux-${LINUX_LIBRE_VERSION_NOT_GNU}
  26. LINUX_LIBRE_PACKAGE_NAME=${LINUX_LIBRE_NAME_AND_VERSION}.tar.xz
  27. LINUX_LIBRE_PACKAGE_NAME_NOT_LIBRE_AND_GNU=${LINUX_LIBRE_NAME_AND_VERSION_NOT_LIBRE_AND_GNU}.tar.xz
  28. LINUX_LIBRE_PACKAGE_LOCATION=http://linux-libre.fsfla.org/pub/linux-libre/releases/${LINUX_LIBRE_VERSION}/${LINUX_LIBRE_PACKAGE_NAME}
  29. # Busybox Package
  30. BUSYBOX_VERSION=1.34.1
  31. BUSYBOX_NAME_AND_VERSION=busybox-${BUSYBOX_VERSION}
  32. BUSYBOX_PACKAGE_NAME=${BUSYBOX_NAME_AND_VERSION}.tar.bz2
  33. BUSYBOX_PACKAGE_LOCATION=https://busybox.net/downloads/${BUSYBOX_PACKAGE_NAME}
  34. # NCURSES Package
  35. NCURSES_VERSION=6.3
  36. NCURSES_NAME_AND_VERSION=ncurses-${NCURSES_VERSION}
  37. NCURSES_PACKAGE_NAME=${NCURSES_NAME_AND_VERSION}.tar.gz
  38. NCURSES_PACKAGE_LOCATION=https://invisible-mirror.net/archives/ncurses/${NCURSES_PACKAGE_NAME}
  39. # GNU nano package
  40. NANO_VERSION=6.4
  41. NANO_NAME_AND_VERSION=nano-${NANO_VERSION}
  42. NANO_PACKAGE_NAME=${NANO_NAME_AND_VERSION}.tar.xz
  43. NANO_PACKAGE_LOCATION=https://www.nano-editor.org/dist/v6/${NANO_PACKAGE_NAME}
  44. # Syslinux Package
  45. SYSLINUX_VERSION=6.03
  46. SYSLINUX_NAME_AND_VERSION=syslinux-${SYSLINUX_VERSION}
  47. SYSLINUX_PACKAGE_NAME=${SYSLINUX_NAME_AND_VERSION}.tar.xz
  48. SYSLINUX_PACKAGE_LOCATION=http://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/${SYSLINUX_PACKAGE_NAME}
  49. # Make build directories
  50. mkdir -p packages
  51. mkdir -p packages_extracted
  52. mkdir -p rootfs
  53. mkdir -p isoimage
  54. # Download packages
  55. cd packages
  56. wget -nc ${LINUX_LIBRE_PACKAGE_LOCATION}
  57. wget -nc ${BUSYBOX_PACKAGE_LOCATION}
  58. wget -nc ${NCURSES_PACKAGE_LOCATION}
  59. wget -nc ${NANO_PACKAGE_LOCATION}
  60. wget -nc ${SYSLINUX_PACKAGE_LOCATION}
  61. cd ..
  62. # Extract packages
  63. cd packages_extracted
  64. if [ ! -d ${LINUX_LIBRE_NAME_AND_VERSION_NOT_LIBRE_AND_GNU} ]; then tar -xvf ../packages/${LINUX_LIBRE_PACKAGE_NAME} -C .; fi
  65. if [ ! -d ${BUSYBOX_NAME_AND_VERSION} ]; then tar -xvf ../packages/${BUSYBOX_PACKAGE_NAME} -C .; fi
  66. if [ ! -d ${NCURSES_NAME_AND_VERSION} ]; then tar -xvf ../packages/${NCURSES_PACKAGE_NAME} -C .; fi
  67. if [ ! -d ${NANO_NAME_AND_VERSION} ]; then tar -xvf ../packages/${NANO_PACKAGE_NAME} -C .; fi
  68. if [ ! -d ${SYSLINUX_NAME_AND_VERSION} ]; then tar -xvf ../packages/${SYSLINUX_PACKAGE_NAME} -C .; fi
  69. cd ..
  70. # Configure and install Linux-libre
  71. cd packages_extracted/${LINUX_LIBRE_NAME_AND_VERSION_NOT_LIBRE_AND_GNU}
  72. cp -T ../../configs/linux-config .config
  73. make
  74. cp arch/x86/boot/bzImage ../../isoimage/kernel.gz
  75. cd ../..
  76. # Configure and install BusyBox
  77. cd packages_extracted/${BUSYBOX_NAME_AND_VERSION}
  78. cp -T ../../configs/busybox-config .config
  79. make
  80. make busybox install
  81. cp -r _install/* ../../rootfs
  82. cd ../..
  83. # Configure and install NCURSES
  84. cd packages_extracted/${NCURSES_NAME_AND_VERSION}
  85. LDFLAGS=--static ./configure --prefix=$(pwd)/_install/
  86. make
  87. make install
  88. cp -r _install/* ../../rootfs
  89. cd ../..
  90. # Configure and install GNU nano
  91. cd packages_extracted/${NANO_NAME_AND_VERSION}
  92. LDFLAGS=--static ./configure --prefix=$(pwd)/_install/
  93. make
  94. make install
  95. cp -r _install/* ../../rootfs
  96. cd ../..
  97. # Prepare root filesystem with some changes
  98. cd rootfs
  99. mkdir -p dev sys tmp var/cache var/lock var/log var/spool var/tmp
  100. mkdir -p etc/init.d
  101. mkdir -p proc/sys/kernel
  102. ## Add /etc/group
  103. echo 'root:x:0:' > etc/group
  104. echo 'daemon:x:1:' >> etc/group
  105. ## Add /etc/hostname
  106. echo 'minimal' > etc/hostname
  107. ## Add /etc/inittab
  108. echo '::sysinit:/etc/init.d/rcS' > etc/inittab
  109. echo '::sysinit:/bin/hostname -F /etc/hostname' >> etc/inittab
  110. echo '::respawn:/sbin/syslogd -n' >> etc/inittab
  111. echo '::respawn:/sbin/klogd -n' >> etc/inittab
  112. echo '::respawn:/sbin/getty 115200 console' >> etc/inittab
  113. ## Add /etc/init.d/rcS
  114. echo '#!/bin/sh' > etc/init.d/rcS
  115. echo 'dmesg -n 5' >> etc/init.d/rcS
  116. echo 'mount -t proc proc /proc' >> etc/init.d/rcS
  117. echo 'mount -t sysfs sysfs /sys' >> etc/init.d/rcS
  118. echo 'mount -t tmpfs -o size=64m tmp_files /tmp' >> etc/init.d/rcS
  119. echo 'ln -s /tmp /var/cache' >> etc/init.d/rcS
  120. echo 'ln -s /tmp /var/lock' >> etc/init.d/rcS
  121. echo 'ln -s /tmp /var/log' >> etc/init.d/rcS
  122. echo 'ln -s /tmp /var/run' >> etc/init.d/rcS
  123. echo 'ln -s /tmp /var/spool' >> etc/init.d/rcS
  124. echo 'ln -s /tmp /var/tmp' >> etc/init.d/rcS
  125. echo 'mount -t devtmpfs devtmpfs /dev' >> etc/init.d/rcS
  126. echo 'echo /sbin/mdev > /proc/sys/kernel/hotplug' >> etc/init.d/rcS
  127. echo 'mdev -s' >> etc/init.d/rcS
  128. chmod +x etc/init.d/rcS
  129. ## Add /etc/mdev.conf
  130. echo 'console root:root 600' > etc/mdev.conf
  131. echo 'null root:root 666' >> etc/mdev.conf
  132. echo 'random root:root 444' >> etc/mdev.conf
  133. echo 'urandom root:root 444' >> etc/mdev.conf
  134. ## Add /etc/motd
  135. echo '***********************************' > etc/motd
  136. echo '* *' >> etc/motd
  137. echo '* Welcome to Minimal Linux System *' >> etc/motd
  138. echo '* *' >> etc/motd
  139. echo '***********************************' >> etc/motd
  140. ## Add /etc/passwd
  141. echo 'root:x:0:0:root:/root:/bin/sh' > etc/passwd
  142. echo 'daemon:x:1:1:daemon:/usr/sbin:/bin/false' >> etc/passwd
  143. ## Add /etc/profile
  144. echo '#!/bin/sh' > etc/profile
  145. echo 'export TERM=linux' >> etc/profile
  146. chmod +x etc/profile
  147. ## Add /etc/shadow
  148. echo 'root::10933:0:99999:7:::' > etc/shadow
  149. echo 'daemon:*:10933:0:99999:7:::' >> etc/shadow
  150. chmod 0600 etc/shadow
  151. # Package root filesystem and copy root filesystem to ISO filesystem
  152. find ./* | cpio -R root:root -H newc -o | gzip > ../isoimage/rootfs.gz
  153. cd ..
  154. # Copy ISOLINUX files to ISO filesystem and Make ISOcd
  155. cd packages_extracted/${SYSLINUX_NAME_AND_VERSION}
  156. cp bios/core/isolinux.bin ../../isoimage
  157. cp bios/com32/elflink/ldlinux/ldlinux.c32 ../../isoimage
  158. cp bios/com32/libutil/libutil.c32 ../../isoimage
  159. cp bios/com32/menu/menu.c32 ../../isoimage
  160. cp ../../configs/isolinux.cfg ../../isoimage/isolinux.cfg
  161. xorriso -as mkisofs -o ../../ersoy-kardesler-minimal-linux-system.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 20 -boot-info-table ../../isoimage
  162. cd ../..
  163. # Re-set script parameters
  164. set +ex