Fix disk creation on i686
This commit is contained in:
parent
68c91c801f
commit
fd45421a30
|
@ -60,6 +60,8 @@ INSTALLER=\
|
|||
ifeq ($(ARCH),x86_64)
|
||||
BOOTLOADER_BIOS=build/bootloader.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_TARGET=x86-unknown-none
|
||||
else ifeq ($(ARCH),i686)
|
||||
|
@ -68,6 +70,8 @@ else ifeq ($(ARCH),i686)
|
|||
BOOTLOADER_EFI_PATH=efi/boot/bootia32.efi
|
||||
BOOTLOADER_TARGET=x86-unknown-none
|
||||
else ifeq ($(ARCH),aarch64)
|
||||
BOOTLOADER_EFI=build/bootloader.efi
|
||||
BOOTLOADER_EFI_LIVE=build/bootloader-live.efi
|
||||
BOOTLOADER_EFI_PATH=efi/boot/bootaa64.efi
|
||||
BOOTLOADER_TARGET=aarch64-unknown-none
|
||||
else
|
||||
|
|
22
mk/disk.mk
22
mk/disk.mk
|
@ -1,8 +1,22 @@
|
|||
build/harddrive.bin: build/bootloader.efi build/filesystem.bin $(BOOTLOADER_BIOS)
|
||||
env PARTED=$(PARTED) ./mk/disk.sh $@ build/filesystem.bin $< $(BOOTLOADER_EFI_PATH) $(BOOTLOADER_BIOS)
|
||||
build/harddrive.bin: build/filesystem.bin $(BOOTLOADER_EFI) $(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)
|
||||
env PARTED=$(PARTED) ./mk/disk.sh $@ build/filesystem.bin $< $(BOOTLOADER_EFI_PATH) $(BOOTLOADER_BIOS_LIVE)
|
||||
build/livedisk.bin: build/filesystem.bin $(BOOTLOADER_EFI_LIVE) $(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
|
||||
rm -rf build/iso/
|
||||
|
|
73
mk/disk.sh
73
mk/disk.sh
|
@ -3,7 +3,7 @@
|
|||
#TODO: move to installer
|
||||
|
||||
function usage {
|
||||
echo "$0 [disk] [filesystem] [bootloader.efi] [bootloader.efi path] <bootloader.bios>" >&2
|
||||
echo "$0 [disk] [filesystem]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -21,64 +21,57 @@ then
|
|||
fi
|
||||
FILESYSTEM="$2"
|
||||
|
||||
if [ ! -f "$3" ]
|
||||
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"
|
||||
MiB=1048576
|
||||
|
||||
set -ex
|
||||
|
||||
# Calculate partition sizes
|
||||
MiB=1048576
|
||||
|
||||
# Calculate filesystem partition size
|
||||
fs_disk_size="$(du -m "${FILESYSTEM}" | cut -f1)"
|
||||
fs_disk_blkcount="$(expr "${fs_disk_size}" \* "$(expr "${MiB}" / 512)")"
|
||||
fs_start="2048"
|
||||
fs_end="$(expr "${fs_start}" + "${fs_disk_blkcount}")"
|
||||
fs_last="$(expr "${fs_end}" - 1)"
|
||||
|
||||
efi_disk_size="$(expr "$(du -m "${BOOTLOADER_EFI}" | cut -f1)" + 1)"
|
||||
efi_disk_blkcount="$(expr "$efi_disk_size" \* "$(expr "${MiB}" / 512)")"
|
||||
efi_start="${fs_end}"
|
||||
efi_end="$(expr "${efi_start}" + "${efi_disk_blkcount}")"
|
||||
efi_last="$(expr "${efi_end}" - 1)"
|
||||
if [ -n "${BOOTLOADER_EFI}" ]
|
||||
then
|
||||
# Calculate EFI partition size
|
||||
efi_disk_size="$(expr "$(du -m "${BOOTLOADER_EFI}" | cut -f1)" + 1)"
|
||||
efi_disk_blkcount="$(expr "$efi_disk_size" \* "$(expr "${MiB}" / 512)")"
|
||||
efi_start="${fs_end}"
|
||||
efi_end="$(expr "${efi_start}" + "${efi_disk_blkcount}")"
|
||||
efi_last="$(expr "${efi_end}" - 1)"
|
||||
|
||||
# Populate an EFI system partition
|
||||
dd if=/dev/zero of="${DISK}.esp" bs="${MiB}" count="${efi_disk_size}"
|
||||
mkfs.vfat "${DISK}.esp"
|
||||
mmd -i "${DISK}.esp" efi
|
||||
mmd -i "${DISK}.esp" efi/boot
|
||||
mcopy -i "${DISK}.esp" "${BOOTLOADER_EFI}" "::${BOOTLOADER_EFI_PATH}"
|
||||
# Populate an EFI system partition
|
||||
dd if=/dev/zero of="${DISK}.esp" bs="${MiB}" count="${efi_disk_size}"
|
||||
mkfs.vfat "${DISK}.esp"
|
||||
mmd -i "${DISK}.esp" efi
|
||||
mmd -i "${DISK}.esp" efi/boot
|
||||
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
|
||||
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
|
||||
"${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 EFI fat32 "${efi_start}"s "${efi_last}s"
|
||||
"${PARTED}" -s -a minimal "${DISK}" set 2 boot on
|
||||
"${PARTED}" -s -a minimal "${DISK}" set 2 esp on
|
||||
if [ -n "${BOOTLOADER_EFI}" ]
|
||||
then
|
||||
"${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 esp on
|
||||
fi
|
||||
|
||||
# Write the partitions
|
||||
dd if="${FILESYSTEM}" of="${DISK}" bs=512 seek="${fs_start}" count="${fs_disk_blkcount}" conv=notrunc
|
||||
dd if="${DISK}.esp" of="${DISK}" bs=512 seek="${efi_start}" count="${efi_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
|
||||
fi
|
||||
|
||||
# Write BIOS bootloader if applicable
|
||||
if [ -n "${BOOTLOADER_BIOS}" ]
|
||||
|
|
Loading…
Reference in a new issue