Recently I have written a quick “how to” on restoring, formatting a USB flash drive. The “how to” had a lot of hits from different places since then, mostly from GOOGLE, of course, but some from independent bloggers, like my blogging self.
One of such places was www.newlinuxuser.com. Although the guide “saved them” (welcome :)) they had a very constructive critique that one thing the guide missed was how to actually find which device to restore / format.
Hence I decided to write a new little 2 step “how to” that will teach you just that.
Step 1. System Log is your friend, listen to what it has to say…
Imagine you close your eyes, and someone puts an apple in your mouth – would you be able to identify what the heck was put into your mouth? For most people the answer would be “yes”. ( If you’d like to experiment, feel free :). The thing is once you bite on that apple, your brain goes through many lines of code (given that we are written in C), finds that match, and reports:
"The object in your mouth was identified as an Apple - we've had that before. I just talked to the stomach, it knows how to digest it."
You would think that your Linux/Unix system is any different? Well, not really.
Right after you insert a USB device into a slot, Linux/Unix will try to read, and identify it. While doing that, it will also assign it to a particular device as “/dev/particular-device”. This device is exactly the information we need, so we can talk to it, and mount it.
Although most people would approach it with running a dmesg, and look at the output, I prefer a more natural OS way to look at things – we’ll look directly in the eye of a System Log!
Let’s use “tail -f”, so we can see real time system log updates:
tail -f /var/log/messages
Now insert your USB drive into a slot and you should see the output similar to:
Dec 5 14:53:19 your-hostname kernel: [81585.308993] usb 4-1: new full speed USB device using uhci_hcd and address 3 Dec 5 14:53:19 your-hostname kernel: [81585.456757] usb 4-1: not running at top speed; connect to a high speed hub Dec 5 14:53:19 your-hostname kernel: [81585.484884] usb 4-1: configuration #1 chosen from 1 choice Dec 5 14:53:19 your-hostname kernel: [81585.498817] scsi6 : SCSI emulation for USB Mass Storage devices Dec 5 14:53:24 your-hostname kernel: [81590.514870] scsi 6:0:0:0: Direct-Access USB 2.0 USB Flash Drive 0.00 PQ: 0 ANSI: 2 Dec 5 14:53:24 your-hostname kernel: [81590.519874] sd 6:0:0:0: [sdb] 15794175 512-byte hardware sectors (8087 MB) Dec 5 14:53:24 your-hostname kernel: [81590.522834] sd 6:0:0:0: [sdb] Write Protect is off Dec 5 14:53:24 your-hostname kernel: [81590.534817] sd 6:0:0:0: [sdb] 15794175 512-byte hardware sectors (8087 MB) Dec 5 14:53:24 your-hostname kernel: [81590.537814] sd 6:0:0:0: [sdb] Write Protect is off >>>> Dec 5 14:53:25 your-hostname kernel: [81590.537888] sdb: sdb1 <---- GOT YOU! Dec 5 14:53:25 your-hostname kernel: [81590.654848] sd 6:0:0:0: [sdb] Attached SCSI removable disk
Note that the USB drive was “connected”, or associated with sdb device
[81590.654848] sd 6:0:0:0: [sdb] 15794175 512-byte hardware sectors (8087 MB)
and more precisely, with sdb1 device
[81590.537888] sdb: sdb1
And that means we can talk to it! The full name of the guy would be “/dev/sdb1”.
Now let’s greet our friend. Say: “Hi /dev/sdb1”! 🙂
Step 2. Mount USB drive’s device to the File System.
Just an extra step, in case you need to mount it. If you can’t, and would like to format it, so you can mount it afterwards, read this.
To mount the drive enter this:
sudo mount -t vfat /dev/sdb1 /media/usbdrive/
where “/dev/sdb1” is the name of the device, we found in the step above. “/media/usbdrive/” is the directory that we are going to mount it to. Make sure this directory exists (otherwise create it “sudo mkdir /media/usbdrive/”). And “-t vfat” is asking your Linux/Unix OS to mount this device as a “vfat” (FAT16, FAT32) device.
Many, if not most, USB devices are VFAT, however if you have an NTFS USB hard drive, for example, you can mount it by entering:
sudo mount -t ntfs-3g /dev/sdb1 /media/usbdrive/ -o force
“sudo” in above couple commands comes from mostly Ubuntu way to “run command as a super user”. If you have any other flavor of Linux/Unix, you may want to just run it as a “root” user.
Eat more apples, and good luck!