"mount -a" not called at startup?
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.
Related videos on Youtube
Guian
SDK team leader at StickyAdsTV a Video Ad Platform designed for publisher. Working on client side components with Javascript, Android and iOS technologies
Updated on September 18, 2022Comments
-
Guian over 1 year
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
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
, themount -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.
-
Ron over 8 yearspossible duplicate of My new hard drive won't automount on boot
-
Guian over 8 yearsin the topic you linked, the hard drive didn't mount manually either. mine does. not the same issue.
-
Ron over 8 yearsDid you try mounting by UUID?
-
Guian over 8 yearsNow I did : mount -a says "special device UUID=[MY-UUID] does not exist"
-
Guian over 8 yearsI've put back /dev/sda2 to get it mounted manually
-
nsilent22 about 8 yearsDo you have your /home on separate partition? Is your entry listed after all the entries that make /home/yourname/mydata mountpoint available?
-
Guian about 8 yearsThx for your comment nsilent, but /home isn't on a separate partition and I4ve also tried someother mountpoint like /media/mystorage without any luck.
-
unil about 8 yearsSilly 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? Sincemount -a
might create it for you when run manually, but at startup it won't. My suggestion would be to create a folder usingsudo 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.
-
-
Guian about 8 yearsThanks 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 ?
-
Tropcon about 8 yearsAh, 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.
-
Guian about 8 yearsSince 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
-
Tropcon about 8 yearsYou'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.
-
Guian about 8 yearsthere is no /var/log/boot.log .... issue reported here github.com/cubieplayer/Cubian/issues/476