LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 10-15-2015, 11:52 AM   #1
ardabro
Member
 
Registered: May 2015
Location: Katowice, Poland
Distribution: Debian, Ubuntu
Posts: 37

Rep: Reputation: Disabled
how to "refresh" old flash memory USB stick?


Hi all
I have an old USB stick formatted to FAT. Haven't used it for a long time
Now it reports errors when I try do read files from it.
I don't care about these files, but I'd like to make it usable again.
I think simple mkdosfs is not sufficient, and full wrtite/read/scan is necessary. What is a proper tool to use?
It should be something in command line. I have to do it by ssh, because I'm in another location for some time.
 
Old 10-15-2015, 12:33 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Use fdisk and mkfs to format it and create a new file system. You'll need to use sudo, or be root.

fdisk will allow you to remove all partitioning and then create one continuous partition, I'd recommend just native Linux type 83.

mkfs will allow you to create a file system. I'd suggest just ext2.

If this stuff doesn't work, then likely the stick is no longer any good. There's no such thing as repairing, at least from the perspective of a normal user. Meaning if you knew the electronics of the stick and had the right tools you could replace the memory component so as to recondition the hardware, but probably not worth it over the benefit of just purchasing a new stick.
 
Old 10-15-2015, 03:34 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,985

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Some of the OEM web sites may have a program but basically I'd consider it trash.
 
Old 10-15-2015, 07:55 PM   #4
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
For the price you have to pay for USB flash drives, it's not worth your time to try to fix it. Toss it and buy a new one, bigger, faster, newer, and shinier.
 
Old 10-19-2015, 07:13 PM   #5
wroom
Member
 
Registered: Dec 2009
Location: Sweden
Posts: 159

Rep: Reputation: 31
Quote:
Originally Posted by ardabro View Post
Hi all
I have an old USB stick formatted to FAT. Haven't used it for a long time
Now it reports errors when I try do read files from it.
I don't care about these files, but I'd like to make it usable again.
I think simple mkdosfs is not sufficient, and full wrtite/read/scan is necessary. What is a proper tool to use?
It should be something in command line. I have to do it by ssh, because I'm in another location for some time.
I would do like this:

A) If i wanted to use the stick on any computer, inluding 'Widows':

Insert the stick in a computer running linux. Log in as root, or use 'su' or 'sudo su -' or anything that gives you root access.

Use 'df' or 'findmnt' to see if it gets automounted to some directory.
If so, then unmount it.

Lazy method is to open a terminal window and issue command 'tail -f /var/log/messages'.
If you then insert the stick, the log will tell you which device it gets assoxiated with, and if it gets automounted to some directory.

Lets say the stick happens to get associated with device '/dev/sdk' when plugged in.

If it got automounted, just type 'umount /dev/sdk' to unmount it before going any further.

Typing 'blkid' will show you any filesystem labels and UUID's associated with that device.

Typing 'blockdev --report' will list the block devices, and you will see the actual size of the stick, and also any partitions on the stick.

Doing a 'fdisk /dev/sdk' and then typing the command 'p' will show you the partitions on the stick.

if you want to keep boot sector and/or partition table of the stick, you can copy it to a small file like this: 'dd if=/dev/sdk bs=1b count=1 of=mbr.copy.from.stick.bin'

To wipe the stick completely, do one of the following:

1) 'dd if=/dev/zero bs=2k of=/dev/sdk ; sync'
2) 'badblocks -wsb 2048 -t 0x00 /dev/sdk'

Using badblocks, you will get a progress indication, and also a check on that the contents really are zeroed out without errors.

If you use 'badblocks -wsb 2048 /dev/sdk' you will have the stick zeroed out with the "DOD method" of first writing pattern 0xAA, then patterns 0x55, 0xFF and finally 0x00. If this doesn't fail, the stick is proven usable. (Please note that it is best for the FLASH stick lifetime to just write the zeroes).

Now we have a wiped USB FLASH stick. Put it in a Windows PC and let windows format it for you. It will put a fresh partition table on it, (without boot code), and then format it as FAT32. Usable on all computers.


B) Just like alternative A above, except you partition and format the stick under linux.

Re-add the boot sector and partition table that we made a backup to a file:
'dd if=mbr.copy.from.stick.bin bs=1b count=1 of=/dev/sdk ; sync ; partprobe /dev/sdk'

Or use fdisk to make a partition table on the stick. Please note that most common is (strange enough) to only have a primary partition number 4, with FAT32 on it. But you can of course partition it however you like. It is also possible to use the stick without partitioning it. Just to put the filesystem on the whole /dev/sdk. There are some compatibility issues with this, but it can be used if one wants to use as much of the stick as possible for data.

If used only for Linux, i would put reiserfs on the stick. Or possibly ext3/ext4 if reiserfs happens not to be installed on a particular computer i will use the stick with. (unlikely for me).
You can of course add a FAT32 filesystem using Linux. You can also make several partitions, and have one small FAT16 partition usable on an ancient DOS machine, and one FAT32 partition. Or a combo with half the stick as FAT32 and the second half as EXT3, reiserfs, UFS, XFS or hatever you prefer.


Backup of a USB stick:
One can also use 'dd if=/dev/sdk bs=2k | gzip -9 > image.backup.of.stick.bin.gz' to make an image copy of a sticks contents to a file. Which later can be put back to a stick of same size or bigger using 'gzip < image.backup.of.stick.bin.gz | dd bs=2k of=/dev/sdk ; sync'.
This is very useful if you want to temporarily use a stick for something else, and then restore the previous contents again.

(Please note again that '/dev/sdk' is an example, and that the stick might as well be associated with any other device name, like '/dev/sdd').
 
Old 10-20-2015, 07:45 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
This is an old USB thumb stick. Not saying that those actions wouldn't work, but I have to wonder why bother? They don't usually contain SMART technology, and instead it is likely a cheap NAND type of flash device where the R/W cycles will eventually charge the storage locations and lock them out.
 
Old 10-20-2015, 08:48 AM   #7
wroom
Member
 
Registered: Dec 2009
Location: Sweden
Posts: 159

Rep: Reputation: 31
Quote:
Originally Posted by rtmistler View Post
This is an old USB thumb stick. Not saying that those actions wouldn't work, but I have to wonder why bother?
I have seen occational USB sticks and media cards fail, but the failure being in the filesystem, and not in the hardware. So writing fresh partition/filesystem to the stick might "repair" it.

Also, FLASH memory are partitioned in banks, and when a whole bank is "zeroed" a good FLASH device will bank erase and at the same time "relevel" the charge tunnels. So if a FLASH memory has been misused such like rewriting small portions of the device very frequent, then this releveling erase may give the memory a long and healthy life. But not all FLASH do this, and there is not much ways to find out if a particular USB stick does this.

Assuming the USB stick is designed so that erased bits are '0' and written bits are '1', then the method of first writing pattern 0xFF to the whole device and then writing pattern 0x00 to the whole device will do some leveling of the FLASH.

But the basic advice still stands. Why bother, when we don't really know how much life there is left in the little bugger, and it is cheap as popcorn to buy a new one.

I have a very old 1 GiB USB stick. Aluminum box with a little printed circuit board inside. Slow as a punch card reader. But reliable. And very cute. Hate to see it die.

Quote:
Originally Posted by rtmistler View Post
...it is likely a cheap NAND type of flash device where the R/W cycles will eventually charge the storage locations and lock them out.
Could be worse. It could be a cheap NOR type FLASH.


Worst deal must be one of those cheap noname bogus USB sticks that come around on cheap sales. You can write to it, and then read it back. But if you unplug it, you erase it. Because it is a cheap little bogus one that actually does not contain any flash memory.
 
  


Reply

Tags
flash drive, formatting



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
How to Install a Linux distro onto a memory stick "Kingston" Brandon Linux - Newbie 9 11-09-2010 09:12 AM
LXer: Installing "Sugar on a stick" (Strawberry Release) On A USB Stick LXer Syndicated Linux News 0 08-04-2009 03:50 PM
max number of "write" actions on flash memory stick babypeng Linux - Newbie 8 07-21-2009 11:13 PM
Memory Stick Card Reader, Debian "Lenny" FAILURE! mkisow Linux - Hardware 6 04-27-2009 09:15 AM
"Turning off" USB memory stick before unplugging/disconnecting detly Linux - Hardware 3 03-15-2005 12:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 11:00 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
Open Source Consulting | Domain Registration