[syslinux] port syslinux isohybrid perl script to C

H. Peter Anvin hpa at zytor.com
Wed Mar 31 14:53:51 PDT 2010


> 
> My own expertise is limited to the production
> of ISO images. I can predict the LBA of file
> isolinux.bin and the image size. I could
> take a blob of at most 32 KB, perform some
> prescribed computations, insert the results
> at some prescribed byte addresses, and write
> the patched blob as the beginning of the emerging
> ISO image.
> 
> Currently i lack of blob and prescriptions.
> 

The blobs are available in the Syslinux build tree under the names:

mbr/isohdp[fp]x*.bin

The default probably should be mbr/isohdppx.bin, but it's ultimately up
to the user.

User definable parameters:

-> MBR ID		(default random 32-bit number,
			 or preserved from previous instance)
-> Sector count		(default 32, range 1-63)
-> Head count		(default 64, range 1-256)
-> Partition offset	(default 0, range 0-64)
-> Partition number	(default 1, range 1-4)
-> Filesystem type	(default 0x17, range 1-255)

Note: the filesystem type is largely arbitrary, in theory it can be any
value other than 0x00, 0x05, 0x0f, 0x85, 0xee, or 0xef.  0x17 ("Windows
IFS Hidden") seems safeish, some people believe 0x83 (Linux) is better.


Here is the prescriptions for how to install it:

All numbers are littleendian.  "word" means 16 bits, "dword" means 32
bits, "qword" means 64 bits.

Common subroutine LBA_to_CHS():
	s = (lba % sector_count) + 1
	t = (lba / sector_count)
	h = (t % head_count)
	c = (t / head_count)

	if (c >= 1024):
		c = 1023
		h = head_count
		s = sector_count

	s = s | ((c & 0x300) >> 2)
	c = c & 0xff

	write byte h
	write byte s
	write byte c


Main:
	Pad image_size to a multiple of sector_count*head_count
	Use the input file unmodified for bytes 0..431
	write qword boot_lba		# Offset 432
	write dword mbr_id		# Offset 440
	write word 0			# Offset 444

	# Offset 446
	For each partition entry 1..4:
		if this_partition != partition_number:
			write 16 zero bytes
		else:
			write byte 0x80
			write LBA_to_CHS(partition_offset)
			write byte filesystem_type
			write LBA_to_CHS(image_size-1)
			write dword partition_offset
			write dword image_size

	# Offset 510
	write word 0xaa55

	Use the input file unmodified for bytes 512..32767
	(pad with zero as necessary)


For the option of dual metadata trees, the value partition_offset/4
would be the offset at which the second metadata tree should be entered.
 It may make more sense to specify partition_offset in CD sectors (2048
bytes) instead of disk sectors (512 bytes), but that's really up to you.

	-hpa




More information about the Syslinux mailing list