2

I have a PC with Linux Mint 18 XFCE with an external drive permanently connected through USB. I never disconnect it.

When I turn on my PC, the disk is recognized but it is not mounted. I have to "manually" mount it. Actually I just have to click on its icon in Nemo to mount it.

But I'd like to have it automatically mounted so it is always available.

How can it be accomplished?

2

If you truly never disconnect it, then you could have it mounted at boot along with your system partitions (/, /home, ...). This is done in /etc/fstab.

Assuming the partition you want to mount automatically is /dev/sdb1, run the following in order to get the partition's UUID:

# blkid /dev/sdb1 -s UUID -o value

Then, given the <UUID> string you just got, and /mnt/usb as your target mount point, append the following line to /etc/fstab :

UUID=<UUID>    /mnt/usb    ext4       defaults    0    2

or, for NTFS instead of ext4 :

UUID=<UUID>    /mnt/usb    ntfs-3g    rw,uid=1000,gid=1000,dmask=027,fmask=137    0    2

Where 1000 and 1000 are your user's UID and GID ; otherwise the device will be mounted with root ownership. The other options should be adjusted according to your needs.

Note that for ntfs-3g, you might have to install the ntfsprogs or ntfs-3g package, depending on your distribution.

Edit : if you think the device may not always be connected at boot time, I would suggest using the nofail option (which basically tells the system "don't make a fuss is it doesn't work"). This means that, in the above line, defaults becomes:

defaults,nofail,x-systemd.device-timeout=10

For NTFS, adding these options (starting from nofail) after rw should do it.

I've also added x-systemd.device-timeout which a systemd parameter telling the boot sequence to wait 10s before giving up on the device. If you don't specify this option, the default waiting time is 90s. Setting it to zero will make the system wait forever (your booting sequence will hang).

As for your other point: disconnecting the disk when the PC is on isn't a big deal, since fstab is a boot sequence thing. However, disconnecting a mounted device has its risks, since I/O operations are postponed through the use of caches, and your data may not have been synced on disk by the time you pull the plug. If you call umount (or use your graphical interface to un-mount) before disconnecting, then you're good. Calling sync instead is probably good enough, but more hazardous.

  • Thank you. It is not that i never ever disconnect it... but it might happen maybe once per month... I mean, it is always connected to my PC but it is an external drive that I can use to move data to other computers. Based on you answer and the emphasis you did on the word never I'm not sure if it is safe to implement your solution. What could happen if I disconnect the disk with the PC turned on? Or what could happen if I turn on the PC and the disk is not there? Thank you for your help. – juankvillegas Oct 6 '16 at 13:39
  • @juankvillegas I've edited my answer. The first case requires adjustements, the second not really. – John WH Smith Oct 6 '16 at 14:37
  • Thank you @JohnWHSmith. But... the blkid command do not show anything. – juankvillegas Oct 6 '16 at 14:45
  • and... it is formatted as ntfs. – juankvillegas Oct 6 '16 at 14:48
  • 1
    blkid should be run as root or with sudo (a # prompt usually means root). I've edited my answer to include an NTFS example. You'll find more information on the ntfs-3g and fstab man pages. Remember to add such details to your questions :-p – John WH Smith Oct 6 '16 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.