I also managed to create a successfully bootable ISO, but did not use DOSEMU and did so on a current Linux distro with a 5.10 kernel . I used a Windows 98 SE bootable rescue floppy (as created in Windows 98 SE) as a starting point, but this should be adaptable to practically any DOS version (ok, maybe not if your preferred version does not have fixed disk support 😉 )
If using a version of DOS below 5.00 , DOS fdisk will not have an /mbr option . This means that the partitioning and formating will need to be done manually on the mounted disk image from within DOSBox (I have tested this once : instead of creating the partition with Linux fdisk, I did it from within DOSBOX and then DOS 7.1's format /s was enough the make the partition successfully bootable without running fdisk /mbr )
a) use bximage to create a 504MB image file ( could have used dd, but bximage calculates cylinder count for me) :
bximage -mode=create -hd=504 -imgmode=flat -q /disk/newc.img
root@openmediavault:/disk# bximage -mode=create -hd=504 -imgmode=flat -q /disk/newc.img
========================================================================
bximage
Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
$Id: bximage.cc 13069 2017-02-12 16:51:52Z vruppert $
========================================================================
Creating hard disk image '/disk/newc.img' with CHS=1024/16/63
The following line should appear in your bochsrc:
ata0-master: type=disk, path="/disk/newc.img", mode=flat
Spoiler
b) use Linux fdisk to create a DOS partition table with a single FAT16 NON-LBA partition (type 6) I also set partition active/bootable :
printf "o\n n\n p\n 1\n \n \n t\n 6\n a\n w\n" | fdisk -c=dos /disk/newc.img
root@openmediavault:/disk# printf "o\n n\n p\n 1\n \n \n t\n 6\n a\n w\n" | fdisk -c=dos /disk/newc.img[/b]
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
DOS-compatible mode is deprecated.
Created a new DOS disklabel with disk identifier 0x5e45079f.
Command (m for help): DOS-compatible mode is deprecated.
Created a new DOS disklabel with disk identifier 0xedc7fe70.
Command (m for help): Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): Partition number (1-4, default 1): First sector (63-1032191, default 63): Last sector, +/-sectors or +/-size{K,M,G,T,P} (63-1032191, default 1032191):
Created a new partition 1 of type 'Linux' and of size 504 MiB.
Command (m for help): Selected partition 1
Hex code (type L to list all codes): Changed type of partition 'Linux' to 'FAT16'.
Command (m for help): Selected partition 1
The bootable flag on partition 1 is enabled now.
Command (m for help): The partition table has been altered.
Syncing disks.
root@openmediavault:/disk# fdisk -l /disk/newc.img
Disk /disk/newc.img: 504 MiB, 528482304 bytes, 1032192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xedc7fe70
Device Boot Start End Sectors Size Id Type
/disk/newc.img1 * 63 1032191 1032129 504M 6 FAT16
Spoiler
c) Tweak the Windows 98 SE boot floppy image # warning do not boot from that floppy image unless you intend it to automatically format the c: drive without prompting:
mount /disk/win98floppy.img /mnt
sed -i 's/menudefault=CD,30/menudefault=NOCD,1/g' /mnt/CONFIG.SYS
dos2unix /mnt/AUTOEXEC.BAT
echo "%RAMD%:\format c: /s /autotest" >> /mnt/AUTOEXEC.BAT
echo "fdisk /mbr" >> /mnt/AUTOEXEC.BAT
unix2dos /mnt/AUTOEXEC.BAT
umount /mnt
Spoiler
root@openmediavault:/disk# mount /disk/win98floppy.img /mnt
root@openmediavault:/disk# sed -i 's/menudefault=CD,30/menudefault=NOCD,1/g' /mnt/CONFIG.SYS
root@openmediavault:/disk# dos2unix /mnt/AUTOEXEC.BAT
dos2unix: converting file /mnt/AUTOEXEC.BAT to Unix format...
root@openmediavault:/disk# echo "%RAMD%:\format c: /s /autotest" >> /mnt/AUTOEXEC.BAT
root@openmediavault:/disk# echo "fdisk /mbr" >> /mnt/AUTOEXEC.BAT
root@openmediavault:/disk# unix2dos /mnt/AUTOEXEC.BAT
unix2dos: converting file /mnt/AUTOEXEC.BAT to DOS format...
root@openmediavault:/disk# umount /mnt
d) Let DOSBox format the partition for you using the floppy image modified in step c : and close DOSBox once format has finished .
dosbox -c "mount d /disk" -c "d:" -c "imgmount 2 \"newc.img\" -size 512,63,16,1024 -t hdd -fs none" -c "boot \"win98floppy.img\""
format.png
Spoiler
e) Copy the HD image to the folder you want to use and generate the ISO file
cp /disk/newc.img /outiso/
genisoimage -b newc.img -hard-disk-boot -o /disk/new.iso /outiso
root@openmediavault:/disk# genisoimage -b newc.img -hard-disk-boot -o /disk/new.iso /outiso
I: -input-charset not specified, using utf-8 (detected in locale settings)
Size of boot image is 1032192 sectors -> Emulating a hard disk
Warning: image size does not match geometry (262080)
1.94% done, estimate finish Wed Jul 28 16:55:32 2021
3.88% done, estimate finish Wed Jul 28 16:55:32 2021
5.81% done, estimate finish Wed Jul 28 16:55:32 2021
7.75% done, estimate finish Wed Jul 28 16:55:32 2021
9.68% done, estimate finish Wed Jul 28 16:55:32 2021
11.62% done, estimate finish Wed Jul 28 16:55:32 2021
13.55% done, estimate finish Wed Jul 28 16:55:32 2021
15.49% done, estimate finish Wed Jul 28 16:55:32 2021
17.43% done, estimate finish Wed Jul 28 16:55:32 2021
19.37% done, estimate finish Wed Jul 28 16:55:32 2021
21.30% done, estimate finish Wed Jul 28 16:55:32 2021
23.24% done, estimate finish Wed Jul 28 16:55:32 2021
25.17% done, estimate finish Wed Jul 28 16:55:32 2021
27.11% done, estimate finish Wed Jul 28 16:55:32 2021
29.05% done, estimate finish Wed Jul 28 16:55:32 2021
30.98% done, estimate finish Wed Jul 28 16:55:32 2021
32.92% done, estimate finish Wed Jul 28 16:55:32 2021
34.86% done, estimate finish Wed Jul 28 16:55:32 2021
36.79% done, estimate finish Wed Jul 28 16:55:32 2021
38.73% done, estimate finish Wed Jul 28 16:55:32 2021
40.66% done, estimate finish Wed Jul 28 16:55:34 2021
42.60% done, estimate finish Wed Jul 28 16:55:34 2021
44.54% done, estimate finish Wed Jul 28 16:55:34 2021
46.48% done, estimate finish Wed Jul 28 16:55:34 2021
48.41% done, estimate finish Wed Jul 28 16:55:34 2021
50.35% done, estimate finish Wed Jul 28 16:55:33 2021
52.28% done, estimate finish Wed Jul 28 16:55:33 2021
54.22% done, estimate finish Wed Jul 28 16:55:33 2021
56.15% done, estimate finish Wed Jul 28 16:55:33 2021
58.09% done, estimate finish Wed Jul 28 16:55:33 2021
60.03% done, estimate finish Wed Jul 28 16:55:33 2021
61.97% done, estimate finish Wed Jul 28 16:55:33 2021
63.90% done, estimate finish Wed Jul 28 16:55:33 2021
65.84% done, estimate finish Wed Jul 28 16:55:33 2021
67.77% done, estimate finish Wed Jul 28 16:55:33 2021
69.71% done, estimate finish Wed Jul 28 16:55:33 2021
71.64% done, estimate finish Wed Jul 28 16:55:33 2021
73.58% done, estimate finish Wed Jul 28 16:55:33 2021
75.52% done, estimate finish Wed Jul 28 16:55:33 2021
77.46% done, estimate finish Wed Jul 28 16:55:33 2021
79.39% done, estimate finish Wed Jul 28 16:55:33 2021
81.33% done, estimate finish Wed Jul 28 16:55:33 2021
83.26% done, estimate finish Wed Jul 28 16:55:33 2021
85.20% done, estimate finish Wed Jul 28 16:55:33 2021
87.13% done, estimate finish Wed Jul 28 16:55:33 2021
89.07% done, estimate finish Wed Jul 28 16:55:33 2021
91.01% done, estimate finish Wed Jul 28 16:55:33 2021
92.95% done, estimate finish Wed Jul 28 16:55:33 2021
94.88% done, estimate finish Wed Jul 28 16:55:33 2021
96.82% done, estimate finish Wed Jul 28 16:55:33 2021
98.75% done, estimate finish Wed Jul 28 16:55:33 2021
Total translation table size: 2048
Total rockridge attributes bytes: 0
Total directory bytes: 156
Path table size(bytes): 10
Max brk space used 0
258224 extents written (504 MB)
Spoiler
Of course, if one wants to add files to the HDD the image prior to creating the ISO, mount the image through a loop device and copying files to it is possible as is using MTOOLS, if desired (no offset specify in either case as no DOSEMu header). I chose a 504MB image size as that is the biggest size that is mountable is DOSBox without resorting to fudging head/cylinder values (i.e. doubling the number of heads and halving the number of cylinders to keep cylinder count at 1024 or less) .
Also, it seems that multi-partition disk images cannot be used to create a bootable HDD image on an ISO using genisoimage (mkisofs successor). Whether this a limitation of the El Torito spec or of genisoimage I do not know .
root@openmediavault:/disk# genisoimage -b c.img -hard-disk-boot -o new.iso /outiso
I: -input-charset not specified, using utf-8 (detected in locale settings)
Size of boot image is 1252944 sectors -> Emulating a hard disk
Warning: image size does not match geometry (17316)
genisoimage: Boot image '/outiso/c.img' has multiple partitions.