Linux HDD
Adding an external hard drive (HDD)
Note: This example will assume the HDD is SATA and uses USB to connect with the computer.
A lot of external HDDs are sold pre-formatted and usually as NTFS (for Windows). If you are like me, you will want this HDD formatted for Linux.
- Step 1: Getting Linux to discover the newly connected external HDD
After connecting the HDD to the computer via USB, Linux may not always automatically recognise it. The easiest way to manually configure this new HDD is to turn it on and then:
tail /var/log/messages
One of the lines should have something like the following:
Feb 19 01:04:49 linux: Attached scsi disk sda at scsi6, channel 0, id 0, lun 0
The "sda
" is the part we are interested in. This means your new HDD is going to use /dev/sda
as the mount point.
- Step 2: Create the new partition(s)
The easiest way to create a partition is to use fdisk (note: Important! You must exercise caution here and only partition un-mounted drives). As root, enter the following
% fdisk /dev/sda p # display a list of current partitions n # create a new partition (create a "primary partition") # external HDD, so one big partition should suffice w # write the partition table
Then quit fdisk.
- Step 3: Format as a Linux filesystem
I recommend using the ext3
filesystem. To format (or "make") this, enter the following (as root):
mkfs.ext3 -v /dev/sda1 # the 'v' is for "verbose" and shows you its progress.
This step will take a while, depending on how large your external HDD is and other factors.
- Step 4: Create a mount point
It is customary to use the /mnt
subdirectory for external mount points. Create a sub-directory here and call it whatever you like (I will call mine "xhdd"):
mkdir /mnt/xhdd
You may want to issue the the following command to grant other users access to the mount point:
chmod go+x /mnt/xhdd
Now manually mount the drive and test it with:
mount -t ext3 /dev/sda1 /mnt/xhdd
- Step 5: Add new external HDD to
fstab
In order for your external HDD to be automatically mounted every time you turn on your machine, you must add the appropriate line to your /etc/fstab
file. Something like the following should work for most uses:
/dev/sda1 /mnt/xhdd ext3 defaults 0 0
To test that the above works, first un-mount the HDD (as root):
umount /dev/sda1
Then mount it using the information in your /etc/fstab
file:
mount -a
This mounts all filesystems (of the given types) mentioned in fstab (unless they are already mounted).
That's it!