4

I've got a problem mounting an external hard drive at startup.

The short question

Should mount -a launch during startup process ? and how can I check it does ?

The whole story

related to this topic

I've mounted my hard drive using the fstab file by adding the line:

#device        mountpoint             fstype    options  dump   fsck

/dev/sda2    /home/yourname/mydata    vfat    defaults    0    0

It mounts when I called mount -a but its not mounted at startup.

I've played with the auto/noauto mount option. As expected, when using noauto, the mount -a doesn't mount my drive. So the default auto value should be good.

that's why it seems to me the mount -a call isn't run at startup...

The system is the nano-headless cubian X1 running on a cubieboard A10 (pretty much the same as a raspeberry pi)

thanks for any advice.

Different from this topic since my hard drive boot correctly manually the issue is only at startup.

  • 1
    possible duplicate of My new hard drive won't automount on boot – Ron Aug 30 '15 at 6:30
  • in the topic you linked, the hard drive didn't mount manually either. mine does. not the same issue. – Guian Aug 30 '15 at 7:29
  • Did you try mounting by UUID? – Ron Aug 30 '15 at 8:10
  • 1
    Do you have your /home on separate partition? Is your entry listed after all the entries that make /home/yourname/mydata mountpoint available? – nsilent22 Feb 23 '16 at 20:08
  • 1
    Silly question, but have you made sure that the path exists on startup? E.g. have you made sure that /home/yourname/mydata is a real folder? If it isn't have you tried creating it? Since mount -a might create it for you when run manually, but at startup it won't. My suggestion would be to create a folder using sudo mkdir -p /media/mystorage so that it is owned by root and so that it exists on startup and change your fstab to use that instead. Since this could also be a permission issue along with a non-existent directory. – hazrpg Feb 27 '16 at 14:50
4
+50

Anything with the default settings in fstab should be mounted automatically, so you may not have it pointing to the correct device (especially since the internal drive is usually sda, and external drives are usually sdb, sdc, etc.) Here's how I would set up an external drive to automatically mount at boot:

1. Identify your device

Run sudo fdisk -l to get a list of your connected drives. You should find one matching the size and partition settings of the drive you want to automatically mount. For instance, my 16gb flash drive looks like this:

    Disk /dev/sdd: 14.9 GiB, 16007561216 bytes, 31264768 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos Disk identifier: 0x00000000

    Device     Boot Start      End  Sectors  Size Id Type
/dev/sdd1           8192 31264767  31256576 14.9G  c W95 FAT32 (LBA)

Since this is the only device on my system that's close to the correct size, my removable drive must be sdd, and it's primary partition must be sdd1. (Yours will likely be sdb or sdc; mine is such a high letter because I have a lot of drives in my computer.)

You can test to make sure that you have have the right device by running sudo mount /dev/device /mnt and then checking the /mnt folder to see if the contents of that partition is correct. (Be sure to replace "device" with your own block device. For example, sudo mount /dev/sdb1 /mnt.) To unmount the device again, use sudo umount /dev/device.

2. Find your device's UUID

We want to do this because block devices may change. For example, right now my 16gb drive is sdd, but if I add more drives to my computer it may show up as sde, or sdf. At this point, my fstab would be trying to mount the wrong drive! Unlike the block device identifier, the UUID is built into the partition and never changes (unless you reformat your drive.) This makes it a much more reliable way of mounting removable drives.

To find your devices UUID, simly use the blkid command:

sudo blkid

For my drive, the line I'm looking for looks like this (I have replaced the actual UUID with Xs):

/dev/sdd1: UUID="XXXX-XXXX" TYPE="vfat"

Note that this tells me not only the UUID, but also the filesystem type (which we will need later.)

3. Edit your fstab file

This is the trickiest step. First, open up /etc/fstab as root in your favorite text editor:

sudo gedit /etc/fstab

(Note that if you're using the Mate desktop environment you should use pluma instead of gedit. KDE also has it's own text editor.)

Now you'll want to add a line to the end of this file that will cause your drive to be automatically mounted at boot. (It's good form to add a descriptive line (starting with #) before your entry to let those who come after you know why this line was added.) In my case, it would look something like this (note that you WILL have to change this line to match the information gathered in the previous steps):

#External hard drive    
UUID=XXXX-XXXX /media/exdrive           vfat    defaults,user        0       0

The first section of the line is the UUID of the partition you want mounted. Use the UUID you got from running blkid.

The second section is what folder you want the partition mounted to. Be sure the folder actually exists! In my example, I could use sudo mkdir /media/exdrive to create the folder I want to use. It may be a good idea to put this folder outside your home folder so that other users can still access the drive. You can always make a link to it if you want it more accessible.

The third section defines the filesystem your partition should be mounted as. Use the output from blkid to find your filesystem type. The drive in my example has a fat32 filesystem, so I need to use vfat. Alternately, you may have ntfs, ext4, or some other type altogether.

The fourth section specifies the mount options. This gets complicated, so if you want to do more reading on the subject you can do so here: https://help.ubuntu.com/community/Fstab#Options For most people following this guide, defaults,user should work fine.

The last two sections (0 and 0 in our example) have to do with the backup utility dump, and if and in what order fsck will check the disk. Neither should be needed in our setup, so it is safe to leave both at 0.

4. Test it!

Your computer should now automatically mount your drive at boot, and should still mount it to the correct place if connected after boot.

  • Thanks for your detailed answer, I'll try that. just a note: the os I use is Cubian, installed on nand storage of the cubiboard. So the internal drive is /dev/nand And it makes sense that my first external drive is /dev/sda, doesn't it ? – Guian Feb 25 '16 at 9:15
  • Ah, yes. That does make sense. I'm not as familiar with those devices, but Linux is Linux, so the instructions should still work. Of course, Linux can also be made to work in any way the developer wants it too, but I can't think why they would change how things are mounted. If the instructions don't work, you may want to try contacting the developer directly. – Tropcon Feb 26 '16 at 4:16
  • Since I didn't have time to try it yet, I give you the bounty award, you deserve it thanks to yourdetailed answer. I'll keep you posted on my tests later. Thanks again – Guian Feb 29 '16 at 15:11
  • You're welcome, and thank you also. I just thought of this, but you might also check the boot log at "/var/log/boot.log" to see if it presents any reasons why your partition isn't mounting. Detecting and mounting disks is one of the first things the system does, so what you're looking for should be right near the top of the log. I hope it all works out for you. – Tropcon Feb 29 '16 at 18:46
  • there is no /var/log/boot.log .... issue reported here github.com/cubieplayer/Cubian/issues/476 – Guian Apr 24 '16 at 18:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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