MRKAVANA (mrkavana@gmail.com) - www.facebook.com/kavanathai

Sep 8, 2011

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 myLinux server. Here’s how I went about formatting and mounting the drive on my Linuxserver.
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.

No comments:

Post a Comment