Difference between revisions of "Linux HDD"

From Christoph's Personal Wiki
Jump to: navigation, search
(External links)
(Adding an external USB hard drive (HDD))
Line 12: Line 12:
  
 
The "<code>sda</code>" is the part we are interested in. This means your new HDD is going to use <code>/dev/sda</code> as the mount point.
 
The "<code>sda</code>" is the part we are interested in. This means your new HDD is going to use <code>/dev/sda</code> as the mount point.
 +
 +
Another and simpler method (that doesn't always work) is to execute the following command:
 +
grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short)
  
 
*Step 2: Create the new partition(s)
 
*Step 2: Create the new partition(s)

Revision as of 06:10, 27 January 2012

Adding an external USB 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.

Another and simpler method (that doesn't always work) is to execute the following command:

grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short)
  • Step 2: Create the new partition(s)

Note: If your drive arrives pre-formatted (e.g., as HPFS/NTFS), you will first need to delete the existing partition(s).

Only do the following if there is a pre-existing partition you wish to delete (note: fdisk may need to be run from /sbin/fdisk):

% fdisk /dev/sda
d   # delete a partition

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. Note the "/dev/sda1" (not "/dev/sda"). To format (or "make") this, enter the following (as root; note: mkfs.ext3 may need to be run from /sbin/mkfs.ext3):

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!

Adding an external eSATA hard drive (HDD)

Note: In this example, I will be mounting a 400 GB external HDD (xHDD) using an eSATA port on my 64bit PCI-X bus host adapter card which use the Silicon Image SATA II - 3Gbs SiI3214 chipset. Also note that this card has four eSATA ports.

First, check that your PCI-X card has been recognized:

lspci |grep Silicon

The chipset on my SATA-II card requires the kernel module sata_sil24. Simply load this module (assuming your kernel is 2.6.x+):

modprobe sata_sil24

then,

lsmod |grep sata

to make sure it loaded.

After that, you should be able to mount your xHDD with something like the following:

mount /dev/sdc1 /mnt/xhdd

Note: you might need to tell it which filesystem your xHDD was formatted as (e.g. ext3). However, newer kernels are fairly good at auto-detecting this.

That should do it.

Also note that you can have the module, sata_sil24, automatically loaded at boot time. Simply add the following line to your /etc/modprobe.preload file (it is called /etc/modules on older kernels):

sata_sil24

Finally, if you wish to add a second xHDD (or third or fourth, to use all available ports), you might need to first umount the devices (i.e., umount /dev/sdc1, or whatever it was first mounted as) then,

rmmod sata_sil24     # to first remove the module
modprobe sata_sil24  # then reload this same module

That should automatically detect the second, connected xHDD, add you are set.

External links