Difference between revisions of "Linux HDD"
(→Adding an external USB hard drive (HDD)) |
|||
Line 7: | Line 7: | ||
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: | 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 | + | $ tail /var/log/messages |
One of the lines should have something like the following: | 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 | Feb 19 01:04:49 linux: Attached scsi disk sda at scsi6, channel 0, id 0, lun 0 | ||
Line 13: | Line 13: | ||
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 | + | Another and simpler method (that doesn't always work) is to execute one of the following commands: |
− | grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short) | + | $ grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short) |
+ | $ udevadm monitor --udev | ||
+ | $ dmesg -T|grep -i usb | ||
+ | $ lsinput # part of the "input-utils" package | ||
*Step 2: Create the new partition(s) | *Step 2: Create the new partition(s) | ||
Line 20: | Line 23: | ||
Only do the following ''if'' there is a pre-existing partition you wish to delete (note: <code>fdisk</code> may need to be run from <code>/sbin/fdisk</code>): | Only do the following ''if'' there is a pre-existing partition you wish to delete (note: <code>fdisk</code> may need to be run from <code>/sbin/fdisk</code>): | ||
− | + | $ fdisk /dev/sda | |
d # delete a partition | 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 | 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 | p # display a list of current partitions | ||
n # create a new partition (create a "primary partition") | n # create a new partition (create a "primary partition") | ||
Line 40: | Line 43: | ||
It is customary to use the <code>/mnt</code> subdirectory for external mount points. Create a sub-directory here and call it whatever you like (I will call mine "xhdd"): | It is customary to use the <code>/mnt</code> subdirectory for external mount points. Create a sub-directory here and call it whatever you like (I will call mine "xhdd"): | ||
− | mkdir /mnt/xhdd | + | $ mkdir /mnt/xhdd |
You may want to issue the the following command to grant other users access to the mount point: | You may want to issue the the following command to grant other users access to the mount point: | ||
− | chmod go+x /mnt/xhdd | + | $ chmod go+x /mnt/xhdd |
Now manually mount the drive and test it with: | Now manually mount the drive and test it with: | ||
− | mount -t ext3 /dev/sda1 /mnt/xhdd | + | $ mount -t ext3 /dev/sda1 /mnt/xhdd |
*Step 5: Add new external HDD to <code>fstab</code> | *Step 5: Add new external HDD to <code>fstab</code> | ||
Line 53: | Line 56: | ||
To test that the above works, first un-mount the HDD (as root): | To test that the above works, first un-mount the HDD (as root): | ||
− | umount /dev/sda1 | + | $ umount /dev/sda1 |
Then mount it using the information in your <code>/etc/fstab</code> file: | Then mount it using the information in your <code>/etc/fstab</code> file: | ||
− | mount -a | + | $ mount -a |
This mounts all filesystems (of the given types) mentioned in fstab (unless they are already mounted). | This mounts all filesystems (of the given types) mentioned in fstab (unless they are already mounted). | ||
Revision as of 16:13, 11 July 2014
Contents
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 one of the following commands:
$ grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short) $ udevadm monitor --udev $ dmesg -T|grep -i usb $ lsinput # part of the "input-utils" package
- 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.
Miscellaneous HDD commands
- Find unallocated free space on a HDD:
parted /dev/sda unit TB print free | grep 'Free Space' | tail -n1 | awk '{print $3}' # in TB parted /dev/sda unit GB print free | grep 'Free Space' | tail -n1 | awk '{print $3}' # in GB parted /dev/sda unit MB print free | grep 'Free Space' | tail -n1 | awk '{print $3}' # in MB parted /dev/sda unit B print free | grep 'Free Space' | tail -n1 | awk '{print $3}' # in bytes parted /dev/sda unit '%' print free | grep 'Free Space' | tail -n1 | awk '{print $3}' parted /dev/sda unit s print free | grep 'Free Space' | tail -n1 | awk '{print $3}' # free sectors
External links
- LUKS — the upcoming standard for Linux hard disk encryption.
- The Coroner's Toolkit (TCT)
- HOWTO recover deleted files on an ext3 file system — by Carlo Wood
- dm-crypt: a device-mapper crypto target
- loop-AES
- tripwire
- Ext4 (and Ext2/Ext3) Wiki
- Migrating to ext4