[COMMIT osv master] scripts: use common binary partition header file to build disk images

8 views
Skip to first unread message

Commit Bot

unread,
Jul 6, 2020, 10:56:53 PM7/6/20
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

scripts: use common binary partition header file to build disk images

The scripts/build accepts the '--create-disk' option to allow
creating disk images (disk.img) intended to be used when booting
OSv in direct kernel mode (-k option to run.py). Currently
the build script uses `build/last/boot.bin` as a partition table disk header.
Even though the end result is working, boot.bin contains unnecessary code
from arch/x64/boot16.S and more importantly is not present in aarch64 build.

So this patch adds tiny 512-bytes partition table template file (510 zeros followed by 0xaa, 0x55)
which is then used as a disk image header when creating a ROFS or ZFS disk.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/scripts/build b/scripts/build
--- a/scripts/build
+++ b/scripts/build
@@ -266,7 +266,7 @@ fi

if [[ ${vars[create_disk]} == "true" ]]; then
partition_offset=512
- bare=boot.bin
+ bare="$SRC"/scripts/disk.bin
raw_disk=disk
qcow2_disk=disk
upload_kernel_mode="-k"
diff --git a/scripts/disk.bin b/scripts/disk.bin
--- a/scripts/disk.bin
+++ b/scripts/disk.bin
null

Nadav Har'El

unread,
Jul 7, 2020, 2:00:46 AM7/7/20
to Waldemar Kozaczuk, Osv Dev
On Tue, Jul 7, 2020 at 5:56 AM Commit Bot <b...@cloudius-systems.com> wrote:
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

scripts: use common binary partition header file to build disk images

The scripts/build accepts the '--create-disk' option to allow
creating disk images (disk.img) intended to be used when booting
OSv in direct kernel mode (-k option to run.py). Currently
the build script uses `build/last/boot.bin` as a partition table disk header.
Even though the end result is working, boot.bin contains unnecessary code
from arch/x64/boot16.S and more importantly is not present in aarch64 build.

So this patch adds tiny 512-bytes partition table template file (510 zeros followed by 0xaa, 0x55)
which is then used as a disk image header when creating a ROFS or ZFS disk.

How did you determine this magic file needs to be exactly those bytes?
Your actual file has 0x55 first and then 0xaa, and not the other way around as you said it.... Does that matter?

By the way, you could have the script (or Makefile) create it with a command instead of having it pre-exist, for example:
    python -c 'import sys; sys.stdout.buffer.write(b"\0"*510+b"\x55\xaa")'
To make it easier for somebody to later change these bytes - but I don't know if that would ever be needed.


Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/scripts/build b/scripts/build
--- a/scripts/build
+++ b/scripts/build
@@ -266,7 +266,7 @@ fi

 if [[ ${vars[create_disk]} == "true" ]]; then
        partition_offset=512
-       bare=boot.bin
+       bare="$SRC"/scripts/disk.bin
        raw_disk=disk
        qcow2_disk=disk
        upload_kernel_mode="-k"
diff --git a/scripts/disk.bin b/scripts/disk.bin
--- a/scripts/disk.bin
+++ b/scripts/disk.bin
null

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/000000000000a1ab8005a9d1242a%40google.com.

Waldek Kozaczuk

unread,
Jul 7, 2020, 9:42:43 AM7/7/20
to OSv Development
On Tuesday, July 7, 2020 at 2:00:46 AM UTC-4 Nadav Har'El wrote:
On Tue, Jul 7, 2020 at 5:56 AM Commit Bot <b...@cloudius-systems.com> wrote:
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

scripts: use common binary partition header file to build disk images

The scripts/build accepts the '--create-disk' option to allow
creating disk images (disk.img) intended to be used when booting
OSv in direct kernel mode (-k option to run.py). Currently
the build script uses `build/last/boot.bin` as a partition table disk header.
Even though the end result is working, boot.bin contains unnecessary code
from arch/x64/boot16.S and more importantly is not present in aarch64 build.

So this patch adds tiny 512-bytes partition table template file (510 zeros followed by 0xaa, 0x55)
which is then used as a disk image header when creating a ROFS or ZFS disk.

How did you determine this magic file needs to be exactly those bytes?
Your actual file has 0x55 first and then 0xaa, and not the other way around as you said it.... Does that matter?
Yeah, I made a mistake when writing a comment. And yes the order matters.

I simply discovered that by looking at arch/x64/boot16.S and more importantly the code in fs/devfs/device.cc (read_partition_table) - https://github.com/cloudius-systems/osv/blob/771b61dc6813aa4807f020ad96edb9929259deab/fs/devfs/device.cc#L104-L148.

Yeah, in theory, we could have added this logic to scripts/imgedit.py which manipulates the partition table of a disk.
Reply all
Reply to author
Forward
0 new messages