Created
June 15, 2024 12:39
-
-
Save clicseo/cea6821f446242da38e83a9f25a5f68b to your computer and use it in GitHub Desktop.
Minimal busybox & musl linux distro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
BUSYBOX_URL="https://busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64" | |
MUSL_URL="https://musl.libc.org/releases/musl-1.2.4.tar.gz" | |
KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.95.tar.xz" | |
OS_NAME="MinimalLinux.iso" | |
ROOTFS="/tmp/root" | |
KERNEL_VERSION="5.10.95" | |
[ -d ${ROOTFS} ] && rm -rf ${ROOTFS} | |
mkdir -p ${ROOTFS}/{bin,dev,etc,lib,mnt,proc,sbin,sys,tmp,var,boot/grub,usr/local/musl} | |
wget ${BUSYBOX_URL} -O ${ROOTFS}/bin/busybox | |
chmod +x ${ROOTFS}/bin/busybox | |
${ROOTFS}/bin/busybox --install -s ${ROOTFS}/bin | |
cat << 'EOF' > ${ROOTFS}/init | |
#!/bin/busybox sh | |
/bin/busybox --install -s /bin | |
mount -t devtmpfs devtmpfs /dev | |
mount -t proc proc /proc | |
mount -t sysfs sysfs /sys | |
mount -t tmpfs tmpfs /tmp | |
setsid cttyhack sh | |
exec /bin/sh | |
EOF | |
chmod +x ${ROOTFS}/init | |
cd ${ROOTFS} | |
find . | cpio -H newc -o | gzip -9 > boot/initramfs | |
cd - | |
cd /tmp | |
wget ${MUSL_URL} | |
tar xzf musl-1.2.4.tar.gz | |
cd musl-1.2.4 | |
./configure --prefix=${ROOTFS}/usr/local/musl | |
make | |
make install | |
cd - | |
cd /tmp | |
wget ${KERNEL_URL} | |
tar xvf linux-${KERNEL_VERSION}.tar.xz | |
cd linux-${KERNEL_VERSION} | |
make defconfig | |
make -j$(nproc) | |
cp arch/x86/boot/bzImage ${ROOTFS}/boot/vmlinuz | |
cd - | |
cat << 'EOF' > ${ROOTFS}/boot/grub/grub.cfg | |
set default=0 | |
set timeout=5 | |
menuentry "Minimal Linux" { | |
linux /boot/vmlinuz ro quiet | |
initrd /boot/initramfs | |
} | |
EOF | |
grub-mkrescue -o ${OS_NAME} ${ROOTFS} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment