TestDisk: Flash Drive="CHS and LBA don't match" [SOLVED]

Using applications, configuring, problems
Message
Author
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#101 Post by Sylvander »

linuxcbon:
Tried this:
1.

Code: Select all

# dd if=/dev/zero of=/dev/sdb
dd: writing to `/dev/sdb': No space left on device
1974272+0 records in
1974271+0 records out
1010826752 bytes (1.0 GB) copied, 180.075 s, 5.6 MB/s
# 
LED on Flash Drive sdb was blinking rhythmically and constantly during this operation until it completed.
sdb1 had not/not-ever/never been mounted [it was unmounted throughout].

2. GParted still shows sdb1 as "unknown" file system.
Attempt to delete partition fails.
Attempt to format fails.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#102 Post by Karl Godt »

I think it is only useable for dd operations . My Agfa 16gb Pendrive refuses to format the GB over ~4,5 . Have dd'ed it to a .img file that successfully mounted vfat automatically mount -o loop /path/to/rescue16gb.dd.img /mnt/loop and all .sfs and .iso inside had been mountable. The first 4,5GB had been two partitions that also did mount and got rescued. Now everytime a program tries to run a sync function , the usb-storage or sg scsi driver throws out something like that in dmesg and one core gets into 100% wait load :

[34154.930308] sd 33:0:0:0: [sdc] Sense Key : 0x0 [current]
[34154.930313] sd 33:0:0:0: [sdc] ASC=0x0 ASCQ=0x0
[34154.937808] sd 33:0:0:0: [sdc] Sense Key : 0x0 [current]
[34154.937814] sd 33:0:0:0: [sdc] ASC=0x0 ASCQ=0x0


ps -elF | grep sync :
0 D root 16612 20253 0 82 2 - 0 sync_p 0 1 22:57 pts/3 0:00 [mkfs.msdos]

So it must have damaged the firmware on that drive or the flash.

linuxcbon
Posts: 1312
Joined: Thu 09 Aug 2007, 22:54

#103 Post by linuxcbon »

- After doing dd zero, did dmesg show anything at the end ?

- Type "gparted" from shell
Delete partitions.
Create a new partition.
Format the new partition.
What are the shell error messages ?

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#104 Post by amigo »

That dd command appears to have succeeded -which means that there is no more partition table nor filesystem on it.

So, start again with fdisk and create your type 83 partition, then run 'mkfs.ext2 /dev/sdb1' to create the filesystem. Then, since there seem to be lots of bad blocks on there, run 'e2fsck -y /dev/sdb1'
If that doesn't succeed then you might as well throw the thing away. With so many bad blocks it must be already failing.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#105 Post by Sylvander »

linuxcbon:
1.
a. Ran gparted using a console command...
Result: It only saw the partitions on the internal HDD; didn't display the opportunity to choose drive sdb. :?
Oops, sorry, I now see I can choose at top right to display sdb1.
When I do that, it displays the partition with "unknown" filesystem.

b. When attempting to re-format to FAT32 [after completing 2 below], got this:

Code: Select all

# gparted
======================
libparted : 2.3
======================
Unable to open /dev/sdb read-write (No medium found).  /dev/sdb has been opened read-only.
Error fsyncing/closing /dev/sdb: Input/output error
Input/output error during write on /dev/sdb
Unable to open /dev/sdb read-write (No medium found).  /dev/sdb has been opened read-only.
Error fsyncing/closing /dev/sdb: Input/output error
# 
amigo:
Tried this:
2.

Code: Select all

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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 2): 1
Partition 1 is already defined.  Delete it before re-adding it.

Command (m for help): d
Selected partition 1

Command (m for help): 1
1: unknown command
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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-1974270, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1974270, default 1974270): 
Using default value 1974270

Command (m for help): 
How do I create a type 83 partition?
Didn't see any opportunity to choose the type.

linuxcbon
Posts: 1312
Joined: Thu 09 Aug 2007, 22:54

#106 Post by linuxcbon »

fdisk /dev/sdb
Delete partition d 1
Create a new primary partition n p 1
Write to table and quit w q
Then make a FAT32 filesystem mkfs.vfat -F 32 /dev/sdb1
But I guess it is better to use ntfs.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#107 Post by Sylvander »

linuxcbon:
Here's what I did:
1.

Code: Select all

# fdisk /dev/sdb

Command (m for help): d1
Selected partition 1

Command (m for help): np1
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-1974270, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1974270, default 1974270): 
Using default value 1974270

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

Calling ioctl() to re-read partition table.
Syncing disks.
# mkfs.vfat -F 32 /dev/sdb1
mkfs.vfat 3.0.11 (24 Dec 2010)
# 
Does that look OK?
Should I have included spaces between n p 1 etc?
GParted shows no change to sdb1; partition still has "unknown" filesystem.

linuxcbon
Posts: 1312
Joined: Thu 09 Aug 2007, 22:54

#108 Post by linuxcbon »

It seems all correct.
Always run gparted from shell and tell which error messages.
And you didnt tell what are dmesg final messages.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#109 Post by Sylvander »

linuxcbon wrote:you didnt tell what are dmesg final messages.
I don't understand what dmesg is, and what/where is its final messages [more than 1?]

linuxcbon
Posts: 1312
Joined: Thu 09 Aug 2007, 22:54

#110 Post by linuxcbon »

Dmesg is messages from kernel.
Type in shell dmesg and copy here the last 10 lines.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#111 Post by amigo »

linuxcbon, you seem to be leading him down the saem (wrong) path as before. fdisk will, by default, create a type 83 partition -he shouldn't then format it as a FAT if the partition type is not right! And, I thought the whole point here was to create an ext2 FS -or have I missed some important posting?

Sylvander, the fdisk commands seems to have succeeded. All you need to do then is use mke2fs or mkfs.ext2 to format the partition (as ext2). You'll then want to run 'fsck -cp /dev/sdb1' to handle the bad blocks.

Don't use gparted as it seems to not work -as it is prone to do...

If you now want the partition as a FAT, please say so. As for ntfs, there is no way to format a partition as NTFS under linux. If that is what you want, then say so -as you will need to *change* the partition type before using windows to format the partition. windows will not recognize partitions of any non-windows type.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#112 Post by rcrsn51 »

amigo wrote:As for ntfs, there is no way to format a partition as NTFS under linux.
mkntfs

linuxcbon
Posts: 1312
Joined: Thu 09 Aug 2007, 22:54

#113 Post by linuxcbon »

amigo you dont need to set the type to format a partition. Gparted works, it's a good program. He wants fat32, not ext2. Yes it is possible possible to format ntfs in linux. What did you say ?

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#114 Post by Sylvander »

At the moment I'll take any filesystem I can get...
Though I'd prefer FAT32.

amigo:
1. Tried this:
[Didn't know what to do with mke2fs, so used mkfs.ext2 instead]

Code: Select all

# fdisk /dev/sdb

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): d
Selected partition 1

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-1974270, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1974270, default 1974270): 
Using default value 1974270

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

Calling ioctl() to re-read partition table.
Syncing disks.
# mke2fs
Usage: mke2fs [-c|-l filename] [-b block-size] [-f fragment-size]
	[-i bytes-per-inode] [-I inode-size] [-J journal-options]
	[-G meta group size] [-N number-of-inodes]
	[-m reserved-blocks-percentage] [-o creator-os]
	[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
	[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
	[-T fs-type] [-U UUID] [-jnqvFKSV] device [blocks-count]
# mkfs.ext2 /dev/sdb1
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61568 inodes, 246272 blocks
12313 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=255852544
8 block groups
32768 blocks per group, 32768 fragments per group
7696 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# fsck -cp /dev/sdb1
fsck from util-linux 2.19
fsck.ext2: Bad magic number in super-block while trying to open /dev/sdb1
/dev/sdb1: 
The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

# 
linuxcbon:
2. Last 10 lines of dmesg:

Code: Select all

[ 1183.901557] sd 4:0:0:0: [sdb]  Sense Key : Not Ready [current] 
[ 1183.901561] sd 4:0:0:0: [sdb]  Add. Sense: Medium not present
[ 1183.901565] sd 4:0:0:0: [sdb] CDB: Write(10): 2a 00 00 00 08 00 00 00 08 00
[ 1183.901572] end_request: I/O error, dev sdb, sector 2048
[ 1238.334837] sd 4:0:0:0: [sdb] 1974271 512-byte logical blocks: (1.01 GB/963 MiB)
[ 1238.335828] sd 4:0:0:0: [sdb] Asking for cache data failed
[ 1238.335830] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[ 1238.337451] sd 4:0:0:0: [sdb] Asking for cache data failed
[ 1238.337454] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[ 1238.339085]  sdb: sdb1
# 

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#115 Post by amigo »

Really strange that everything seems to succeed until you run fsck... If you can't mount that now, then it is truly trashed. Just for future reference, you said you'd like a FAT filesystem, but then you used mkfs.ext2 to format it. For a FAT, NTFS or other windows filesystem, while running fdisk, use the '-t' option to change the partition type (called 'system id' in the options). You need to do this before trying to format the drive. As I mentioned, if you wanted an NTFS file system, then you'd need to change the partition type (system id) to one of the valid windows types and then use windows to create the filesystem. But, as of now, I'm convinced your drive is trashed.

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#116 Post by npierce »

Neither fdisk nor dd automatically verify their writes.

You can get dd to write to a rock if it believes that it you have write permission to do so. That doesn't mean that anything actually got written to the rock.

Sylvander has a type b FAT32 partition on his flash drive. He has made many good attempts to change the partition table, and has provided the results of his sessions in fdisk so we can see what he has done.

Yes, he can change the partition type or even delete it in the partition table that fdisk holds in memory. And the p command will show that change. And he uses the w command to write the partition table to the drive, and that completes with no error message.

But the table does not get written.

Currently the drive appears to be unwritable, perhaps permanently so. There is a chance that a low level format will restore it, but unfortunately the utility I found doesn't work for him.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#117 Post by amigo »

It is also possible that rebooting after writing the partition table may help -sometimes changing the partition type doesn't take effect until after a reboot.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#118 Post by Sylvander »

npierce:
1. "You can get dd to write to a rock if it believes that it you have write permission to do so. That doesn't mean that anything actually got written to the rock"
I think you're correct in saying that. :D

2. "he uses the w command to write the partition table to the drive, and that completes with no error message"
But, but, but....
When I enter the write command [w], the command console CLOSES! :(
So I think it likely the changes were NOT written to the drive [because it's READ-ONLY!]

3. "...the table does not get written.
Currently the drive appears to be unwritable...
"
Seems so to me. :(

4. "There is a chance that a low level format will restore it, but unfortunately the utility I found doesn't work for him"
Sad, but true.

amigo:
5. "It is also possible that rebooting after writing the partition table may help -sometimes changing the partition type doesn't take effect until after a reboot"
I had tried that previously, and it failed...
Probably because the drive cannot be written to [for some reason as yet unproved?]
I've seen at least 1 program report that the drive is read-only.

-------------------------------------------

6. I certainly find this problem very interesting.
I'd love to understand what is really amiss with the drive.
i.e. Why is it unwritable=read-only?

sheldonisaac
Posts: 902
Joined: Mon 22 Jun 2009, 01:36
Location: Philadelphia, PA

the unwriteable flash drive

#119 Post by sheldonisaac »

Sylvander wrote: I'd love to understand what is really amiss with the drive.
i.e. Why is it unwritable=read-only?
I guess this won't help, Sylvander; you probably did all tnis,
and seem to find there's something wrong with your thumb drive?

I have a 512MB SD card Kingston. Sliding lock set to locked. in a USB card reader. Lucid Puppy Linux 5.2.8-005

Code: Select all

~> cp sylpheed.desktop~ /mnt/sdb1/
cp: cannot create regular file `/mnt/sdb1/sylpheed.desktop~': Read-only file system
Set slider to unlocked.

Code: Select all

~> cp sylpheed.desktop~ /mnt/sdb1/
~>

~> ls -lat  /mnt/sdb1/
total 32
drwxr-xr-x  2 root root 16384 2013-03-17 13:43 .
-rwxr-xr-x  1 root root   456 2013-03-17 13:43 sylpheed.desktop~
drwxr-xr-x 15 root root   140 2013-03-17 13:40 ..
~> 

~> umount /mnt/sdb1
~>

~> fdisk /dev/sdb

The number of cylinders for this disk is set to 3908.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdb: 512 MB, 512229376 bytes
8 heads, 32 sectors/track, 3908 cylinders
Units = cylinders of 256 * 512 = 131072 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        3908      500203+   6  FAT16

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdb: 512 MB, 512229376 bytes
8 heads, 32 sectors/track, 3908 cylinders
Units = cylinders of 256 * 512 = 131072 bytes

   Device Boot      Start         End      Blocks   Id  System

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

Calling ioctl() to re-read partition table.
Syncing disks.
~> fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 512 MB, 512229376 bytes
16 heads, 62 sectors/track, 1008 cylinders
Units = cylinders of 992 * 512 = 507904 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): q

~> 

~> dd if=/dev/zero of=/dev/sdb bs=512

dd: writing `/dev/sdb': No space left on device
1000449+0 records in
1000448+0 records out
512229376 bytes (512 MB) copied, 314.13 s, 1.6 MB/s
~> 
~> fdisk /dev/sdb
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/sdb: 512 MB, 512229376 bytes
16 heads, 62 sectors/track, 1008 cylinders
Units = cylinders of 992 * 512 = 507904 bytes

   Device Boot      Start         End      Blocks   Id  System

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): 0C
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): p

Disk /dev/sdb: 512 MB, 512229376 bytes
16 heads, 62 sectors/track, 1008 cylinders
Units = cylinders of 992 * 512 = 507904 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1008      499937    c  W95 FAT32 (LBA)

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.
~> mkfs.vfat /dev/sdb1
mkfs.vfat 3.0.7 (24 Dec 2009)
~> 
(now I rebooted)

Code: Select all

 ~> fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 512 MB, 512229376 bytes
16 heads, 62 sectors/track, 1008 cylinders
Units = cylinders of 992 * 512 = 507904 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1008      499937    c  W95 FAT32 (LBA)

Command (m for help): q

~> mkdir /mnt/sdb1
~> mount -t vfat /dev/sdb1  /mnt/sdb1
~>  cp sylpheed.desktop~ /mnt/sdb1/
~> ls -lta  /mnt/sdb1/
total 24
drwxr-xr-x  2 root root 16384 2013-03-17 14:13 .
-rwxr-xr-x  1 root root   456 2013-03-17 14:13 sylpheed.desktop~
drwxr-xr-x 15 root root   140 2013-03-17 14:12 ..
~>

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#120 Post by npierce »

Sylvander,

I'm looking to see if I can locate a low level format utility that will work with your drive. Could you plug in your drive and then post the output of this command?

Code: Select all

lsusb

Post Reply