Last active
April 16, 2025 11:50
-
-
Save yangziy/373ade7fd769884e21fcfe15508784d1 to your computer and use it in GitHub Desktop.
Scripts for building root file systems for Linux development
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
qemu-img create -f raw rootfs.raw 100G | |
mkfs.ext4 rootfs.raw | |
mkdir rootfs | |
sudo mount rootfs.raw ./rootfs | |
sudo debootstrap \ | |
--include apt,apt-utils \ | |
--include isc-dhcp-client,iproute2,wget,curl \ | |
--include git,vim,build-essential,gcc-multilib,g++-multilib \ | |
focal ./rootfs http://archive.ubuntu.com/ubuntu/ | |
sudo su | |
export UUID=$(blkid rootfs.raw | cut -d'"' -f 2) | |
echo "UUID=$UUID / ext4 errors=remount-ro 0 1" >> ./rootfs/etc/fstab | |
echo "vm" > ./rootfs/etc/hostname | |
chroot ./rootfs | |
echo '#!/bin/bash' > /etc/rc.local | |
echo "dhclient" >> /etc/rc.local | |
chmod +x /etc/rc.local | |
useradd --create-home user | |
echo "root:root" | chpasswd | |
echo "user:user" | chpasswd | |
exit | |
umount ./rootfs | |
qemu-img convert -f raw -O qcow2 rootfs.raw rootfs.qcow2 |
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
curl https://busybox.net/downloads/busybox-1.36.0.tar.bz2 | tar xjf - | |
cd busybox-1.36.0 | |
make defconfig | |
sleep 1s && sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' ./.config | |
make -j$(nproc) | |
make install | |
cd _install | |
mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}} | |
cat <<'EOF' > init | |
#!/bin/sh | |
mount -t proc none /proc | |
mount -t sysfs none /sys | |
mount -t debugfs nodev /sys/kernel/debug | |
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n" | |
exec /bin/sh | |
EOF | |
chmod +x init | |
find . -print0 \ | |
| cpio --null -ov --format=newc \ | |
| gzip -9 > ../initramfs-busybox-x86.cpio.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment