Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Okay... so I was trying to setup dsl (damn small linux) to boot off a usb drive. I found my BIOS wasn't booting from it when using a USB-HDD mode so I found a page for using SYSLINUX to set it up in USB-ZIP mode (http://syslinux.zytor.com/usbkey.php).
I used a Live Ubuntu CD to follow the instructions on the page. In Ubuntu I could see my NTFS Windows XP drive, and 2 USB drives, the one being a 230GB External Hard-Drive (NTFS) and the other being my 256mb usb drive (FAT32). I unmounted all except the 256mb drive, went to console and typed 'sudo fdisk -l' to find the info on the drive's sectors to follow the calculations on the page.
Ah... to the point: I did exactly what the page warned against not doing and used the mkdiskimage command on the wrong drive. I typed 'sudo ./mkdiskimage -4 /dev/sdb 243 64 32' instead of typing /dev/sdc and now all my data on my External Drive is inaccessable from any operating system.
I haven't performed any other read,write,partition (or format) commands since running the mkdiskimage script.
Is there anyway to undo what I've done?

One solution is to get the System Rescue CD, a live CD image containing a number of tools useful for disaster recovery and system maintenance. The tool you want on this CD is the Test-Disk utility.
The description from the System Rescue CD
page follows:Test-disk - tool to check and
undelete partition, supports reiserfs, ntfs,
fat32, ext2/3 and many othersHTH,
Ernie Registered Linux User 247790

The script "mkdiskimage" which is supplied with the syslinux
distribution can be used to initialize USB keys in a Zip-like fashion.
To do that, calculate the correct number of cylinders (31 in the
example above), and, if your USB key is /dev/sda (CHECK THE KERNEL
MESSAGES CAREFULLY - IF YOU ENTER THE WRONG DISK DRIVE IT CANNOT BE
RECOVERED),
I doubt you can go against this info. The author is a guru. Not sure why you can not re-enter the command with the original specs of the disk and access it.As a note. You didn't have to do all this. Simply using syslinux (usbdrive letter) in xp would have worked. Not even sure why you didn't use dsl to install to usb.
"Best Practices", Event viewer, host file, perfmon, are in my top 10

I didn't have dsl as an ISO file, only the embedded version, and I have no idea how to run a script in Windows (I doubt just renaming it to .bat would work?). Also all the other commands were for programs already (or easily) available on linux.
I have so far been able to recover a lot of my files using 'Partition Find and Mount', and after I've copied all the valid files I'm going to try other methods (that actually alter the drive) like seeing if TestDisk can fix the drive.
Thanks for the help so far, the ideal situation would be if somebody knew exactly what the 'mkdiskimage' script does, and if there is a way to (partially?) undo it by, for instance, re-entering the command with the original specs of the disk.

This will do you no good but here it is.
It makes a drive look to the bios like a zip drive. The thinking is that a zip drive may be more bootable than a usb-hd.
The problem is if you changed the geometry and wrote to the areas as part of the format.You can always load it as a raw device and poke around sector by sector. The issue is still what is a good sector?
"#!/usr/bin/perl
----------------
## $Id: syslinux-mkdiskimage,v 1.1 2006/03/09 06:36:48 yama Exp $
##
## Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
## Boston MA 02111-1307, USA; either version 2 of the License, or
## (at your option) any later version; incorporated herein by reference.
##
----------------#
# Creates a blank MS-DOS formatted hard disk image
#use bytes;
use integer;
use Fcntl;
use Errno;
use Cwd;
use IO::Handle; # For flush()sub absolute_path($) {
my($f) = @_;
my($c);return $f if ( $f =~ /^\// );
$c = cwd();
$c = '' if ( $c eq '/' );
return $c.'/'.$f;
}sub is_linux() {
return !!eval '{ '.
'use POSIX; '.
'($sysname, $nodename, $release, $version, $machine) = POSIX::uname(); '.
"return \$sysname eq \'Linux\'; }";
}
$is_linux = is_linux();
if ( $is_linux ) {
# IOCTL numbers
$BLKRRPART = 0x125f;
$BLKGETSIZE = 0x1260;
}%opt = ();
@args = ();for $a ( @ARGV ) {
if ( $a =~ /^\-/ ) {
foreach $o ( split(//, substr($a,1)) ) {
$opt{$o} = 1;
}
} else {
push(@args, $a);
}
}($file,$c,$h,$s) = @args;
$c += 0; $h += 0; $s += 0;$pentry = 1;
$pentry = 2 if ( $opt{'2'} );
$pentry = 3 if ( $opt{'3'} );
$pentry = 4 if ( $opt{'4'} );if ( $opt{'M'} ) {
# Specify size in megabytes, not in cylinders
$c = ($c*1024*2)/($h*$s);
}$is_open = 0;
if ( $c == 0 && $file ne '' ) {
$len = 0;
if ( sysopen(OUTPUT, $file, O_RDWR, 0666) ) {
$is_open = 1;if ( (@filestat = stat(OUTPUT)) && S_ISREG($filestat[2]) ) {
$len = $filestat[7] >> 9;
} elsif ( $is_linux && S_ISBLK($filestat[2]) ) {
$blksize = pack("L!", 0);
if ( ioctl(OUTPUT, $BLKGETSIZE, $blksize) == 0 ) {
$len = unpack("L!", $blksize); # In 512-byte sectors!
}
}
}if ( !$len ) {
print STDERR "$0: $file: don't know how to determine the size of this device\n";
exit 1;
}$c = $len/($h*$s);
}if ( $file eq '' || $c < 1 || $c > 1024 ||
$h < 1 || $h > 256 || $s < 1 || $s > 63 ) {
print STDERR "Usage: $0 [-doF4] file [c h s] (max: 1024 256 63)\n";
print STDERR " -d add DOSEMU header\n";
print STDERR " -o print filesystem offset to stdout\n";
print STDERR " -F format partition as FAT32\n";
print STDERR " -M \"c\" argument is megabytes, calculate cylinders\n";
print STDERR " -4 use partition entry 4 (standard for zipdisks)\n";
exit 1;
}$cylsize = $h*$s*512;
if ( !$is_open ) {
sysopen(OUTPUT, $file, O_CREAT|O_RDWR|O_TRUNC, 0666)
or die "$0: Cannot open: $file\n";
}
binmode OUTPUT;# Print out DOSEMU header, if requested
if ( $opt{'d'} ) {
$emuhdr = "DOSEMU\0" . pack("VVVV", $h, $s, $c, 128);
$emuhdr .= "\0" x (128 - length($emuhdr));
print OUTPUT $emuhdr;
}# Print the MBR and partition table
$mbr = '';
while ( $line = <DATA> ) {
chomp $line;
foreach $byte ( split(/\s+/, $line) ) {
$mbr .= chr(hex($byte));
}
}
if ( length($mbr) > 446 ) {
die "$0: Bad MBR code\n";
}$mbr .= "\0" x (446 - length($mbr));
print OUTPUT $mbr;
# Print partition table
$psize = $c*$h*$s-$s;
$bhead = ($h > 1) ? 1 : 0;
$bsect = 1;
$bcyl = ($h > 1) ? 0 : 1;
$ehead = $h-1;
$esect = $s + ((($c-1) & 0x300) >> 2);
$ecyl = ($c-1) & 0xff;
if ( $psize > 65536 ) {
$fstype = 0x06;
} else {
$fstype = 0x04;
}
for ( $i = 1 ; $i <= 4 ; $i++ ) {
if ( $i == $pentry ) {
print OUTPUT pack("CCCCCCCCVV", 0x80, $bhead, $bsect, $bcyl, $fstype,
$ehead, $esect, $ecyl, $s, $psize);
} else {
print OUTPUT "\0" x 16;
}
}
print OUTPUT "\x55\xaa";# Output blank file
$totalsize = $c*$h*$s;
$tracks = $c*$h;$track = "\0" x (512*$s);
# Print fractional track
print OUTPUT "\0" x (512 * ($s-1));for ( $i = 1 ; $i < $tracks ; $i++ ) {
print OUTPUT $track;
}# Print mtools temp file
$n = 0;
while ( !defined($tmpdir) ) {
$tmpdir = "/tmp/mkdiskimage.$$.".($n++);
if ( !mkdir($tmpdir, 0700) ) {
die "$0: Failed to make temp directory: $tmpdir\n"
if ( $! != EEXIST );
undef $tmpdir;
}
}$cfgfile = $tmpdir.'/mtools.conf';
$imglink = $tmpdir.'/disk.img';
die "$0: Failed to create symlink $imglink\n"
if ( !symlink(absolute_path($file), $imglink) );$header_size = ($opt{'d'} ? 128 : 0);
# Start of filesystem
$offset = $s*512 + $header_size;# Start of partition table entry
$pstart = $header_size + 446 + 16*($pentry-1);open(MCONFIG, "> ${cfgfile}") or die "$0: Cannot make mtools config\n";
print MCONFIG "drive z:\n";
print MCONFIG "file=\"${imglink}\"\n";
print MCONFIG "cylinders=${c}\n";
print MCONFIG "heads=${h}\n";
print MCONFIG "sectors=${s}\n";
print MCONFIG "offset=${offset}\n";
print MCONFIG "mformat_only\n";
close(MCONFIG);# Output the filesystem offset to stdout if appropriate
if ( $opt{'o'} ) {
print $offset, "\n";
}$ENV{'MTOOLSRC'} = $cfgfile;
if ( $opt{'F'} ) {
system('mformat', '-F', 'z:');
} else {
system('mformat', 'z:');
}# Clean up in /tmp
unlink($cfgfile);
unlink($imglink);
rmdir($tmpdir);# MTOOLS doesn't write the bsHiddenSecs field correctly
seek(OUTPUT, $offset + 0x1c, 0);
print OUTPUT pack("V", ($offset-$header_size)>>9);# Set the partition type
if ( $opt{'F'} ) {
$fstype = 0x0b; # FAT32
} else {
if ( $psize > 65536 ) {
$fstype = 0x06; # FAT16 > 32MB
} else {
$fstype = 0x04; # FAT16 <= 32MB
}
seek(OUTPUT, $offset + 0x36, 0);
read(OUTPUT, $fsname, 8);
# FAT12: adjust partition type
if ( $fsname eq 'FAT12 ' ) {
$fstype = 0x01; # FAT12
}
}
seek(OUTPUT, $pstart+4, 0);
print OUTPUT pack("C", $fstype);flush OUTPUT;
# Just in case this is a block device, try to flush the partition table
if ( $is_linux ) {
ioctl(OUTPUT, $BLKRRPART, 0);
};exit 0;
__END__
fa 31 c0 8e d8 8e c0 8e d0 bc 0 7c fb fc 89 e6 bf 0 6 b9 0 1 f3 a5 ea 1d 6 0 0 88 16 0 8 b4 8 cd 13
31 c0 88 f0 40 a3 f0 6 80 e1 3f 88 e f2 6 be be 7 31 c0 b9 4 0 f6 4 80 74 3 40 89 f7 83 c6 10 e2 f3 83
f8 1 75 73 8a 16 0 8 b8 0 41 bb aa 55 31 c9 30 f6 f9 cd 13 72 23 81 fb 55 aa 75 1d f6 c1 1 74 18 57 be e0
6 8b 5d 8 89 5c 8 8b 5d a 89 5c a 8a 16 0 8 b4 42 eb 2a 57 8b 45 8 8b 55 a f7 36 f2 6 42 89 d1 31 d2
f7 36 f0 6 88 c5 d1 e8 d1 e8 24 c0 8 c1 88 d6 8a 16 0 8 bb 0 7c b8 1 2 cd 13 72 16 5e 81 3e fe 7d 55 aa
75 8 fa ea 0 7c 0 0 77 5 be f4 6 eb 3 be f 7 ac 20 c0 74 c b4 e 8a 3e 62 4 b3 7 cd 10 eb ef eb fe
0 0 10 0 1 0 0 7c 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4d 69 73 73 69 6e 67 20 6f 70 65 72 61 74 69
6e 67 20 73 79 73 74 65 6d d a 0 4f 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d 20 6c 6f 61 64 69 6e 67 20
65 72 72 6f 72 d a 0 ""Best Practices", Event viewer, host file, perfmon, are in my top 10

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |