LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 09-24-2007, 10:45 PM   #1
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Rep: Reputation: 0
Format a disk image as MS-DOS?


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.

Githlar

Last edited by Githlar; 09-25-2007 at 12:23 PM.
 
Old 09-25-2007, 12:25 AM   #2
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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.
 
Old 09-25-2007, 03:33 AM   #3
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
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:

http://www.linuxquestions.org/questi...d.php?t=362506
 
Old 09-25-2007, 04:12 AM   #4
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
I figured it out. It's about time haha.

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:

dd if=/dev/sdc of=smallerdisk.img bs=512 count=[end sector]

That worked =)
 
Old 09-25-2007, 04:30 AM   #5
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
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.
 
Old 09-25-2007, 12:23 PM   #6
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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?

Last edited by Githlar; 09-25-2007 at 12:24 PM.
 
Old 09-25-2007, 01:28 PM   #7
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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?

Last edited by Githlar; 09-25-2007 at 01:45 PM.
 
Old 09-26-2007, 02:04 AM   #8
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Probably unhelpful, but it says exactly: "97440 K", which is to my mind about 97 M ...

As already said I have no experience with qemu...
 
Old 09-26-2007, 05:56 AM   #9
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Well. I think my problem was that it was a hard disk image. I had the MBR and boot record set all correctly on it, but something still went wrong.

So, I had to make a way oversized floppy image of the partition basically.

Here's how I did it:

1. Download a 1.44MB floppy image of some boot disk and the mkfloppyimg.sh script from http://people.cs.uchicago.edu/~gmura...downloads.html

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...
 
Old 09-26-2007, 04:23 PM   #10
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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.
 
Old 09-27-2007, 01:57 AM   #11
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Quote:
Originally Posted by Githlar View Post
...when I try to inject it using a hex editor, dd, and cat, it doesn't like it very much haha.
Oh dear. You do like to do it by force, don't you . What is the source of the wrong io.sys, can't you change it there?
 
Old 09-27-2007, 08:43 AM   #12
Githlar
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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.

Last edited by Githlar; 09-27-2007 at 08:46 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to convert dos to unix format kapilcool Linux - Software 3 06-15-2006 11:50 AM
Command to convert dos file to a unix format sathish80 Linux - Newbie 1 03-22-2006 11:32 PM
newline problem between DOS and Unix format cjs_pro Programming 7 03-11-2005 11:08 AM
Why do file names keep getting changed to dos 8.3 format on my usb drive? firehawk256 Linux - Newbie 1 02-25-2005 03:32 PM
DOS Floppy image w/ grub? hroman Linux - Software 5 10-09-2004 12:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration