Skip to content


How to format and mount a USB hard drive in Linux

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.

Posted in Linux.

Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

 

You can always opt out of this email subscription at any time.

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. daniel c.n says

    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.



Some HTML is OK

or, reply to this post via trackback.