|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# RootFS variables |
| 6 | +ROOTFS="alpine-minirootfs" |
| 7 | +CACHEPATH="$ROOTFS/var/cache/apk/" |
| 8 | +SHELLHISTORY="$ROOTFS/root/.ash_history" |
| 9 | +DEVCONSOLE="$ROOTFS/dev/console" |
| 10 | +MODULESPATH="$ROOTFS/lib/modules/" |
| 11 | +DEVURANDOM="$ROOTFS/dev/urandom" |
| 12 | + |
| 13 | +# Kernel variables |
| 14 | +KERNELVERSION="5.6.8" |
| 15 | +KERNELPATH="linux-5.6.8" |
| 16 | +export INSTALL_MOD_PATH="../$ROOTFS/" |
| 17 | + |
| 18 | +# Build threads equall CPU cores |
| 19 | +THREADS=$(getconf _NPROCESSORS_ONLN) |
| 20 | + |
| 21 | +echo" ____________" |
| 22 | +echo" /|------------|" |
| 23 | +echo" /_| .---. |" |
| 24 | +echo" | / \ |" |
| 25 | +echo" | \.6-6./ |" |
| 26 | +echo" | /\`\_/\`\ |" |
| 27 | +echo" | // _\\\ |" |
| 28 | +echo" | | \ / | |" |
| 29 | +echo" | /\`\_\`> <_/\`\ |" |
| 30 | +echo" | \__/'---'\__/ |" |
| 31 | +echo" |_______________|" |
| 32 | +echo"" |
| 33 | +echo" OneFileLinux.efi" |
| 34 | + |
| 35 | +########################## |
| 36 | +# Checking root filesystem |
| 37 | +########################## |
| 38 | + |
| 39 | +echo"----------------------------------------------------" |
| 40 | +echo -e"Checking root filesystem\n" |
| 41 | + |
| 42 | +# Clearing apk cache |
| 43 | +if ["$(ls -A$CACHEPATH)" ];then |
| 44 | +echo -e"Apk cache folder is not empty:$CACHEPATH \nRemoving cache...\n" |
| 45 | + rm$CACHEPATH* |
| 46 | +fi |
| 47 | + |
| 48 | +# Remove shell history |
| 49 | +if [-f$SHELLHISTORY ];then |
| 50 | +echo -e"Shell history found:$SHELLHISTORY \nRemoving history file...\n" |
| 51 | + rm$SHELLHISTORY |
| 52 | +fi |
| 53 | + |
| 54 | +# Clearing kernel modules folder |
| 55 | +if ["$(ls -A$MODULESPATH)" ];then |
| 56 | +echo -e"Kernel modules folder is not empty:$MODULESPATH \nRemoving modules...\n" |
| 57 | + rm -r$MODULESPATH* |
| 58 | +fi |
| 59 | + |
| 60 | +# Removing dev bindings |
| 61 | +if [-e$DEVURANDOM ];then |
| 62 | +echo -e"/dev/ bindings found:$DEVURANDOM. Unmounting...\n" |
| 63 | + umount$DEVURANDOM||echo -e"Not mounted. \n" |
| 64 | + rm$DEVURANDOM |
| 65 | +fi |
| 66 | + |
| 67 | + |
| 68 | +## Check if console character file exist |
| 69 | +#if [ ! -e $DEVCONSOLE ]; then |
| 70 | +# echo -e "ERROR: Console device does not exist: $DEVCONSOLE \nPlease create device file: mknod -m 600 $DEVCONSOLE c 5 1" |
| 71 | +# exit 1 |
| 72 | +#else |
| 73 | +# if [ -d $DEVCONSOLE ]; then # Check that console device is not a folder |
| 74 | +# echo -e "ERROR: Console device is a folder: $DEVCONSOLE \nPlease create device file: mknod -m 600 $DEVCONSOLE c 5 1" |
| 75 | +# exit 1 |
| 76 | +# fi |
| 77 | +# |
| 78 | +# if [ -f $DEVCONSOLE ]; then # Check that console device is not a regular file |
| 79 | +# echo -e "ERROR: Console device is a regular: $DEVCONSOLE \nPlease create device file: mknod -m 600 $DEVCONSOLE c 5 1" |
| 80 | +# fi |
| 81 | +#fi |
| 82 | + |
| 83 | +# Print rootfs uncompressed size |
| 84 | +echo -e"Uncompressed root filesystem size WITHOUT kernel modules:$(du -sh$ROOTFS| cut -f1)\n" |
| 85 | + |
| 86 | + |
| 87 | +cd$KERNELPATH |
| 88 | + |
| 89 | +########################## |
| 90 | +# Bulding kernel |
| 91 | +########################## |
| 92 | +echo"----------------------------------------------------" |
| 93 | +echo -e"Building kernel with initrams using$THREADS threads...\n" |
| 94 | +make -j$THREADS |
| 95 | + |
| 96 | +########################## |
| 97 | +# Bulding kernel modules |
| 98 | +########################## |
| 99 | + |
| 100 | +echo"----------------------------------------------------" |
| 101 | +echo -e"Building kernel mobules using$THREADS threads...\n" |
| 102 | +make modules -j$THREADS |
| 103 | + |
| 104 | +# Copying kernel modules in root filesystem |
| 105 | +echo"----------------------------------------------------" |
| 106 | +echo -e"Copying kernel modules in root filesystem\n" |
| 107 | +make modules_install |
| 108 | +echo -e"Uncompressed root filesystem size WITH kernel modules:$(du -sh ../$ROOTFS| cut -f1)\n" |
| 109 | + |
| 110 | +# Creating modules.dep |
| 111 | +echo"----------------------------------------------------" |
| 112 | +echo -e"Copying modules.dep\n" |
| 113 | +depmod -b ../$ROOTFS -F System.map$KERNELVERSION-onefile |
| 114 | + |
| 115 | +########################## |
| 116 | +# Bulding kernel |
| 117 | +########################## |
| 118 | +echo"----------------------------------------------------" |
| 119 | +echo -e"Building kernel with initrams using$THREADS threads...\n" |
| 120 | +make -j$THREADS |
| 121 | + |
| 122 | + |
| 123 | +########################## |
| 124 | +# Get builded file |
| 125 | +########################## |
| 126 | + |
| 127 | +#rm /boot/efi/EFI/OneFileLinux.efi |
| 128 | +#cp arch/x86/boot/bzImage /boot/efi/EFI/OneFileLinux.efi |
| 129 | +cp arch/x86/boot/bzImage ../OneFileLinux.efi |
| 130 | +#cd .. |
| 131 | +echo"----------------------------------------------------" |
| 132 | +echo -e"\nBuilded successfully:$(pwd)/OneFileLinux.efi\n" |
| 133 | +echo -e"File size:$(du -sh ../OneFileLinux.efi| cut -f1)\n" |