Friday, 5 August 2016

Discovering and Mounting USB Drives/Flash Drives using the command line on Ubuntu Server

Discovering which drives are connected

There are many ways to see which drives are connected to the ubuntu system:

To show full detailed information about all drives connected to the system.

sudo fdisk -l

This will list, in detail, all of the drives connected.

Here is an example of the drive we are interested in. A 500mb external HDD:

Disk /dev/sdi: 465.8 GiB, 500107706368 bytes, 976772864 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: 0xe38f367e

Other options:

blkid
lsblk -f
lsusb
sudo lshw
df -h -T

To see if the drive is FAT16 or FAT32

sudo file -s /dev/sdi1


This will show is the following details for the drive


/dev/sdi1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "BSD  4.4", sectors/cluster 64, Media descriptor 0xf8, sectors/track 32, heads 255, hidden sectors 2, sectors 976772862 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 119206, serial number 0xfd44150c, label: "500-FREECOM"

Mount the drive

USB drives are usually mounted under the /media directory. Create a directory to mount the drive on.

cd /media
mkdir external

sudo mount -t vfat /dev/sdb1 /media/external
If no -t option is given, or if the auto type is specified, mount will try to guess the desired type.