Skip to content

Instantly share code, notes, and snippets.

@brandonros
Last active June 4, 2020 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonros/61e56acdbfe18a3399edb85f73671f33 to your computer and use it in GitHub Desktop.
Save brandonros/61e56acdbfe18a3399edb85f73671f33 to your computer and use it in GitHub Desktop.

Compiling kernel

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.7.tar.xz
tar -xf linux-5.7.tar.xz
cd linux-5.7
docker run --rm dockcross/linux-x64 > ./dockcross
chmod +x ./dockcross
./dockcross make defconfig
./dockcross make -j $(sysctl -n hw.ncpu)

Compiling Busybox

wget https://busybox.net/downloads/busybox-1.31.1.tar.bz2
tar -xf busybox-1.31.1.tar.bz2
cd busybox-1.31.1
docker run --rm dockcross/linux-x64 > ./dockcross
chmod +x ./dockcross
./dockcross make defconfig
./dockcross make -j $(sysctl -n hw.ncpu)

Building disk image

From host

cd ~/Desktop
dd if=/dev/zero of=disk.raw bs=1 count=10G
docker run -it --privileged -v /Users/$USER/Desktop:/tmp/Desktop ubuntu

From container

IMG=/tmp/Desktop/disk.raw
SIZE=10G
apt-get update
apt-get install parted kpartx udev extlinux
dd if=/usr/lib/syslinux/mbr/mbr.bin of=$IMG conv=notrunc bs=440 count=1
parted -s $IMG mklabel msdos
parted -s -a none $IMG mkpart primary ext4 0 $SIZE
parted -s -a none $IMG set 1 boot on
kpartx -av /tmp/Desktop/disk.raw 
mke2fs -t ext4 /dev/mapper/loop1p1 
mount /dev/mapper/loop1p1 /mnt
mkdir /mnt/boot
extlinux --install /mnt/boot
cp /tmp/Desktop/bzImage /mnt/boot
cp /tmp/Desktop/extlinux.conf /mnt/boot
cp /tmp/Desktop/busybox-1.31.1/busybox /mnt/
./mnt/busybox --install /mnt/ 
umount /mnt

Running VM

qemu-system-x86_64 -hda ~/Desktop/disk.raw 
default test
prompt 1
timeout 50
LABEL test
MENU Test entry
LINUX /boot/bzImage
APPEND ro root=/dev/sda1
@brandonros
Copy link
Author

brandonros commented Jun 3, 2020

busybox install

chroot /mnt /busybox sh
mkdir /sbin
mkdir /bin
mkdir -p /usr/bin
mkdir -p /usr/sbin
/bin/busybox --install

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