Format, mount and unmount a USB drive in Linux

execute the mount command without any arguments to view all the mounts:

#mount

rootfs on / type rootfs (rw)
/dev on /dev type tmpfs (rw,relatime)
/dev/disk/by-uuid/c4f411af-56b1-4ecc-b85e-a0173aa9dc30 on / type ext4 (rw,noatime,data=ordered)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=490760k,nr_inodes=122690,mode=755)
tmpfs on /run type tmpfs (rw,relatime)
tmpfs on /run/shm type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
tmpfs on /var/state/login type tmpfs (rw,nosuid,noexec,relatime,mode=700,uid=99,gid=99)
tmpfs on /var/tmp type tmpfs (rw,relatime)
/dev/sda4 on /var/log type ext4 (rw,noatime,data=ordered)
/dev/sdc1 on /media type ext4 (rw,relatime,data=ordered)
You can also use df command to view all the mount points:

#df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.9G 3.3G 3.2G 51% /
devtmpfs 480M 0 480M 0% /dev
tmpfs 498M 1.3M 496M 1% /run
tmpfs 498M 0 498M 0% /run/shm
tmpfs 498M 0 498M 0% /var/state/login
tmpfs 498M 368K 497M 1% /var/tmp
/dev/sda4 7.6G 146M 7.1G 2% /var/log
/dev/sdc1 7.1G 17M 6.7G 1% /media

(USB drive should appear as SCSI drive):

#fdisk -l

WARNING: GPT (GUID Partition Table) detected on ‘/dev/sda’! The util fdisk doesn’t support GPT. Use GNU Parted.
Disk /dev/sda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 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
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sda1 1 33554431 16777215+ ee GPT

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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
Disk identifier: 0x00000000

Disk /dev/sdb doesn’t contain a valid partition table

Disk /dev/sdc: 7864 MB, 7864320000 bytes
30 heads, 33 sectors/track, 15515 cylinders, total 15360000 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
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdc1 8192 15359999 7675904 7 HPFS/NTFS/exFAT

Let’s format the partition as traditional EXT4 Linux file system :

#mkfs.ext4 /dev/sdc1
Mount the drive :

#mount -t ext4 /dev/sdc1 /media

Unmount the drive :

#umount -t ext4 /dev/sdc1 /media
You’re now ready to use it! However, this mount will not survive to a reboot. To make it permanent, you need to edit fstab :

#vi /etc/fstab
tmpfs /run tmpfs defaults 0 0
tmpfs /run/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devtmpfs /dev devtmpfs defaults 0 0
devpts /dev/pts devpts defaults 0 0
tmpfs /var/state/login tmpfs mode=700,uid=nobody,gid=nobody,noexec,nosuid 0 0
tmpfs /var/tmp tmpfs defaults 0 0
UUID=c4f411af-56b1-4ecc-b85e-a0173aa9dc30 / ext4 noatime 1 2
UUID=74f22d22-75b6-45f5-b1dd-fb98f328d138 swap swap defaults 0 0
UUID=f6213ff4-16e3-4107-812b-ba653154128f /var/log ext4 noatime 1 2
/dev/sdc1 /media ext4 defaults 0 0

Advertisements

Posted on June 15, 2015, in Linux (Ubuntu/CentOS). Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: