Skip to content

Instantly share code, notes, and snippets.

@alirezaarzehgar
Last active January 10, 2024 20:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezaarzehgar/8d2cb5e4f1855653115ebb5eeaff4a8c to your computer and use it in GitHub Desktop.
Save alirezaarzehgar/8d2cb5e4f1855653115ebb5eeaff4a8c to your computer and use it in GitHub Desktop.
Create Super Minimal Linux Live Distro!
#!/usr/bin/env bash
URL="https://www.busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64"
OS_NAME=AliOS.img
[ -d /tmp/root ] && rm /tmp/root/boot
# Install Busybox
mkdir -p /tmp/root/{bin,dev,etc,lib,mnt,proc,sbin,sys,tmp,var,boot/grub}
cd /tmp/root || exit
wget ${URL} --no-clobber -O bin/busybox
chmod +x bin/busybox
# Create Initramfs
echo "#!/bin/busybox sh
/bin/busybox --install -s /bin
clear
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" >init
chmod +x init
find . | cpio -ov --format=newc | gzip -9 >boot/initramfs
echo "linux /boot/vmlinuz ro quiet
initrd /boot/initramfs
boot" >boot/grub/grub.cfg
cp -f /boot/vmlinuz-"$(uname -r)" boot/vmlinuz
cd -
grub-mkrescue -o ${OS_NAME} /tmp/root
@amirhossein-ka
Copy link

عالی !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment