First, find out what device the kernel uses to act on the USB drive. You should first check what storage devices are there right now:
[alessandro@localhost ~]$ ls /dev/sd?
/dev/sda
[alessandro@localhost ~]$
Then you plug in the USB stick and check again:
[alessandro@localhost ~]$ ls /dev/sd?
/dev/sda /dev/sdb
[alessandro@localhost ~]$
sdb just showed up, that's your USB storage device.
Or, you could check the system logs while you're inserting the USB stick:
[alessandro@localhost ~]$ $ tail -fn0 /var/log/syslog
Sep 6 11:54:31 localhost kernel: usb 2-1.3: new high-speed USB device number 6 using ehci-pci
Sep 6 11:54:31 localhost kernel: usb-storage 2-1.3:1.0: USB Mass Storage device detected
Sep 6 11:54:31 localhost kernel: scsi host8: usb-storage 2-1.3:1.0
Sep 6 11:54:31 localhost mtp-probe: checking bus 2, device 6: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3"
Sep 6 11:54:31 localhost mtp-probe: bus: 2, device: 6 was not an MTP device
Sep 6 11:54:32 localhost kernel: scsi 8:0:0:0: Direct-Access General USB Flash Disk 1.0 PQ: 0 ANSI: 2
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: [sdb] 7831552 512-byte logical blocks: (4.00 GB/3.73 GiB)
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: [sdb] Write Protect is off
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: [sdb] Mode Sense: 03 00 00 00
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: Attached scsi generic sg2 type 0
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: [sdb] No Caching mode page found
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: [sdb] Assuming drive cache: write through
Sep 6 11:54:32 localhost kernel: sdb:
Sep 6 11:54:32 localhost kernel: sd 8:0:0:0: [sdb] Attached SCSI removable disk
[alessandro@localhost ~]$
You might have to prepend the tail command by sudo, should you get a permission error reading the syslog file.
Either way, after you figured out what device you have to use to access the USB drive, you should check no partition of the drive is mounted:
[alessandro@localhost ~]$ mount | grep /dev/sdb
[alessandro@localhost ~]$
No output, no partition is mounted. Should the command return a list of mounted partitions, umount each one of them. Then, check that the drive's partition table looks all right to the system.
Old command, old partition format (MBR Partition Table), classic and stable:
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 3,8 GiB, 4009754624 bytes, 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
Disklabel type: dos
Disk identifier: 0x00000000
[root@localhost ~]#
New command, new partition format (GPT), more features:
[root@localhost ~]# gdisk -l /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Caution: invalid main GPT header, but valid backup; regenerating main header
from backup!
Caution! After loading partitions, the CRC doesn't check out!
Warning! Main partition table CRC mismatch! Loaded backup partition table
instead of main partition table!
Warning! One or more CRCs don't match. You should repair the disk!
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: damaged
Found valid MBR and corrupt GPT. Which do you want to use? (Using the
GPT MAY permit recovery of GPT data.)
1 - MBR
2 - GPT
3 - Create blank GPT
Your answer:
In this case I have a troubled USB stick with a messed-up partition table. I tell gdisk to use the GPT data it found to try and recover the storage device:
Your answer: 2
Disk /dev/sdb: 7831552 sectors, 3.7 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 86EA5119-B15E-4964-A485-DC0C687C187C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 7831518
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB 8300 Linux filesystem
2 1050624 3147775 1024.0 MiB 8300 Linux filesystem
3 3147776 4536319 678.0 MiB 8300 Linux filesystem
4 4536320 4798463 128.0 MiB 8300 Linux filesystem
5 4798464 7831518 1.4 GiB 8300 Linux filesystem
[root@localhost ~]#
You could end up with an empty partition table, if so you should make a new one. After saving the new partitioning, you should have /dev/sdb1, sdb2... devices you can make a new filesystem on, then mount and use.
Hope it was easy enough to follow.