What’s the best way to auto mount a usb drive or hard disk? What if the filesystem is ntfs?
To get a list of connected usb disks you can:
sudo blkid
In the screenshot above you can see there are two usb devices:
- /dev/sda1: UUID=”E89484EA9484BC96″ TYPE=”ntfs” PARTUUID=”008ffb75-01″
- /dev/sdb1: LABEL=”Extern station” UUID=”92FA278AFA2769A5″ TYPE=”ntfs” PARTUUID=” 0009a8db-01″
To be able to use these devices, you have to mount them in a folder. Let’s create two folders:
sudo mkdir /mnt/usb1 sudo mkdir /mnt/hd1
The usb1 folder I’ve created for my usb stick. The hd1 folder for my external hard drive.
We need to take ownership of these folders:
sudo chown -R pi:pi /mnt/usb1 sudo chown -R pi:pi /mnt/hd1
If any of the usb devices is formatted in ntfs, you best install ntfs-3g:
sudo apt-get install ntfs-3g
You best test if mounting is successful, this is the easy way:
sudo mount -o uid=pi -o gid=pi -t ntfs-3g /dev/sda1 /mnt/hd1
I once had a problem with ntfs-3g that was solved by updating everything:
apt-get update apt-get dist-upgrade apt-get rpi-update rpi-update
Now let’s edit our file system table, so that the usb stick & external hard drive are mounted every time the system boots:
sudo nano /etc/fstab
As you can see in the screenshot above I’ve used the disk UUID as name to find it. This way, if you unplug your usb flash drive and put it in another usb port, it still works. As type, make sure to use ntfs-3g.
Now you just need to reboot and the disks are both mounted!
sudo reboot
Sources