Last active
May 19, 2025 17:27
-
-
Save Mr-Bossman/2cb4fc98fb6c8fdc9dd724ae5232789c to your computer and use it in GitHub Desktop.
generate a bootable linux image for 68k using emile
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
#!/bin/bash | |
PART_NAME="linux" | |
IMG_NAME="emile.img" | |
PART_SIZE=$((1024*1024*1000)) | |
BS=$((1024*1024)) | |
# HD0-OpenRetroSCSI-7.5.3.hda | |
# https://mega.nz/folder/8hA3AQCJ#pWUq92L70yDXlogy9lk5Dg/file/hkIxnQ4S | |
#mv HD0-OpenRetroSCSI-7.5.3.hda MacOS.img | |
cp MacOS.img "$IMG_NAME" | |
dd if=/dev/zero of="$IMG_NAME" conv=notrunc oflag=sync,append status=progress bs="$BS" count=$(( PART_SIZE / BS )) | |
START_SEC=$(partx -ro START "$IMG_NAME" | sort -n | tail -n1) | |
LAST_SEC=$((START_SEC - 1)) | |
END_SEC=$((LAST_SEC + ( PART_SIZE ) / 512)) | |
dd if="$IMG_NAME" of="$IMG_NAME".tmp bs=512 count=1 | |
parted -s "$IMG_NAME" mkpart "$PART_NAME" ext4 "$START_SEC"s "$END_SEC"s | |
dd if="$IMG_NAME".tmp of="$IMG_NAME" bs=512 count=1 conv=notrunc oflag=sync | |
rm "$IMG_NAME".tmp | |
PART_NUM=$(partx "$IMG_NAME" -o NR,NAME | sed -nr "s/([0-9]+) $PART_NAME/\1/p") | |
PART_NUM=$((PART_NUM + 0)) | |
LOOP_DEV=$(losetup -f) | |
ROOT_PART="$LOOP_DEV"p"$PART_NUM" | |
losetup -P "$LOOP_DEV" "$IMG_NAME" | |
sudo mke2fs "$ROOT_PART" | |
mkdir -p rootfs | |
sudo mount "$ROOT_PART" rootfs | |
sudo debootstrap --no-check-gpg --arch=m68k --foreign --variant=minbase --components=main,non-free --include=nano,linux-image-m68k,systemd-sysv,emile --extra-suites=unreleased sid rootfs https://deb.debian.org/debian-ports/ | |
sudo cp "$(which qemu-m68k-static)" rootfs/usr/bin/ | |
cat << EOF > setup.sh | |
#!/bin/bash | |
/debootstrap/debootstrap --second-stage | |
cat << EOT >> etc/initramfs-tools/modules | |
mac_esp | |
esp_scsi | |
sd_mod | |
EOT | |
update-initramfs -u -k all | |
EOF | |
chmod +x setup.sh | |
sudo mv setup.sh rootfs/ | |
sudo chroot rootfs/ /usr/bin/qemu-m68k-static /bin/bash /setup.sh | |
cat << EOF > emile.conf | |
partition /dev/sda3 | |
first_level /boot/emile/first_scsi | |
second_level /boot/emile/second_scsi | |
timeout 5 | |
default 0 | |
title Debian GNU/Linux | |
root ext2:(sd0,3) | |
kernel /vmlinuz | |
initrd /initrd.img | |
args root=/dev/sda4 rw rootwait earlyprintk console=ttyS0 console=tty0 fbcon=font:ProFont6x11 ignore_loglevel printk.time=1 | |
EOF | |
sudo mv emile.conf rootfs/boot/emile/ | |
cat << EOF > setup.sh | |
#!/bin/bash | |
emile --backup | |
emile | |
sync | |
poweroff -f | |
EOF | |
chmod +x setup.sh | |
sudo mv setup.sh rootfs/ | |
cp rootfs/vmlinuz . | |
cp rootfs/initrd.img . | |
sudo umount rootfs | |
losetup -D "$LOOP_DEV" | |
rmdir rootfs | |
dd if=/dev/zero of=pram.img bs=512 count=1 | |
qemu-system-m68k -M q800 -m 1000M -net nic,model=dp83932 -net user -nographic -append "root=/dev/sda4 rw console=ttyS0 init=/setup.sh" -kernel vmlinuz -initrd initrd.img -drive file="$IMG_NAME",format=raw | |
exit | |
# https://www.macintoshrepository.org/7038-all-macintosh-roms-68k-ppc- Old_World_Mac_Roms.zip | |
# shellcheck disable=SC2317 | |
qemu-system-m68k \ | |
-M q800 \ | |
-bios Quadra800.rom \ | |
-m 128 \ | |
-display gtk \ | |
-device scsi-hd,scsi-id=0,drive=hd1 \ | |
-drive file=pram.img,format=raw,if=mtd \ | |
-drive file=emile.img,media=disk,format=raw,if=none,id=hd1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment