microcore-mininit - stripped down Tiny Core Linux

microcore-mininit.sh 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Install tinycore on harddisk
  2. set -e -x
  3. . /etc/init.d/tc-functions
  4. FILE_URL=http://`getbootparam http`
  5. KERNEL_RELEASE=`uname -r`
  6. # format harddisk
  7. echo -e 'n\np\n1\n\n\na\n1\nw' | sudo fdisk -H16 -S32 /dev/sda
  8. sudo mkfs.ext2 /dev/sda1
  9. # copy system to harddisk
  10. sudo mkdir /mnt/sda1
  11. sudo mount /dev/sda1 /mnt/sda1
  12. sudo mount /mnt/sr0
  13. sudo cp -a /mnt/sr0/boot /mnt/sda1/
  14. sudo umount /mnt/sr0
  15. # modify bootloader config
  16. sudo mv /mnt/sda1/boot/isolinux /mnt/sda1/boot/extlinux
  17. cd /mnt/sda1/boot/extlinux
  18. sudo rm boot.cat isolinux.bin f?
  19. sudo mv isolinux.cfg extlinux.conf
  20. sudo sed -i -e '$ d' boot.msg
  21. sudo sed -i -e '/^label mc/,$ d' -e '/^ *$/ d' -e '1 i serial 0 38400' -e 's/\(append .*\)/\1 console=ttyS0,38400 console=tty0/' -e 's/\(initrd .*\)/\1,\/boot\/microcore-mininit.gz/' extlinux.conf
  22. cd
  23. # make disk bootable
  24. tce-load -wi syslinux
  25. sudo sh -c 'cat /usr/local/share/syslinux/mbr.bin > /dev/sda'
  26. sudo /usr/local/sbin/extlinux --install /mnt/sda1/boot/extlinux
  27. # make microcore-mininit base directory
  28. sudo mkdir microcore-mininit
  29. sudo chmod 755 microcore-mininit
  30. sudo sh -c 'echo -e "/etc\n/etc/init.d\n/opt\n/root\n/sbin" | cpio -p microcore-mininit'
  31. cd microcore-mininit
  32. # new boot script
  33. sudo cp -p /etc/init.d/rcS etc/init.d/
  34. sudo sed -i -e 's/^\(.*tc-config.*\)/#\1/' -e '/tc-config/ a /etc/init.d/microcore_mininit-config' etc/init.d/rcS
  35. sudo wget -O etc/init.d/microcore_mininit-config $FILE_URL/microcore-mininit/microcore_mininit-config
  36. sudo chmod 755 etc/init.d/microcore_mininit-config
  37. # new user initialization script
  38. sudo wget -O opt/bootlocal.sh $FILE_URL/microcore-mininit/bootlocal.sh
  39. sudo chown root:staff opt/bootlocal.sh
  40. sudo chmod 775 opt/bootlocal.sh
  41. # inittab
  42. sudo cp -p /etc/inittab etc/
  43. sudo sed -i -e 's/^\(tty1:[^:]*\):respawn/\1:askfirst/' -e '/tty6/ a ttyS0::askfirst:/sbin/getty -nl /sbin/autologin 38400 ttyS0 xterm' etc/inittab
  44. sudo cp -p /etc/securetty etc/
  45. sudo sed -i -e 's/^# *ttyS0/ttyS0/' etc/securetty
  46. sudo sh -c 'echo -e "#!/bin/busybox ash\nexec login -f root" > sbin/autologin'
  47. sudo chown root:staff sbin/autologin
  48. sudo chmod 775 sbin/autologin
  49. sudo sh -c 'echo -e "#!/bin/sh\nTCUSER=\"\$(cat /etc/sysconfig/tcuser)\"\nexec /bin/su - \"\$TCUSER\"" > root/.profile'
  50. sudo chown root:staff root/.profile
  51. sudo chmod 664 root/.profile
  52. # install ipv6 kernel module
  53. mkdir /tmp/loop
  54. tce-load -w ipv6-${KERNEL_RELEASE}
  55. sudo mount -o loop /tmp/tce/optional/ipv6-${KERNEL_RELEASE}.tcz /tmp/loop
  56. sudo cp -a /tmp/loop/usr/local/lib .
  57. sudo umount /tmp/loop
  58. # install iproute2 and nano
  59. rm /tmp/tce/optional/*
  60. tce-load -w iproute2 nano
  61. rm -f /tmp/tce/optional/db.tcz*
  62. find /tmp/tce/optional -name "*.tcz" | while read tce; do
  63. sudo mount -o loop "$tce" /tmp/loop
  64. sudo cp -a /tmp/loop/usr .
  65. sudo umount /tmp/loop
  66. done
  67. sudo rm usr/local/sbin/arpd
  68. sudo rmdir usr/local/var/lib/arpd
  69. sudo rmdir --ignore-fail-on-non-empty usr/local/var/lib usr/local/var
  70. # create kernel module dependencies and library cache
  71. sudo mkdir -p /tmp/chroot
  72. sudo sh -c "cd /tmp/chroot; zcat /mnt/sda1/boot/core.gz | cpio -idmu"
  73. sudo cp -a * /tmp/chroot/
  74. sudo chroot /tmp/chroot depmod -a
  75. sudo cp -p /tmp/chroot/lib/modules/${KERNEL_RELEASE}/modules.* lib/modules/${KERNEL_RELEASE}/
  76. sudo chroot /tmp/chroot /sbin/ldconfig
  77. sudo cp -p /tmp/chroot/etc/ld.so.cache etc/
  78. # create microcore-mininit initrd
  79. sudo sh -c 'find * | sort | cpio -o -H newc | gzip -9 > /mnt/sda1/boot/microcore-mininit.gz'
  80. sudo umount /mnt/sda1
  81. exit 0