This part explains how to get an external drive working with you Pi, when the drive is formatted as an NTFS drive. Not that the USB-ports of the Pi are not capable of delivering much power to external devices, so if your drive has its own powersupply make sure to use it.
By default, the Pi does not support NTFS. Install NTFS support like this:
sudo apt-get install ntfs-3g
Create a mountpoint where you want to access your drive, e.g. /media/hdd
:
sudo mkdir /media/hdd
Next you'll need the name of your drive; run the next command and look for a name like sda
, sda1
or sda2
, etc.:
sudo fdisk -l
Use the mountpoint and drive name to mount the drive. You can do so manually by typing mount /dev/sda1 /media/hdd
(replace the names where necessary), but since it needs to be mounted on every boot automatically you need to edit fstab:
sudo nano /etc/fstab
Add the following line to auto-mount on boot:
/dev/sda1 /media/hdd ntfs-3g auto,async,noatime,defaults,user,noexec,rw 0 0
Replace name and mountpoint where necessary. Now, the drive will automatically mount when booting the Pi.
If the drive has become unmounted for some reason (like detaching and re-attaching) and you want to re-mount all drives listed in fstabm, you can do so using one command:
sudo mount -a
If that fails with an error saying that /dev/sda1
can't be found, it may help to run dmesg
and try mount -a
again. If that doesn't work either, run lsusb
to check if the drive is actually properly attached. lsusb
lists all USB devices; if your drive is not in the list it may be detached or turned off.
When the drive gets corrupted (e.g. due to a power outage halfway through a write operation), the regular fsck /dev/sda1
that might help to fix a Linux drive will fail with an error like 'fsck.ntfs-3g not found' when the drive is an NTFS drive. Here's a fix:
sudo apt-get install ntfs-3g, ntfs-config, ntfsprogs, testdisk
sudo ln -s /bin/ntfsfix /sbin/fsck.ntfs
sudo ln -s /bin/ntfsfix /sbin/fsck.ntfs-3g
Make sure those paths are correct by consulting which ntfsfix
and which fsck
, because some tutorials suggest /usr/sbin/ntfsfix instead.
Now run fsck
again, and omit the -f
flag.
If fsck then still fails by saying that the disk can be mounted and that 'chkdisk' should be run, then:
sudo apt-get install testdisk
sudo testdisk
and follow the instructions on the screen to look for partitions on the drive and rewrite the corrupted partition table.
A drive that stops spinning after being idle for a while will cause problems if the Pi doesn't know how to spin it up again when it needs to. I've experienced a drive that regularly got unmounted and corrupted drive and needed the above steps to be fixed again, because it spinned down. The easiest fix is to run a cron job that simply 'touches' a file every couple of minutes to keep the drive active. I'm using the following (check the section about cron jobs on how to add a cron job) task:
0,10,20,30,40,50 * * * * touch /media/hdd/keephddspinning
I once got this error somehow, everytime I tried to access the external drive (using ls
or whatever):
Transport endpoint is not connected
The following solution, found on Stackoverflow, solved the problem:
fusermount -u /media/hdd
sudo mount -a
This simply unmounts the drive at /media/hdd
, and remounts it. A reboot could also fix the problem.