forked from Bananymous/banan-os
Buildsystem: Build disk image manually
We don't use grub-mkrescue anymore. Instead we build the disk image manually. This allows us to have known disk layout for easier testing when I get to implementing disk reading. For now I made the root partition ext2 since I think that will be the first format that I'll implement.
This commit is contained in:
parent
fb7fe73d49
commit
0eb1fb8bae
|
@ -1,4 +1,4 @@
|
||||||
*.iso
|
*.img
|
||||||
isodir
|
isodir
|
||||||
sysroot
|
sysroot
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
6
bochs.sh
6
bochs.sh
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
. ./iso.sh
|
. ./disk.sh
|
||||||
|
|
||||||
BOCHS_CONFIG_FILE=bochsrc
|
BOCHS_CONFIG_FILE=bochsrc
|
||||||
COM1_TERMINAL=kitty
|
COM1_TERMINAL=kitty
|
||||||
|
@ -15,8 +15,8 @@ COM1_DEVICE=$(cat $COM1_DEVICE_FILE)
|
||||||
rm $COM1_DEVICE_FILE
|
rm $COM1_DEVICE_FILE
|
||||||
|
|
||||||
cat > $BOCHS_CONFIG_FILE << EOF
|
cat > $BOCHS_CONFIG_FILE << EOF
|
||||||
ata0-master: type=cdrom, path=banan-os.iso, status=inserted
|
ata0-master: type=disk, path=banan-os.img, status=inserted
|
||||||
boot: cdrom
|
boot: disk
|
||||||
clock: sync=realtime, time0=local
|
clock: sync=realtime, time0=local
|
||||||
display_library: x, options="gui_debug"
|
display_library: x, options="gui_debug"
|
||||||
magic_break: enabled=1
|
magic_break: enabled=1
|
||||||
|
|
2
clean.sh
2
clean.sh
|
@ -8,4 +8,4 @@ done
|
||||||
|
|
||||||
rm -rf sysroot
|
rm -rf sysroot
|
||||||
rm -rf isodir
|
rm -rf isodir
|
||||||
rm -rf banan-os.iso
|
rm -rf banan-os.img
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
. ./build.sh
|
||||||
|
|
||||||
|
DISK_NAME=banan-os.img
|
||||||
|
DISK_SIZE=$[50 * 1024 * 1024]
|
||||||
|
MOUNT_DIR=/mnt
|
||||||
|
|
||||||
|
dd if=/dev/zero of=$DISK_NAME bs=512 count=$[$DISK_SIZE / 512]
|
||||||
|
|
||||||
|
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $DISK_NAME
|
||||||
|
g # gpt
|
||||||
|
n # new partition
|
||||||
|
1 # partition number 1
|
||||||
|
# default (from the beginning of the disk)
|
||||||
|
+1MiB # bios boot partiton size
|
||||||
|
n # new partition
|
||||||
|
2 # partition number 2
|
||||||
|
# default (right after bios boot partition)
|
||||||
|
# default (to the end of disk)
|
||||||
|
t # set type
|
||||||
|
1 # ... of partition 1
|
||||||
|
4 # bios boot partition
|
||||||
|
t # set type
|
||||||
|
2 # ... of partition 2
|
||||||
|
20 # Linux filesystem
|
||||||
|
w # write changes
|
||||||
|
EOF
|
||||||
|
|
||||||
|
LOOP_DEV=$(sudo losetup -f --show $DISK_NAME)
|
||||||
|
sudo partprobe $LOOP_DEV
|
||||||
|
|
||||||
|
PARTITION1=${LOOP_DEV}p1
|
||||||
|
PARTITION2=${LOOP_DEV}p2
|
||||||
|
|
||||||
|
sudo mkfs.ext2 $PARTITION2
|
||||||
|
|
||||||
|
sudo mount $PARTITION2 $MOUNT_DIR
|
||||||
|
|
||||||
|
sudo cp -r sysroot/* ${MOUNT_DIR}/
|
||||||
|
|
||||||
|
sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory=${MOUNT_DIR}/boot $LOOP_DEV
|
||||||
|
|
||||||
|
echo -e '
|
||||||
|
menuentry "banan-os" {
|
||||||
|
multiboot /boot/banan-os.kernel
|
||||||
|
}
|
||||||
|
menuentry "banan-os (no serial)" {
|
||||||
|
multiboot /boot/banan-os.kernel noserial
|
||||||
|
}
|
||||||
|
menuentry "banan-os (no apic)" {
|
||||||
|
multiboot /boot/banan-os.kernel noapic
|
||||||
|
}
|
||||||
|
menuentry "banan-os (no apic, no serial)" {
|
||||||
|
multiboot /boot/banan-os.kernel noapic noserial
|
||||||
|
}
|
||||||
|
' | sudo tee ${MOUNT_DIR}/boot/grub/grub.cfg
|
||||||
|
|
||||||
|
sudo umount $MOUNT_DIR
|
||||||
|
sudo losetup -d $LOOP_DEV
|
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
. ./iso.sh
|
. ./disk.sh
|
||||||
|
|
||||||
sudo su -c "cat banan-os.iso > /dev/sda"
|
SIZE=$(stat banan-os.img | grep -oP '\d+' | head -n 1)
|
||||||
|
|
||||||
|
echo Writing $SIZE bytes
|
||||||
|
sudo dd if=banan-os.img of=/dev/sda status=progress
|
||||||
|
|
24
iso.sh
24
iso.sh
|
@ -1,24 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
. ./build.sh
|
|
||||||
|
|
||||||
mkdir -p isodir
|
|
||||||
mkdir -p isodir/boot
|
|
||||||
mkdir -p isodir/boot/grub
|
|
||||||
|
|
||||||
cp sysroot/boot/banan-os.kernel isodir/boot/banan-os.kernel
|
|
||||||
cat > isodir/boot/grub/grub.cfg << EOF
|
|
||||||
menuentry "banan-os" {
|
|
||||||
multiboot /boot/banan-os.kernel
|
|
||||||
}
|
|
||||||
menuentry "banan-os (no serial)" {
|
|
||||||
multiboot /boot/banan-os.kernel noserial
|
|
||||||
}
|
|
||||||
menuentry "banan-os (no apic)" {
|
|
||||||
multiboot /boot/banan-os.kernel noapic
|
|
||||||
}
|
|
||||||
menuentry "banan-os (no apic, no serial)" {
|
|
||||||
multiboot /boot/banan-os.kernel noapic noserial
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
grub-mkrescue -o banan-os.iso isodir
|
|
4
qemu.sh
4
qemu.sh
|
@ -1,10 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
. ./iso.sh
|
. ./disk.sh
|
||||||
|
|
||||||
qemu-system-$(./target-triplet-to-arch.sh $HOST) \
|
qemu-system-$(./target-triplet-to-arch.sh $HOST) \
|
||||||
-m 128 \
|
-m 128 \
|
||||||
-smp 2 \
|
-smp 2 \
|
||||||
-drive format=raw,media=cdrom,file=banan-os.iso \
|
-drive format=raw,media=disk,file=banan-os.img \
|
||||||
-serial stdio \
|
-serial stdio \
|
||||||
|
|
Loading…
Reference in New Issue