Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a bootable flash drive that boots one of my favorite DOS-based bootdisks. However, if I use dd to make an image of the disk, it also copies over the free space, which is not what I intended. So, I decided to try to mount a hard disk image and my existing USB image under qemu (so I an copy the files from my bootable USB image to my new hard drive image.
OK. I'm trying to make a hard disk image that is able to boot into DOS.
OK, here's what I've tried (keep in mind, I really don't know what I'm doing):
1) I'm working with a RAW disk image created with qemu-img as I don't know how to resize an existing disk image. The image is 77M. I used the command: qemu-img -f raw disk.img 77M
2a) I've tried this so many ways and the drive image will never boot in qemu. I've tried booting into FreeDOS, but using the SYS command installs the Syslinux bootloader and files, which is not what I need to use. I need to use the original DOS loader and files - I have the files from a boot disk which should be all I need as I understand. I've set up the drive in FreeDOS, but I don't see a way to make it bootable.
2b) I've used `ms-sys -d -f disk.img` to install what I believe is the proper MBR and then used the CFDISK utility in FreeDOS to set up the partitions and then the FORMAT C: (the disk image under qemu) to format the partition as a DOS partition. I then copied the files from my usable/bootable usb image.
I've tried many other methods that I can't think of at the moment. I'm starting to get extremely frustrated at this. I need a quick and dirty solution if it's possible, but I'm willing to try anything.
2c) Oh, I also tried extracting the MBR of my bootable USB drive with FDISK in FreeDOS and replacing the C: drive's (the disk image I'm trying to manipulate) MBR, but that didn't work either.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
I must confess that I can't really follow your explanation and I don't have experience with qemu. For what it is worth, here is a link for a thorough explanation of the dd command, I hope it can help:
I had tried this:
dd if=/dev/sdc of=mbr bs=512 count=1
dd if=/dev/sdc1 of=partition1
cat mbr partition1 > finalimage.img
But that didn't work. I found out later that it was looking for the partition on sector 63, and after using the above commands, the final result was the partition was on sector 2. Of course, that caused problems =)
So, I just copied the disk from sector 1 straight to the end of the partition I wanted to keep:
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
Glad you solved it. Still, you might want to have a look at the link I posted above in a quiet moment. Exactly your difficulty is treated there. Good luck.
Perhaps I haven't solved it. Now Memdisk is telling me that the image has a fractional last cylinder.
I think I have to set the c/h/s, but I don't know what it should be. Surely the cylinders shouldn't be the same number that's on my flash drive, because the file is not the same size?
Perhaps the image has to be rounded off to the nearest cylinder.
Well, I did that and Memdisk doesn't complain about the image anymore, however it does still hang right after it says its booting.
"Loading boot sector... booting...
j"
That 'j' is what throws me. That's what was showing up sometimes when the disk was not working. That is the output under both Qemu and the actual output from booting.
But that's also really odd, because using Qemu, the image itself boot, but when it's run as an argument to Memdisk, it fails.
Here's the full output of Memdisk:
Quote:
Ready.
MEMDISK 3.11 Debian-2007-03-12 Copyright 2001-2005 H. Peter Anvin
e820: 0000000000000000 000000000009fc00 1
e820: 000000000009fc00 0000000000000400 2
e820: 00000000000e8000 0000000000018000 2
e820: 0000000000100000 0000000007f00000 1
e820: 00000000fffc0000 0000000000040000 2
Ramdisk at 0x020d8000, length 0x05f28000
command line: initrd=hrn.img c=3 h=64 s=1015 harddisk BOOT_IMAGE=memdisk
Disk is hard disk 0, 97440 K, C/H/S = 3/64/1015
Total size needed = 1904 bytes, allocating 2K
Old dos memory at 0x9fc00 (map says 0x9fc00), loading at 0x9f400
1588: 0x7f60 15E801: 0x3c00 0x010d
INT 13 08: Success, count = 1, BPT = 0000:0000
old: int13 = f000e3f3 int15 = f000f859
new: int13 = 9f400008 int15 = 9f400290
Loading boot sector... booting...
j
Hm. A couple things I noted while typing that: It says the hard disk is 97K, when it's actually about 97M. If 'map says 0x9fc00,' then why's it loading at 0x9f400?
2. Modify the necessary values in mkfloppyimg.sh and run it. You should now end up with an oversized image formatted as a floppy with all of the files of the original boot disk as well as the C/H/S values. Very cool. Make note of that command line given to you.
3. Mount the floppy image:
Code:
losetup /dev/loop0 oversizefloppy.img
mount /dev/loop0 /mnt/point
4. Add the files you want to add to it.
5. Unmount:
Code:
umount /mnt/point
losetup -d /dev/loop0
6. Now you can boot that floppy image with Memdisk like this:
syslinux.cfg:
Code:
LABEL test
KERNEL memdisk
APPEND [argument]
Where [argument] is the string that mkfloppyimg.sh reports after finishing.
That sure was a helpful script. It took me long enough to find it though haha *Literally has about 50 Firefox tabs open*. That was the part I was having problems with: getting a correct CHS values to pass to memdisk. I wonder if I could use those values I got from mkfloppyimg.sh and use them on my hard disk image...
I got it to boot, but the io.sys file is different than the one I need, and when I try to inject it using a hex editor, dd, and cat, it doesn't like it very much haha.
Well, the BootCD I'm using has a custom edited IO.SYS. I found that I can boot into DOS on the CD and use the SYS command to write that custom IO.SYS to a bootable floppy. However, now that script I mentioned above doesn't work. I need to find out where the size info is on the floppy image so I can leave it out when I copy it to the bigger floppy image.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.