partitioning - Format flash drive without partitions

05
2014-04
  • vityav

    I'm trying to format a flash drive with a FAT partition to use in my car stereo, but running into a small problem. I've tried making it all one big FAT 16 partition, and the stereo won't accept it. Another flash drive I formatted in Windows works, but fdisk -l shows this:

    Disk /dev/sdc: 4009 MB, 4009754624 bytes
    124 heads, 62 sectors/track, 1018 cylinders, total 7831552 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
    Disk identifier: 0x6f20736b
    
    This doesn't look like a partition table
    Probably you selected the wrong device.
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdc1   ?   778135908  1919645538   570754815+  72  Unknown
    /dev/sdc2   ?   168689522  2104717761   968014120   65  Novell Netware 386
    /dev/sdc3   ?  1869881465  3805909656   968014096   79  Unknown
    /dev/sdc4   ?  2885681152  2885736650       27749+   d  Unknown
    
    Partition table entries are not in disk order
    

    Which to me looks like corruption, but apparently is normal for flash drives.

    Trying to format this one without a partition (as in mkfs.vfat -I /dev/sdd) only shows

    Disk /dev/sdd: 7876 MB, 7876902912 bytes
    243 heads, 62 sectors/track, 1021 cylinders, total 15384576 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
    Disk identifier: 0x00000000
    
       Device Boot      Start         End      Blocks   Id  System
    

    and still doesn't work in the stereo. So my question is how do I replicate that specific formatting in linux? Short-term (for a roadtrip this weekend) I'm okay with somehow using dd and only half the space on the new drive, but would like to know how to accurately replicate it without a working drive in the future.

    Edit: did dd if=/dev/sdc of=/dev/sdd bs=4096 conv=notrunc,noerror and now fdisk -l shows both drives as being the same other than the number of bytes, but it still doesn't work, so despite the manual saying my stereo accepts 8GB sticks, maybe apparently doesn't?

    Thanks

  • Answers
  • Rod Smith

    Given your edit that a dd copy doesn't work, my guess is that this is a hardware incompatibility. It might not be the 8GB size that's the problem, though; it could be an electronic issue. I've heard of such electronic problems preventing some USB flash drives from working as boot devices in PCs, although they work fine as normal data disks. IIRC, the culprit in that case seemed to be something about the amperage of the device, but my memory is foggy. It might be worth simply buying a new flash drive.


  • Related Question

    linux - Partition table corrupted (USB flash drive)
  • Questioner

    It's an 8 GB Patriot thumb drive, which I've used extensively with lots of data. Today, it is detected, but all data is gone: (EDIT at least some data is still there, but the partition table is gone)


    EDIT @Sathya (thanks) here's the relevant output from sudo fdisk -l:

    Disk /dev/sdc: 8019 MB, 8019509248 bytes
    247 heads, 62 sectors/track, 1022 cylinders
    Units = cylinders of 15314 * 512 = 7840768 bytes
    
    Disk /dev/sdc doesn't contain a valid partition table
    

    It looks like it is /dev/sdc, with that 8 GB... and no partition table.

    I tried to mount /dev/sdc (and then dmesg | tail):

    /media> sudo mount /dev/sdc mytmp
    mount: wrong fs type, bad option, bad superblock on /dev/sdc,
           missing codepage or other error
           In some cases useful info is found in syslog - try
           dmesg | tail  or so
    
    /media> dmesg | tail
    [   24.300000]  sdc: unknown partition table
    [   24.320000] sd 2:0:0:0: Attached scsi removable disk sdc
    [   24.370000] usb-storage: device scan complete
    [   26.870000] EXT2-fs error (device sdc): ext2_check_descriptors: Block bitmap for group 1 not in group (block 0)!
    [   26.870000] EXT2-fs: group descriptors corrupted!
    [   50.420000] unhashed dentry being revalidated: .DCOPserver_eeepc-brendanma__0
    [   50.430000] unhashed dentry being revalidated: .DCOPserver_eeepc-brendanma__0
    [   50.430000] unhashed dentry being revalidated: .DCOPserver_eeepc-brendanma__0
    [ 5565.470000] EXT2-fs error (device sdc): ext2_check_descriptors: Block bitmap for group 1 not in group (block 0)!
    [ 5565.470000] EXT2-fs: group descriptors corrupted!
    

    EDIT @Col: results from testdisk

    Disk /dev/sdc - 8013 MB / 7642 MiB - CHS 1022 247 62
    Current partition structure:
         Partition                  Start        End    Size in sectors
    
    Partition sector doesn't have the endmark 0xAA55
    

    After I hit [proceed], it says:

    Structure: Ok.
    
    
    Keys A: add partition, L: load backup, Enter: to continue
    

    The "Structure: Ok." seems reassuring... will "A: add partition" make my old data accessible (if it's still there), or will it make a new, fresh partition?

    Another option is "[ MBR Code ] Write TestDisk MBR code to first sector" - would it be better to do this?


    EDIT I found that at least some of my data is still on the flash drive, by using the below, and searching for English text in less (like " the "):

    cat /dev/sde | tr -cd '\11\12\40\1540-\176' | less
    

    (The drive changed from "/dev/sdb" to "/dev/sde" because I connected some extra drives today). I've learnt that "/dev/sde1" would be the first partition; and "/dev/sde" is the whole drive. Because unix treats these devices just like files, you can use all the ordinary unix file commands on them, like cat, and then process them like any other stream of data. The tr above removes non-printable characters ("\40" is space, which I wanted to preserve). In less, you can use "/" to search, similar to Vim.

    How can I get my data back (assuming it's still there)? If only the partition table is corrupted, is there a standard "partition recovery tool"? Is there a way to "repartition" without deleting everything?


  • Related Answers
  • Col

    It may be worth running testdisk over the device, it sounds like your partition table may have gone pop. Testdisk should be able to recover your data.

  • Area 51

    ddrescue is the tool you need. I don't think you'll be able to salvage the partition table and access the data any other way, based on the output you've posted from testdisk etc.

    http://www.forensicswiki.org/wiki/Ddrescue

    ddrescue is a data recovery tool. It copies data from one file or block device (hard disc, cdrom, etc) to another, trying hard to rescue data in case of read errors.

    The basic operation of ddrescue is fully automatic. That is, you don't have to wait for an error, stop the program, read the log, run it in reverse mode, etc.

    If you use the logfile feature of ddrescue, the data is rescued very efficiently, (only the needed blocks are read). Also you can interrupt the rescue at any time and resume it later at the same point.

    Ddrescue does not write zeros to the output when it finds bad sectors in the input, and does not truncate the output file if not asked to. So, every time you run it on the same output file, it tries to fill in the gaps without wiping out the data already rescued.

    If you have two or more damaged copies of a file, cdrom, etc, and run ddrescue on all of them, one at a time, with the same output file, you will probably obtain a complete and error-free file. This is because the probability of having damaged areas at the same places on different input files is very low. Using the logfile, only the needed blocks are read from the second and successive copies.