Fix disk creation on i686

This commit is contained in:
Jeremy Soller 2022-08-28 15:40:01 -06:00
parent 68c91c801f
commit fd45421a30
3 changed files with 55 additions and 44 deletions

View file

@ -60,6 +60,8 @@ INSTALLER=\
ifeq ($(ARCH),x86_64) ifeq ($(ARCH),x86_64)
BOOTLOADER_BIOS=build/bootloader.bin BOOTLOADER_BIOS=build/bootloader.bin
BOOTLOADER_BIOS_LIVE=build/bootloader-live.bin BOOTLOADER_BIOS_LIVE=build/bootloader-live.bin
BOOTLOADER_EFI=build/bootloader.efi
BOOTLOADER_EFI_LIVE=build/bootloader-live.efi
BOOTLOADER_EFI_PATH=efi/boot/bootx64.efi BOOTLOADER_EFI_PATH=efi/boot/bootx64.efi
BOOTLOADER_TARGET=x86-unknown-none BOOTLOADER_TARGET=x86-unknown-none
else ifeq ($(ARCH),i686) else ifeq ($(ARCH),i686)
@ -68,6 +70,8 @@ else ifeq ($(ARCH),i686)
BOOTLOADER_EFI_PATH=efi/boot/bootia32.efi BOOTLOADER_EFI_PATH=efi/boot/bootia32.efi
BOOTLOADER_TARGET=x86-unknown-none BOOTLOADER_TARGET=x86-unknown-none
else ifeq ($(ARCH),aarch64) else ifeq ($(ARCH),aarch64)
BOOTLOADER_EFI=build/bootloader.efi
BOOTLOADER_EFI_LIVE=build/bootloader-live.efi
BOOTLOADER_EFI_PATH=efi/boot/bootaa64.efi BOOTLOADER_EFI_PATH=efi/boot/bootaa64.efi
BOOTLOADER_TARGET=aarch64-unknown-none BOOTLOADER_TARGET=aarch64-unknown-none
else else

View file

@ -1,8 +1,22 @@
build/harddrive.bin: build/bootloader.efi build/filesystem.bin $(BOOTLOADER_BIOS) build/harddrive.bin: build/filesystem.bin $(BOOTLOADER_EFI) $(BOOTLOADER_BIOS)
env PARTED=$(PARTED) ./mk/disk.sh $@ build/filesystem.bin $< $(BOOTLOADER_EFI_PATH) $(BOOTLOADER_BIOS) rm -f $@ $@.partial
env \
PARTED=$(PARTED) \
BOOTLOADER_EFI=$(BOOTLOADER_EFI) \
BOOTLOADER_EFI_PATH=$(BOOTLOADER_EFI_PATH) \
BOOTLOADER_BIOS=$(BOOTLOADER_BIOS) \
./mk/disk.sh $@.partial $<
mv "$@.partial" "$@"
build/livedisk.bin: build/bootloader-live.efi build/filesystem.bin $(BOOTLOADER_BIOS_LIVE) build/livedisk.bin: build/filesystem.bin $(BOOTLOADER_EFI_LIVE) $(BOOTLOADER_BIOS_LIVE)
env PARTED=$(PARTED) ./mk/disk.sh $@ build/filesystem.bin $< $(BOOTLOADER_EFI_PATH) $(BOOTLOADER_BIOS_LIVE) rm -f $@ $@.partial
env \
PARTED=$(PARTED) \
BOOTLOADER_EFI=$(BOOTLOADER_EFI_LIVE) \
BOOTLOADER_EFI_PATH=$(BOOTLOADER_EFI_PATH) \
BOOTLOADER_BIOS=$(BOOTLOADER_BIOS_LIVE) \
./mk/disk.sh $@.partial $<
mv "$@.partial" "$@"
build/livedisk.iso: build/livedisk.bin.gz build/livedisk.iso: build/livedisk.bin.gz
rm -rf build/iso/ rm -rf build/iso/

View file

@ -3,7 +3,7 @@
#TODO: move to installer #TODO: move to installer
function usage { function usage {
echo "$0 [disk] [filesystem] [bootloader.efi] [bootloader.efi path] <bootloader.bios>" >&2 echo "$0 [disk] [filesystem]" >&2
exit 1 exit 1
} }
@ -21,38 +21,20 @@ then
fi fi
FILESYSTEM="$2" FILESYSTEM="$2"
if [ ! -f "$3" ] MiB=1048576
then
echo "invalid bootloader.efi '$3'" >&2
usage
fi
BOOTLOADER_EFI="$3"
if [ ! -n "$4" ]
then
echo "invalid bootloader.efi path '$4'" >&2
usage
fi
BOOTLOADER_EFI_PATH="$4"
# Optional argument
if [ -n "$5" -a ! -f "$5" ]
then
echo "invalid bootloader.bios '$5'" >&2
fi
BOOTLOADER_BIOS="$5"
set -ex set -ex
# Calculate partition sizes # Calculate filesystem partition size
MiB=1048576
fs_disk_size="$(du -m "${FILESYSTEM}" | cut -f1)" fs_disk_size="$(du -m "${FILESYSTEM}" | cut -f1)"
fs_disk_blkcount="$(expr "${fs_disk_size}" \* "$(expr "${MiB}" / 512)")" fs_disk_blkcount="$(expr "${fs_disk_size}" \* "$(expr "${MiB}" / 512)")"
fs_start="2048" fs_start="2048"
fs_end="$(expr "${fs_start}" + "${fs_disk_blkcount}")" fs_end="$(expr "${fs_start}" + "${fs_disk_blkcount}")"
fs_last="$(expr "${fs_end}" - 1)" fs_last="$(expr "${fs_end}" - 1)"
if [ -n "${BOOTLOADER_EFI}" ]
then
# Calculate EFI partition size
efi_disk_size="$(expr "$(du -m "${BOOTLOADER_EFI}" | cut -f1)" + 1)" efi_disk_size="$(expr "$(du -m "${BOOTLOADER_EFI}" | cut -f1)" + 1)"
efi_disk_blkcount="$(expr "$efi_disk_size" \* "$(expr "${MiB}" / 512)")" efi_disk_blkcount="$(expr "$efi_disk_size" \* "$(expr "${MiB}" / 512)")"
efi_start="${fs_end}" efi_start="${fs_end}"
@ -66,19 +48,30 @@ mmd -i "${DISK}.esp" efi
mmd -i "${DISK}.esp" efi/boot mmd -i "${DISK}.esp" efi/boot
mcopy -i "${DISK}.esp" "${BOOTLOADER_EFI}" "::${BOOTLOADER_EFI_PATH}" mcopy -i "${DISK}.esp" "${BOOTLOADER_EFI}" "::${BOOTLOADER_EFI_PATH}"
disk_size="$(expr "${fs_disk_size}" + "${efi_disk_size}" + 2)"
else
disk_size="$(expr "${fs_disk_size}" + 2)"
fi
# Create the disk # Create the disk
dd if=/dev/zero of="${DISK}" bs="${MiB}" count="$(expr "$(du -m "${DISK}.esp" | cut -f1)" + 2 + "$(du -m "${FILESYSTEM}" | cut -f1)")" dd if=/dev/zero of="${DISK}" bs="${MiB}" count="${disk_size}"
# Create partition table # Create partition table
"${PARTED}" -s -a minimal "${DISK}" mklabel gpt "${PARTED}" -s -a minimal "${DISK}" mklabel gpt
"${PARTED}" -s -a minimal "${DISK}" mkpart redox ext4 "${fs_start}s" "${fs_last}"s "${PARTED}" -s -a minimal "${DISK}" mkpart redox ext4 "${fs_start}s" "${fs_last}"s
if [ -n "${BOOTLOADER_EFI}" ]
then
"${PARTED}" -s -a minimal "${DISK}" mkpart EFI fat32 "${efi_start}"s "${efi_last}s" "${PARTED}" -s -a minimal "${DISK}" mkpart EFI fat32 "${efi_start}"s "${efi_last}s"
"${PARTED}" -s -a minimal "${DISK}" set 2 boot on "${PARTED}" -s -a minimal "${DISK}" set 2 boot on
"${PARTED}" -s -a minimal "${DISK}" set 2 esp on "${PARTED}" -s -a minimal "${DISK}" set 2 esp on
fi
# Write the partitions # Write the partitions
dd if="${FILESYSTEM}" of="${DISK}" bs=512 seek="${fs_start}" count="${fs_disk_blkcount}" conv=notrunc dd if="${FILESYSTEM}" of="${DISK}" bs=512 seek="${fs_start}" count="${fs_disk_blkcount}" conv=notrunc
if [ -n "${BOOTLOADER_EFI}" ]
then
dd if="${DISK}.esp" of="${DISK}" bs=512 seek="${efi_start}" count="${efi_disk_blkcount}" conv=notrunc dd if="${DISK}.esp" of="${DISK}" bs=512 seek="${efi_start}" count="${efi_disk_blkcount}" conv=notrunc
fi
# Write BIOS bootloader if applicable # Write BIOS bootloader if applicable
if [ -n "${BOOTLOADER_BIOS}" ] if [ -n "${BOOTLOADER_BIOS}" ]