Sunday, February 17, 2008

Making Bootable USB Drives Recognizable on Windows, Again

A couple of weeks back, I "borrowed" my sister's 256MB USB flash memory and put Slax on it.

Now, my sister wants her "USB" back, which I tried to explain that if I give her just the USB part it won't work as intended. As funny as I was, she didn't think so, and she wanted the WHOLE thing back. And working.

Windows didn't recognize the whole device and couldn't even see it as a removable disk, so formatting was not an option, yet.

Using a Windows XP bootable CD and trying to use fixmbr failed, because the recovery console failed to see the USB drive.

I fixed it on Linux, by using "dd" to write zeros on the disk (/dev/sdf in my case), then used fdisk (not cfdisk) to write a DOS partition table, then created a new primary partition with type "Windows 95 FAT" (b).

root@adrenalin:~# dd if=/dev/zero of=/dev/sdf
dd: writing to `/dev/sdf': No space left on device
517121+0 records in
517120+0 records out
264765440 bytes (265 MB) copied, 110.158 s, 2.4 MB/s


root@adrenalin:~# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF
disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by
w(rite)

Command (m for help): p

Disk /dev/sdf: 264 MB, 264765440 bytes
9 heads, 57 sectors/track, 1008 cylinders
Units = cylinders of 513 * 512 = 262656 bytes

Device Boot Start End Blocks Id System

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): o
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by
w(rite)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1008, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1008, default 1008):
Using default value 1008

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)

Command (m for help): p

Disk /dev/sdf: 264 MB, 264765440 bytes
9 heads, 57 sectors/track, 1008 cylinders
Units = cylinders of 513 * 512 = 262656 bytes

Device Boot Start End Blocks Id System
/dev/sdf1 1 1008 258523+ b W95 FAT32

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.


The disk is fixed, but doesn't have a filesystem. You can either make one in Linux, or slap it on a Windows machine & format it.

To make a FAT32 filesystem on Linux, run:
mkfs.vfat -F 32 /dev/sdf1

2 comments:

Otek said...

Thanks techy I've used this twice to restore thumb drives after using as a live distro.

MBH said...

Glad it helped :D