Last active
December 15, 2025 19:19
-
-
Save a-sakharov/eec7c1e5e6f5f529fd498221c0667bc8 to your computer and use it in GitHub Desktop.
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
| romimage: file=BIOS-bochs-latest, options=fastboot | |
| vgaromimage: file=VGABIOS-lgpl-latest | |
| cpu: count=1, ips=10000000, model=corei5_arrandale_m520 | |
| megs: 256 | |
| display_library: sdl2 | |
| ata0-master: type=disk, mode=flat, biosdetect=auto, translation=auto, path="disk.img", cylinders=0, heads=0, spt=0 | |
| boot: disk | |
| log: bochsout.txt | |
| mouse: enabled=0 | |
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/bash | |
| # create disk image that could be used with qemu or written to real hardware. No efi, MBR only | |
| set -e | |
| if [ $(id -u) -ne 0 ]; then | |
| echo run as root | |
| exit -1 | |
| fi | |
| #set -x #echo commands as they executing | |
| DISK_SIZE_BYTES=$((1024 * 1024 * 32)) #32MB total image sizes | |
| DISK_FILE_NAME=disk.img | |
| LODEVICE=$(losetup -f) | |
| SYS_MOUNTPOINT=$(mktemp -d) | |
| BUSYBOX_PATH=busybox/busybox-1.37.0/busybox | |
| LINUX_KERN_PATH=linux/linux-6.18.1/arch/x86/boot/bzImage | |
| function cleanup { | |
| set +e | |
| # unmount everything | |
| umount $SYS_MOUNTPOINT 2> /dev/null | |
| losetup -d $LODEVICE | |
| chmod 775 $DISK_FILE_NAME | |
| if [[ -v SUDO_USER ]]; then | |
| chown $SUDO_USER:$SUDO_USER $DISK_FILE_NAME | |
| fi | |
| } | |
| trap cleanup EXIT | |
| dd if=/dev/zero of=$DISK_FILE_NAME bs=512 count=$((($DISK_SIZE_BYTES + 511) / 512)) status=none # create empty file which size is a multiple of 512 | |
| losetup $LODEVICE $DISK_FILE_NAME # mount image to loop dev | |
| parted $LODEVICE mktable msdos --script #create mbr partition table | |
| parted $LODEVICE mkpart primary fat32 512KB 100% --script #create system partition | |
| parted $LODEVICE set 1 boot on --script #mark bootpartition | |
| mkfs.vfat $LODEVICE"p1" > /dev/null #format sys partition | |
| mount $LODEVICE"p1" $SYS_MOUNTPOINT | |
| grub-install --target=i386-pc --modules="part_msdos fat" --install-modules="search linux echo halt" --boot-directory $SYS_MOUNTPOINT/boot --fonts="ascii" $LODEVICE > /dev/null | |
| ROOT_FS_UUID=$(blkid -s UUID -o value $LODEVICE"p1") | |
| #copy kernel | |
| cp $LINUX_KERN_PATH $SYS_MOUNTPOINT/boot | |
| #create+copy ramdisk | |
| RAMDISK_TMPDIR=$(mktemp -d) | |
| cat << INIT > $RAMDISK_TMPDIR/init | |
| #! /bin/sh | |
| mount -t sysfs sysfs /sys | |
| mount -t proc proc /proc | |
| mount -t devtmpfs udev /dev | |
| sysctl -w kernel.printk="2 4 1 7" | |
| /bin/sh | |
| poweroff -f | |
| INIT | |
| chmod 777 $RAMDISK_TMPDIR/init | |
| mkdir -p $RAMDISK_TMPDIR/bin | |
| mkdir -p $RAMDISK_TMPDIR/dev | |
| mkdir -p $RAMDISK_TMPDIR/proc | |
| mkdir -p $RAMDISK_TMPDIR/sys | |
| cp $BUSYBOX_PATH $RAMDISK_TMPDIR/bin/busybox | |
| for prog in $($RAMDISK_TMPDIR/bin/busybox --list); do | |
| ln -s /bin/busybox $RAMDISK_TMPDIR/bin/$prog; | |
| done | |
| (cd $RAMDISK_TMPDIR && find .) | cpio -D $RAMDISK_TMPDIR -o -H newc | xz -9 --check=crc32 > $SYS_MOUNTPOINT/boot/initrd.img | |
| cp $SYS_MOUNTPOINT/boot/initrd.img . | |
| #create grub config | |
| cat << GRUB > $SYS_MOUNTPOINT/boot/grub/grub.cfg | |
| set timeout=5 | |
| menuentry "Boot this linux" { | |
| search --no-floppy --set=root --fs-uuid $ROOT_FS_UUID | |
| linux /boot/$(basename $LINUX_KERN_PATH) | |
| initrd /boot/initrd.img | |
| } | |
| menuentry "System shutdown" { | |
| echo "System shutting down..." | |
| halt | |
| } | |
| GRUB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment