added isoz stage to make a compressed disk image
also included a work around for a WSL bug in create-disk.sh
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
out/*
|
||||
build/*
|
||||
*.img
|
||||
*.img.gz
|
||||
*.elf
|
||||
bx_enh_dbg.ini
|
||||
stevia-log
|
||||
|
||||
15
Makefile
15
Makefile
@@ -1,4 +1,5 @@
|
||||
iso := 'disk.img'
|
||||
iso := '/tmp/disk.img'
|
||||
isoz := 'disk.img.gz'
|
||||
|
||||
include := './include'
|
||||
|
||||
@@ -15,9 +16,9 @@ boottest_binary_files := $(patsubst src/miniboot32/%.nasm, build/%.bin, $(bootte
|
||||
build_dir := 'build'
|
||||
|
||||
qemu_args := -L ./bin/ -bios bios.bin -cpu pentium3 -m 128 -S -s -monitor stdio -nic none
|
||||
.PHONY: all mbr vbr stage2 boottest clean run run_bochs iso
|
||||
.PHONY: all mbr vbr stage2 boottest clean run run_bochs iso isoz
|
||||
|
||||
all: $(iso) $(mbr_binary_files) $(vbr_binary_files) $(stage2_binary_files)
|
||||
all: $(iso) $(isoz) $(mbr_binary_files) $(vbr_binary_files) $(stage2_binary_files)
|
||||
mbr: $(mbr_binary_files)
|
||||
vbr: $(vbr_binary_files)
|
||||
stage2: $(stage2_binary_files)
|
||||
@@ -26,6 +27,7 @@ boottest: $(boottest_binary_files)
|
||||
clean:
|
||||
@rm -rvf $(build_dir)/*
|
||||
@rm -rvf $(iso)
|
||||
@rm -rvf $(isoz)
|
||||
|
||||
run: $(iso)
|
||||
@sudo qemu-system-i386 $(qemu_args) -hda $(iso)
|
||||
@@ -34,7 +36,10 @@ run_bochs: $(iso)
|
||||
@bochs -q
|
||||
|
||||
iso: $(iso)
|
||||
@file disk.img
|
||||
@file $(iso)
|
||||
|
||||
isoz: $(isoz)
|
||||
@file $(isoz)
|
||||
|
||||
build/%.bin: src/mbr/%.nasm
|
||||
@mkdir -p $(shell dirname $@)
|
||||
@@ -56,3 +61,5 @@ $(iso): $(mbr_binary_files) $(vbr_binary_files) $(stage2_binary_files) $(boottes
|
||||
@echo root access needed to create disk image...
|
||||
@sudo scripts/create-disk.sh
|
||||
|
||||
$(isoz): $(iso)
|
||||
@gzip -9kc $(iso) > $(isoz)
|
||||
|
||||
@@ -25,21 +25,30 @@ if ! [ $(id -u) = 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# paths to bootcode
|
||||
mbr_file=build/mbr.bin
|
||||
vbr_file=build/vbr.bin
|
||||
stage2_file=build/stage2.bin
|
||||
boottest_file=build/BOOT_386.bin
|
||||
|
||||
mount_point=/tmp/stevia_disk
|
||||
|
||||
if ! [ -e disk.img ]; then
|
||||
# Disk creation options
|
||||
mount_point=/tmp/stevia_disk
|
||||
disk_tmp_file=/tmp/disk.img
|
||||
disk_file_final=./disk.img.gz
|
||||
|
||||
# $disk_sector_size * $disk_size = total bytes, default is 128MiB
|
||||
disk_size=262144
|
||||
disk_sector_size=512
|
||||
|
||||
if ! [ -e $disk_tmp_file ]; then
|
||||
# create raw disk image with 128MiB of space
|
||||
dd if=/dev/zero of=disk.img bs=512 count=262144
|
||||
dd if=/dev/zero of=$disk_tmp_file bs=$disk_sector_size count=$disk_size
|
||||
sync
|
||||
else
|
||||
echo "Removing old disk image..."
|
||||
rm -rfv disk.img
|
||||
dd if=/dev/zero of=disk.img bs=512 count=262144
|
||||
rm -rfv $disk_tmp_file
|
||||
dd if=/dev/zero of=$disk_tmp_file bs=$disk_sector_size count=$disk_size
|
||||
sync
|
||||
fi
|
||||
|
||||
@@ -47,7 +56,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if [ -e $mbr_file ] && [ -e $vbr_file ]; then
|
||||
# get next loop device and mount it
|
||||
ld=$(losetup -f)
|
||||
losetup -P -b 512 $ld disk.img
|
||||
losetup -P -b 512 $ld $disk_tmp_file
|
||||
|
||||
# create a DOS disk, with 1 FAT32 partition that is bootable, part1 starts at sector 2048
|
||||
sfdisk $ld < scripts/loop_setup.sfdisk
|
||||
@@ -55,9 +64,9 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# partprobe the image
|
||||
partprobe $ld
|
||||
|
||||
# get first partition
|
||||
# get first partition, this is sloppy might need to review this...
|
||||
firstpart=$(lsblk -ilp -o NAME $ld | tr '\n' ' ' | awk '{print $3}')
|
||||
mkfs.vfat -v -F32 -S 512 $firstpart
|
||||
mkfs.vfat -v -F32 -S $disk_sector_size $firstpart
|
||||
|
||||
# copy MBR while preserving partition table
|
||||
dd if=$mbr_file of=$ld bs=1 count=440
|
||||
@@ -73,7 +82,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
dd if=$vbr_file of=$firstpart bs=1 seek=510 skip=510 count=2
|
||||
|
||||
#stage2 to sectors 1-64
|
||||
dd if=$stage2_file of=$ld bs=512 seek=1
|
||||
dd if=$stage2_file of=$ld bs=$disk_sector_size seek=1
|
||||
|
||||
# copy boot32 boot test file to disk image
|
||||
if ! [ -e $mount_point ]; then
|
||||
@@ -94,8 +103,10 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
losetup -d $ld
|
||||
|
||||
# chown to the real user to prevent issues with reading/writing the file later
|
||||
SUDOUSER=$(logname)
|
||||
chown --from=root:root ${SUDOUSER}:$(id $SUDOUSER -g) disk.img
|
||||
# BUG: ${logname}:$(id $(logname -g)) doesn't work right on WSL because of runlevel hacks in WSL
|
||||
# BUG: https://github.com/microsoft/WSL/issues/1761
|
||||
# as a work around I'll just reference LICENSE.md...WHICH SHOULD ALWAYS BE THERE 👀
|
||||
chown --from=root:root --reference=LICENSE.md $disk_tmp_file
|
||||
|
||||
else
|
||||
echo "unable to find MBR/VBR binaries!"
|
||||
@@ -159,7 +170,7 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
dd if=$vbr_file of=/dev/$firstpart bs=1 seek=510 skip=510 count=2 conv=sync
|
||||
|
||||
#stage2 to sectors 1-64
|
||||
dd if=$stage2_file of=$ld_path bs=512 seek=1 conv=sync
|
||||
dd if=$stage2_file of=$ld_path bs=$disk_sector_size seek=1 conv=sync
|
||||
|
||||
#sync pending dd stuff
|
||||
sync
|
||||
@@ -189,7 +200,7 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# chown to the real user to prevent issues with reading/writing the file later
|
||||
SUDOUSER=$(logname)
|
||||
chown ${SUDOUSER}:staff disk.img
|
||||
|
||||
gzip -9kc $disk_tmp_file > $disk_file_final
|
||||
else
|
||||
echo "unable to find MBR/VBR binaries!"
|
||||
exit 2
|
||||
|
||||
Reference in New Issue
Block a user