[syslinux] isohybrid and ISO images whose size is not a multiple of 2048 bytes vs. VirtualBox

Thomas Schmitt scdbackup at gmx.net
Fri Feb 20 02:29:37 PST 2015


Hi,

> Now, I have a question:  what about the "offset" parameter? How it 
> modifies our assumptions and calculations if the "offset" parameter is 
> not zero?

The offset influences only the start address of the
partition. The alignment goal is about the end address.
So these concepts are nearly independent.

Of course, partition start must be smaller than partition
end. But a mountable ISO cannot be smaller than
18 * 2048 bytes = 72 in units of -o. And -o is limited
to 64. (Not so clear why ...)


A non-zero offset makes the MBR ISO partition unmountable
unless the ISO is specially prepared by a second superblock
and directory tree.
So isohybrid option -o is for experts, anyway.
 
The ISO partition covers the block range at least up to
the end of the ISO filesystem and includes the padding.
Even if it is not mountable, it still protects the ISO
filesystem from being regarded as free space by partition
editors.


> Perhaps the code will 
> be more clear to me when I'll see it included in isohybrid.c

This is a patch against
  http://git.kernel.org/cgit/boot/syslinux/syslinux.git/plain/utils/isohybrid.c

It roughly compiles here. (Up to missing uuid_generate.)
------------------------------------------------------------------------

--- isohybrid.c 2015-02-20 10:43:49.000000000 +0100
+++ isohybrid_test.c    2015-02-20 11:01:33.000000000 +0100
@@ -947,7 +947,7 @@ main(int argc, char *argv[])
     int i = 0;
     FILE *fp = NULL;
     uint8_t *buf = NULL, *bufz = NULL;
-    int cylsize = 0, frac = 0;
+    int cylsize = 0, frac = 0, align_factor, align_cylsize;
     size_t orig_gpt_size, free_space, gpt_size;
     struct iso_primary_descriptor descriptor;
 
@@ -1058,9 +1058,20 @@ main(int argc, char *argv[])
     isosize = lendian_int(descriptor.size) * lendian_short(descriptor.block_size);
     free_space = isostat.st_size - isosize;
 
+    /* Making sure that the resulting image size is divisible by 2048.
+       (Can waste nearly 32 MB. Should be done on user request only.)
+    */
+    if ((head * sector) % 4 == 0)
+        align_factor = 1;
+    else if ((head * sector) % 2 == 0)
+        align_factor = 2;
+    else
+        align_factor = 4;
+
     cylsize = head * sector * 512;
-    frac = isostat.st_size % cylsize;
-    padding = (frac > 0) ? cylsize - frac : 0;
+    align_cylsize = cylsize * align_factor;
+    frac = isostat.st_size % align_cylsize;
+    padding = (frac > 0) ? align_cylsize - frac : 0;
 
     if (mode & VERBOSE)
         printf("imgsize: %zu, padding: %d\n", (size_t)isostat.st_size, padding);

------------------------------------------------------------------------

I wrapped the essential code into a standalone program for
playing with a few numbers:

-h 255 -s 63 , ISO size 1085739008 :
  align_factor= 4 , padding= 32899072 , image size= 136.000000 cylinders

-h 252 -s 63 , ISO size 1085739008 :
  align_factor= 1 , padding= 3481600 , image size= 134.000000 cylinders

-h 128 -s 32  , ISO size 1085739008 :
  align_factor= 1 , padding= 585728 , image size= 518.000000 cylinders

"padding" is the actual waste.
Well, ISO size 1085739008 was designed to let -h 255 -s 63 look bad.
Let's choose some random size around 1.5 GB: 2048 * 723452 

-h 255 -s 63 , ISO size 1481629696 :
  align_factor= 4 , padding= 31821824 , image size= 184.000000 cylinders

-h 252 -s 63 , ISO size 1481629696 :
  align_factor= 1 , padding= 5888000 , image size= 183.000000 cylinders

-h 128 -s 32 , ISO size 1481629696 :
  align_factor= 1 , padding= 1056768 , image size= 707.000000 cylinders

Bad luck again.
I swear i just toggled a 7 and then blindly 5 digits
for the "random" number.
More tries

-h 255 -s 63 , ISO size 1478760448 :
  align_factor= 4 , padding= 1789952 , image size= 180.000000 cylinders

-h 255 -s 63 , ISO size 1630908416 :
  align_factor= 4 , padding= 14147584 , image size= 200.000000 cylinders

I expect the average waste to be a bit less than 16 MB.


Have a nice day :)

Thomas



More information about the Syslinux mailing list