LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices



Reply
 
Search this Thread
Old 05-01-2009, 09:10 PM   #1
entropic
LQ Newbie
 
Registered: May 2009
Posts: 6

Rep: Reputation: 0
Corrupted/Smaller 16 GB Sandisk MicroSDHC


EDIT: The solution can be found in post #11.

I use a 16 GB MicroSDHC and a USB 2.0 card reader as a flash drive. It recently got corrupted by a windows machine that had a few viruses.

I immediately used dd to backup the disk image, then I copied off all of my files. Thankfully, they are all safe. I zeroed the disk using:
Code:
dd if=/dev/zero of=/dev/sdc
After that, I used gparted to create a primary fat32 partition that used up the "entire" card.

This is where things get interesting. Gparted reports that the size of the card is 14.83 GB, not the 15.9 GB that I expected. The card functions properly in linux, as far as I can tell. It's just smaller.

Strangely, the output from fdisk gives the correct size of the device as 15.9 GB:
Code:
root@bt:~# fdisk -lu /dev/sdc

Disk /dev/sdc: 15.9 GB, 15931539456 bytes
255 heads, 63 sectors/track, 1936 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0xc04a730c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1              63    31101839    15550888+   b  W95 FAT32
...and here is the output from sfdisk:
Code:
root@bt:~# sfdisk -d /dev/sdc
# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=       63, size= 31101777, Id= b
/dev/sdc2 : start=        0, size=        0, Id= 0
/dev/sdc3 : start=        0, size=        0, Id= 0
/dev/sdc4 : start=        0, size=        0, Id= 0
Something seems wrong. The first partition is not using the entire card! In fact...
Code:
root@bt:~# fdisk /dev/sdc

The number of cylinders for this disk is set to 1936.
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): v
14510 unallocated sectors

Command (m for help): q
The unallocated sectors could account for the storage space I'm missing, right?

So, this is where I am stuck at. I can't figure out how to get it to use the remaining unallocated sectors. I already have my files, now I want my card back.

If there is any more information I can provide, just ask. Thanks!

Last edited by entropic; 05-03-2009 at 09:53 AM. Reason: Solution
 
Old 05-02-2009, 06:01 AM   #2
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Try doing:

Code:
mkdosfs -I -F 32 /dev/sdc
 
Old 05-02-2009, 09:39 AM   #3
entropic
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
After using that command, I used fdisk to create a new primary partition:
Code:
root@bt:~# fdisk /dev/sdc

The number of cylinders for this disk is set to 15193.
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): u
Changing display/entry units to sectors

Command (m for help): v
31116287 unallocated sectors

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

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): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
It let me use more sectors this time! Now I only have 31 unallocated sectors, which is perfectly normal. After that, I rebooted because it told me to.

However... Gparted now reports that the size of the device is 14.84 GB. At least it's a step in the right direction.

I am going to continue repeating this process in order to see if I can recover more space. If anyone has any more ideas, don't hesitate to share!

EDIT: No additional space can be recovered using this method.

Last edited by entropic; 05-02-2009 at 09:54 AM. Reason: more info
 
Old 05-02-2009, 10:11 AM   #4
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Well, the command I gave partitions the entire disk as a FAT32 partition. So, there's no need to run fdisk on it, IMO.
 
Old 05-02-2009, 01:27 PM   #5
entropic
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
I don't understand. After I use that command, fdisk shows a 15.9 GB device with no partitions:
Code:
root@bt:~# mkdosfs -I -F 32 /dev/sdc
mkdosfs 2.11 (12 Mar 2005)
root@bt:~# fdisk -l /dev/sdc

Disk /dev/sdc: 15.9 GB, 15931539456 bytes
64 heads, 32 sectors/track, 15193 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
While Gparted still shows 14.3 GB of unallocated space.

If there is no need to run fdisk, then what should I do? It seems that the problem remains unchanged.
 
Old 05-02-2009, 02:10 PM   #6
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
You can just mount it and use it:

Code:
mount /dev/sdc /mnt/tmp
fdisk won't show info on the disk because the disk is actually a partition itself. That's no problem, you should be able to mount and use the disk just fine. This is how it has always worked with flash disks, AFAIK. This is the only way most cameras will accept anyway.
 
Old 05-02-2009, 03:12 PM   #7
entropic
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Okay, when I mount the card it still shows up as having a size of 14.8 GB (in Windows too). I can't change the volume label or flip the removable media bit. If I try to format using windows logical disk manager it fails at 100%.

If it helps, the card had one 16 GB partition before it got corrupted. This means it would mount to /mnt/sdc1 because the device was /dev/sdc1.

Thanks for your patience.
 
Old 05-02-2009, 04:44 PM   #8
Electro
Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
It seems you are experiencing cell damage. It is not caused by viruses. The cell damage is caused by too many writes. Actually Flash memory is a poor storage medium investment because it has very limited writes, the oldest data can not be more than 10 years old, and it is easily damaged by power fluctuations. Use hard drives for data storage because the medium it self can hold the data close to a century and the amount of writes is close to infinite.
 
Old 05-02-2009, 05:00 PM   #9
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
It's possible, if that's the case I would try using the '-c' option to check for bad blocks:

Code:
mkdosfs -c -I -F 32 /dev/sdc
Note that it will take a while, but it'll tell you if there are bad blocks.

Last edited by H_TeXMeX_H; 05-02-2009 at 05:02 PM.
 
Old 05-02-2009, 06:21 PM   #10
entropic
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
@Electro: Thanks for the info on cell damage.

I have had my card for 5-6 months with moderate use. Could damage set in that quickly?

Mkdosfs didn't tell me anything, so I assume there are no bad blocks.

I found a program (for windows) called SDFormatter on sdcard.org which might be helpful to others with a similar problem. This gives me a primary partition (/dev/sdc1) of 14.83 GB with 4 MB of unallocated space at the beginning of the device. Apparently this is the standard for sd/microsd cards. It's nice to know that I can always use this if I mess up. It would be even better if it gave me back that extra 1.2 GB!

Last edited by entropic; 05-02-2009 at 06:36 PM.
 
Old 05-03-2009, 09:50 AM   #11
entropic
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Solution

Thanks for you help everyone, I definitely learned many things along the way.

I fixed the corruption using the SD Formatter found on Panasonic's site (windows only ). This formats the card to sd/sdhc standards.

As for the "smaller" size of my card... That was a mistake on my part . When the manufacturer says "16 GB" they actually mean ~14.83 GB. It has to do with measuring megabytes as 10^x instead of 2^x.

All of my files fit perfectly onto my card. I guess I never noticed the total size of my card was 14.83 GB the entire time.

Thanks again for the great support!
 
  


Reply

Tags
corrupt, sectors


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
4gb microsdhc on sandisk sansa e260 Polanski Linux - Laptop and Netbook 1 06-02-2008 07:12 PM
Sandisk Imagemate carlosinfl Linux - Hardware 1 02-09-2006 06:05 PM
Sandisk Cruzer TanSahara Linux - Hardware 1 01-02-2006 07:53 PM
Free disk space in '/' getting smaller and smaller. simjii Suse/Novell 5 12-16-2005 12:24 PM
SanDisk JJPMR52 Linux - Newbie 1 06-21-2003 01:12 AM


All times are GMT -5. The time now is 04:16 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration