How to format and mount a USB hard drive in Linux

I bought a new USB hard drive the other day. I wanted to use it to create backups of my Linux server. Here’s how I went about formatting and mounting the drive on my Linux server.

The first thing I did was to find out where the disk had been mounted. For that I ran the following command:

# tail -F /var/log/messages

When I plugged in the drive into my server there was a message saying the the drive was available at /dev/sdc1. So the next step was to format the drive. There are a number of file formats that can by read and written to by Linux, but Windows is a bit more fussy about it. So I decided to use a tried and tested file system that works well with both operating systems. I went with FAT. So to format the drive as FAT I ran the following command:

# mkfs.vfat /dev/sdc1

In a few minutes the newly formatted drive was ready to go. Now I wanted to mount it. So I created a directory to mount it:

# mkdir /media/usbdisk

Now, to mount the drive to this mount point I ran the following command:

# mount -t vfat /dev/sdc1 /media/usbdisk

And that’s it. My new hard drive was formatted, mounted, and ready to go. I copied the data I wanted to copy on it and then I unmounted it:

# umount /media/usbdisk

NOTE: this last step is very important. If you unplug your drive without unmounting it you could risk the data it holds.

If this is a USB storage device that you might use often and plan to leave it hooked up to your Linux server you can set up the device to be automatically mounted when you boot into Linux. To do that make an entry like the one shown below at the end of file /etc/fstab:

/dev/sdc1 /mnt/usbdrive vfat defaults 0 0

Now your drive will be automatically mounted to your Linux server, and you can take your backups without worrying about mounting a device.

6 thoughts on “How to format and mount a USB hard drive in Linux”

  1. Pingback: How to format and mount a USB hard drive in Linux « PHP TALENT GURU

  2. Why did you go with FAT fs? I made the mistake of not formatting the first USB drive I bought, leaving it’s native windows fs intact, and now I can’t use some utilities like rsync on that drive. Did you run into that problem with FAT? Thanks!

  3. This was the most useful help that I have seen in a long time. It is one of those things that I have to do about once a year, which gives me plenty of time to forget how between events. Thank you.

  4. please hiw do i format my pc hard drive?Each time i try do do so the computer tells me it cant.Also, i tried to uninstall an ms program the other day
    but the system went off before it could complete uninstalling.since then i cant open any ms package,remove program or add any.what must i do to get my system to normal.

Leave a Comment

Your email address will not be published. Required fields are marked *