#!/bin/bash
KERNEL_VERSION=6.9.4
BUSYBOX_VERSION=1.36.1
KERNEL_MAJOR=$(echo $KERNEL_VERSION | sed 's/\([0-9]*\)[^0-9].*/\1/')
debian_based_distro_dependency()
{
sudo apt update
sudo apt install build-essential
sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
}
kernal_stuff()
{
# Download the kernal
#wget https://mirrors.edge.kernel.org/pub/linux/kernel/v$KERNEL_MAJOR.x/linux-$KERNEL_VERSION.tar.xz
#tar -xf linux-$KERNEL_VERSION.tar.xz
cd linux-$KERNEL_VERSION
# Make with default config
make defconfig
# Compile the kernal or Exit
make -j8 || exit
cd ..
}
busybox_stuff()
{
# Download the busy box
wget https://busybox.net/downloads/busybox-$BUSYBOX_VERSION.tar.bz2
tar -xf busybox-$BUSYBOX_VERSION.tar.bz2
cd busybox-$BUSYBOX_VERSION
make defconfig
sed 's/^.*CONFIG_STATIC[^_].*$/CONFIG_STATIC=y/g' -i .config
make -j8 || exit
cd ..
}
build_os()
{
# copy linux kernal
cp src/linux-$KERNEL_VERSION/arch/x86_64/boot/bzImage ./
# initrd
mkdir initrd
cd initrd
mkdir -p bin dev proc sys
cd bin
# busybox binary to bin folder
cp ../../src/busybox-$BUSYBOX_VERSION/busybox ./
for prog in $(./busybox --list); do
ln -s /bin/busybox ./$prog
done
cd .. # exit from bin
cd .. # exit from initrd
}
init_creation()
{
cd initrd/
touch init
echo '#!/bin/sh' > init
echo 'mount -t sysfs sysfs /sys' >> init
echo 'mount -t proc proc /proc' >> init
echo 'mount -t devtmpfs udev /dev' >> init
echo 'sysctl -w kernel.printk="2 4 1 7 Kanchilug"' >> init
#echo 'clear' >> init
echo '/bin/sh' >> init
echo 'poweroff -f' >> init
chmod -R 777 .
find . | cpio -o -H newc > ../initrd.img
cd ..
}
qemu_execution()
{
qemu-system-x86_64 -kernel bzImage -initrd initrd.img -nographic -append 'console=ttyS0'
}
#mkdir -p src
#cd src
#kernal_stuff
#debian_based_distro_dependency
#busybox_stuff
#cd ..
#build_os
init_creation
#https://youtu.be/asnXWOUKhTA?t=1966
Other things
@mousinahanger7621
For all the future visitors, the ‘job control is, tty error’ is actually distrubing. To fix it: run openvt -s -l -w /bin/sh or you can also run it with bash when bash is installed instead of direct /bin/sh. This allows you to run bash directly instead of busy box and it works! (Provided openvt is available from busy box so don’t remove busybox)
and
Similar OS