mirror of
https://github.com/home-assistant/operating-system.git
synced 2025-07-29 16:06:30 +00:00
Migrate to GPT
This commit is contained in:
parent
8a44103558
commit
b48f4184e3
@ -10,6 +10,7 @@ CONFIG_AUTO_COMPLETE=y
|
||||
CONFIG_BOOTM_SHOW_TYPE=y
|
||||
CONFIG_BOOTM_OFTREE=y
|
||||
CONFIG_FLEXIBLE_BOOTARGS=y
|
||||
# CONFIG_PARTITION_DISK_DOS is not set
|
||||
CONFIG_PARTITION_DISK_EFI=y
|
||||
# CONFIG_PARTITION_DISK_EFI_GPT_NO_FORCE is not set
|
||||
# CONFIG_PARTITION_DISK_EFI_GPT_COMPARE is not set
|
||||
@ -29,6 +30,7 @@ CONFIG_CMD_READLINK=y
|
||||
CONFIG_CMD_GETOPT=y
|
||||
CONFIG_CMD_TIMEOUT=y
|
||||
CONFIG_CMD_DETECT=y
|
||||
CONFIG_CMD_OF_DUMP=y
|
||||
CONFIG_CMD_STATE=y
|
||||
CONFIG_CMD_BOOTCHOOSER=y
|
||||
CONFIG_DRIVER_SERIAL_EFI=y
|
||||
|
@ -1,54 +0,0 @@
|
||||
image boot.vfat {
|
||||
vfat {
|
||||
extraargs = "-n boot"
|
||||
|
||||
file EFI/BOOT/BOOTx64.EFI {
|
||||
image = "barebox.bin"
|
||||
}
|
||||
file EFI/barebox/state.dtb {
|
||||
image = "barebox-state.dtb"
|
||||
}
|
||||
}
|
||||
size = 32M
|
||||
}
|
||||
|
||||
image sdcard.img {
|
||||
hdimage {
|
||||
align = 1M
|
||||
extended-partition = 4
|
||||
}
|
||||
|
||||
partition boot {
|
||||
partition-type = 0xef
|
||||
bootable = "true"
|
||||
image = "boot.vfat"
|
||||
}
|
||||
|
||||
partition system0 {
|
||||
partition-type = 0x83
|
||||
image = "rootfs.squashfs"
|
||||
size = 256M
|
||||
}
|
||||
|
||||
partition system1 {
|
||||
partition-type = 0x83
|
||||
size = 256M
|
||||
}
|
||||
|
||||
partition bootstate {
|
||||
partition-type = 0x83
|
||||
size = 2M
|
||||
}
|
||||
|
||||
partition overlay {
|
||||
partition-type = 0x83
|
||||
image = "overlay.ext4"
|
||||
size = 64M
|
||||
}
|
||||
|
||||
partition data {
|
||||
partition-type = 0x83
|
||||
image = "data.ext4"
|
||||
size = 64M
|
||||
}
|
||||
}
|
@ -1,30 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$BR2_EXTERNAL_HASSIO_PATH/scripts"
|
||||
BOARD_DIR="$(dirname $0)"
|
||||
GENIMAGE_CFG="$BOARD_DIR/genimage.cfg"
|
||||
GENIMAGE_TMP="$BASE_DIR/genimage.tmp"
|
||||
|
||||
OVERLAY_IMG="$BINARIES_DIR/overlay.ext4"
|
||||
DATA_IMG="$BINARIES_DIR/data.ext4"
|
||||
BOOT_IMG="$BINARIES_DIR/boot.vfat"
|
||||
|
||||
rm -rf "$GENIMAGE_TMP" "$OVERLAY_IMG" "$DATA_IMG"
|
||||
BOOT_DATA="$BINARIES_DIR/boot-data"
|
||||
|
||||
dd if=/dev/zero of="$OVERLAY_IMG" bs=4k count=16000
|
||||
dd if=/dev/zero of="$DATA_IMG" bs=4k count=16000
|
||||
. "$SCRIPT_DIR"/hdd_image.sh
|
||||
|
||||
mkfs.ext4 "$OVERLAY_IMG" && tune2fs -L "overlay" -c0 -i0 "$OVERLAY_IMG"
|
||||
mkfs.ext4 "$DATA_IMG" && tune2fs -L "data" -c0 -i0 "$DATA_IMG"
|
||||
rm -rf "$BOOT_DATA"
|
||||
|
||||
cp "$BOARD_DIR/barebox-state.dtb" "$BINARIES_DIR/"
|
||||
# Init boot data
|
||||
mkdir -p "$BOOT_DATA/EFI/BOOT"
|
||||
mkdir -p "$BOOT_DATA/EFI/barebox"
|
||||
|
||||
genimage \
|
||||
--rootpath "$TARGET_DIR" \
|
||||
--tmppath "$GENIMAGE_TMP" \
|
||||
--inputpath "$BINARIES_DIR" \
|
||||
--outputpath "$BINARIES_DIR" \
|
||||
--config "$GENIMAGE_CFG"
|
||||
cp "$BINARIES_DIR/barebox.bin" "$BOOT_DATA/EFI/BOOT/BOOTx64.EFI"
|
||||
cp "$BOARD_DIR/barebox-state.dtb" "$BOOT_DATA/EFI/barebox/state.dtb"
|
||||
|
||||
qemu-img resize -f raw "$BINARIES_DIR/sdcard.img" 1G
|
||||
qemu-img convert -O vmdk "$BINARIES_DIR/sdcard.img" "$BINARIES_DIR/hassio-os.vmdk"
|
||||
hassio_boot_image "$BOOT_DATA" "$BOOT_IMG"
|
||||
hassio_overlay_image "$OVERLAY_IMG"
|
||||
hassio_data_image "$DATA_IMG"
|
||||
|
||||
|
||||
hassio_hdd_image "$BOOT_IMG" "$BINARIES_DIR/rootfs.squashfs" "$OVERLAY_IMG" "$DATA_IMG" "$BINARIES_DIR/harddisk.img"
|
||||
|
||||
qemu-img convert -O vmdk "$BINARIES_DIR/harddisk.img" "$BINARIES_DIR/hassio-os.vmdk"
|
||||
|
||||
|
@ -56,6 +56,6 @@ BR2_TARGET_BAREBOX_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_HASSIO_PATH)/board/ova/bar
|
||||
BR2_TARGET_BAREBOX_CUSTOM_EMBEDDED_ENV_PATH="$(BR2_EXTERNAL_HASSIO_PATH)/board/ova/barebox-env $(BR2_EXTERNAL_HASSIO_PATH)/barebox-env"
|
||||
BR2_PACKAGE_HOST_DOSFSTOOLS=y
|
||||
BR2_PACKAGE_HOST_E2FSPROGS=y
|
||||
BR2_PACKAGE_HOST_GENIMAGE=y
|
||||
BR2_PACKAGE_HOST_GPTFDISK=y
|
||||
BR2_PACKAGE_HOST_MTOOLS=y
|
||||
BR2_PACKAGE_HOST_RAUC=y
|
||||
|
0
buildroot-external/patches/.ignore
Normal file
0
buildroot-external/patches/.ignore
Normal file
@ -1,95 +0,0 @@
|
||||
From 22568ea927b8b78c8463ad5beb0105e476d4cf3e Mon Sep 17 00:00:00 2001
|
||||
From: Pascal Vizeli <pvizeli@syshack.ch>
|
||||
Date: Wed, 21 Mar 2018 23:35:44 +0100
|
||||
Subject: [PATCH 1/1] Add support for extended partition
|
||||
|
||||
---
|
||||
image-hd.c | 25 +++++++++++++++++++------
|
||||
1 file changed, 19 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/image-hd.c b/image-hd.c
|
||||
index c53a64a..7d392d3 100644
|
||||
--- a/image-hd.c
|
||||
+++ b/image-hd.c
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
struct hdimage {
|
||||
cfg_bool_t partition_table;
|
||||
+ unsigned int extended_partition;
|
||||
unsigned long long align;
|
||||
unsigned long long extended_lba;
|
||||
uint32_t disksig;
|
||||
@@ -227,14 +228,22 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
|
||||
{
|
||||
struct partition *part;
|
||||
int has_extended;
|
||||
- int partition_table_entries = 0;
|
||||
+ unsigned int partition_table_entries = 0;
|
||||
unsigned long long now = 0;
|
||||
struct hdimage *hd = xzalloc(sizeof(*hd));
|
||||
|
||||
hd->align = cfg_getint_suffix(cfg, "align");
|
||||
hd->partition_table = cfg_getbool(cfg, "partition-table");
|
||||
+ hd->extended_partition = cfg_getint(cfg, "extended-partition");
|
||||
hd->disksig = strtoul(cfg_getstr(cfg, "disk-signature"), NULL, 0);
|
||||
|
||||
+ if (hd->extended_partition > 4) {
|
||||
+ image_error(image, "invalid extended partition index (%i). must be "
|
||||
+ "inferior or equal to 4 (0 for automatic)\n",
|
||||
+ hd->extended_partition);
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+
|
||||
if ((hd->align % 512) || (hd->align == 0)) {
|
||||
image_error(image, "partition alignment (%lld) must be a "
|
||||
"multiple of 1 sector (512 bytes)\n", hd->align);
|
||||
@@ -244,7 +253,10 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
|
||||
if (part->in_partition_table)
|
||||
++partition_table_entries;
|
||||
}
|
||||
- has_extended = partition_table_entries > 4;
|
||||
+ if (!hd->extended_partition && partition_table_entries > 4)
|
||||
+ hd->extended_partition = 4;
|
||||
+ has_extended = hd->extended_partition > 0;
|
||||
+
|
||||
partition_table_entries = 0;
|
||||
list_for_each_entry(part, &image->partitions, list) {
|
||||
if (part->image) {
|
||||
@@ -275,8 +287,8 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
|
||||
/* reserve space for extended boot record if necessary */
|
||||
if (part->in_partition_table)
|
||||
++partition_table_entries;
|
||||
- if (has_extended && (partition_table_entries > 3))
|
||||
- part->extended = cfg_true;
|
||||
+ part->extended = has_extended &&
|
||||
+ (partition_table_entries >= hd->extended_partition);
|
||||
if (part->extended) {
|
||||
if (!hd->extended_lba)
|
||||
hd->extended_lba = now;
|
||||
@@ -289,13 +301,13 @@ static int hdimage_setup(struct image *image, cfg_t *cfg)
|
||||
part->name, part->offset, hd->align);
|
||||
return -EINVAL;
|
||||
}
|
||||
- if (part->offset || !part->in_partition_table) {
|
||||
+ if (part->offset && part->in_partition_table) {
|
||||
if (now > part->offset) {
|
||||
image_error(image, "part %s overlaps with previous partition\n",
|
||||
part->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
- } else {
|
||||
+ } else if (!part->offset && part->in_partition_table) {
|
||||
if (!now && hd->partition_table)
|
||||
now = 512;
|
||||
part->offset = roundup(now, hd->align);
|
||||
@@ -317,6 +329,7 @@ cfg_opt_t hdimage_opts[] = {
|
||||
CFG_STR("align", "512", CFGF_NONE),
|
||||
CFG_STR("disk-signature", "", CFGF_NONE),
|
||||
CFG_BOOL("partition-table", cfg_true, CFGF_NONE),
|
||||
+ CFG_INT("extended-partition", 0, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
--
|
||||
2.7.4
|
||||
|
89
buildroot-external/scripts/hdd_image.sh
Executable file
89
buildroot-external/scripts/hdd_image.sh
Executable file
@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
|
||||
BOOTSTATE_UUID="33236519-7F32-4DFF-8002-3390B62C309D"
|
||||
OVERLAY_BLOCK=131071
|
||||
DATA_BLOCK=131071
|
||||
BOOT_BLOCK=65535
|
||||
|
||||
function hassio_boot_image() {
|
||||
local boot_data=$1
|
||||
local boot_img=$2
|
||||
|
||||
echo "mtools_skip_check=1" > ~/.mtoolsrc
|
||||
dd if=/dev/zero of="$boot_img" bs=512 count=$BOOT_BLOCK
|
||||
mkfs.vfat -n "hassio-boot" "$boot_img"
|
||||
mcopy -i "$boot_img" -sv "$boot_data"/* ::
|
||||
}
|
||||
|
||||
function hassio_overlay_image() {
|
||||
local overlay_img=$1
|
||||
|
||||
dd if=/dev/zero of="$overlay_img" bs=512 count=$OVERLAY_BLOCK
|
||||
mkfs.ext4 "$overlay_img"
|
||||
tune2fs -L "hassio-overlay" -c0 -i0 "$overlay_img"
|
||||
}
|
||||
|
||||
function hassio_data_image() {
|
||||
local data_img=$1
|
||||
|
||||
dd if=/dev/zero of="$data_img" bs=512 count=$DATA_BLOCK
|
||||
mkfs.ext4 "$data_img"
|
||||
tune2fs -L "hassio-data" -c0 -i0 "$data_img"
|
||||
}
|
||||
|
||||
function hassio_hdd_image() {
|
||||
local boot_img=$1
|
||||
local rootfs_img=$2
|
||||
local overlay_img=$3
|
||||
local data_img=$4
|
||||
local hdd_img=$5
|
||||
|
||||
local boot_size="+32M"
|
||||
local boot_offset=0
|
||||
local rootfs_size="+256M"
|
||||
local rootfs_offset=0
|
||||
local overlay_size="+64M"
|
||||
local overlay_offset=0
|
||||
local data_size="+64M"
|
||||
local data_offset=0
|
||||
local bootstate_size="+8M"
|
||||
|
||||
|
||||
# Write new image & GPT
|
||||
dd if=/dev/zero of="$hdd_img" bs=1024K count=800
|
||||
sgdisk -o "$hdd_img"
|
||||
echo "GPT formating done"
|
||||
|
||||
# Boot
|
||||
boot_offset="$(sgdisk -F "$hdd_img")"
|
||||
sgdisk -n 1:$boot_offset:$boot_size -c 1:"hassio-boot" -t 1:"C12A7328-F81F-11D2-BA4B-00A0C93EC93B" "$hdd_img"
|
||||
dd if="$boot_img" of="$hdd_img" conv=notrunc bs=512 seek=$boot_offset
|
||||
echo "Boot formating done"
|
||||
|
||||
# System0
|
||||
rootfs_offset="$(sgdisk -F "$hdd_img")"
|
||||
sgdisk -n 2:$rootfs_offset:$rootfs_size -c 2:"hassio-system0" -t 2:"0FC63DAF-8483-4772-8E79-3D69D8477DE4" "$hdd_img"
|
||||
dd if="$rootfs_img" of="$hdd_img" conv=notrunc bs=512 seek=$rootfs_offset
|
||||
echo "System0 formating done"
|
||||
|
||||
# System1
|
||||
sgdisk -n 3:0:$rootfs_size -c 3:"hassio-system1" -t 3:"0FC63DAF-8483-4772-8E79-3D69D8477DE4" "$hdd_img"
|
||||
echo "System1 formating done"
|
||||
|
||||
# BootState
|
||||
sgdisk -n 4:0:$bootstate_size -c 4:"hassio-bootstate" -t 4:"0FC63DAF-8483-4772-8E79-3D69D8477DE4" -u 4:$BOOTSTATE_UUID "$hdd_img"
|
||||
echo "BootState formating done"
|
||||
|
||||
# Overlay
|
||||
overlay_offset="$(sgdisk -F "$hdd_img")"
|
||||
sgdisk -n 5:$overlay_offset:$overlay_size -c 5:"hassio-overlay" -t 5:"0FC63DAF-8483-4772-8E79-3D69D8477DE4" "$hdd_img"
|
||||
dd if="$overlay_img" of="$hdd_img" conv=notrunc bs=512 seek=$overlay_offset
|
||||
echo "Overlay formating done"
|
||||
|
||||
# Data
|
||||
data_offset="$(sgdisk -F "$hdd_img")"
|
||||
sgdisk -n 6:$data_offset:$data_size -c 6:"hassio-data" -t 6:"0FC63DAF-8483-4772-8E79-3D69D8477DE4" "$hdd_img"
|
||||
dd if="$data_img" of="$hdd_img" conv=notrunc bs=512 seek=$data_offset
|
||||
echo "Data formating done"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user