cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Can't get USB drive to auto mount

Wed May 06, 2015 5:02 am

Short version: I can't get my new USB drive to mount automatically on boot, despite the fact that it mounts fine using "sudo mount -a".

Long version:

I have a new USB external hard drive plugged into my Pi 2. I created a mount directory and successfully formatted it to be EXT4 using :
sudo mkdir /mnt/usbdrive
sudo mkfs.ext4 /dev/sda1 -L downloads
I was then able to mount it manually using:

Code: Select all

sudo mount /dev/sda1 /mnt/usbdrive
Next I wanted to get it to auto mount on fresh boot, so I added the following line to /etc/fstab:

Code: Select all

/dev/sda1       /mnt/usbdrive   auto   defaults,user     0       1
But when I rebooted the drive wasn't mounted. So I tried this:

Code: Select all

sudo mount -a
And that manual method worked to mount the drive. So next I tried changing fstab's "auto" part to "ext4".
But then I got an error on boot that prevented booting without manual intervention:

Code: Select all

File system check failed. A log is being saved in /var/log/fsck/checkfs if that location is writeable. Please repair the file system manually...
The contents of /var/log/fsck/checkfs just has:
Log of fsck -C -R -A -y
Tue May 5 21:36:23 2015

fsck from util-linux 2.20.1
e2fsck 1.42.5 (29-Jul-2012)
fsck.ext4: No such file or directory while trying to open /dev/sda1
Possibly non-existent device?
dosfsck 3.0.13, 30 Jun 2012, FAT32, LFN
/dev/mmcblk0p1: 34 files, 1840/7161 clusters
fsck died with exit status 8
Not sure what it means, but I noticed that fdisk seems to categorize the drive as "HPFS/NTFS/exFAT":

Code: Select all

pi@raspberrypi ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 31.9 GB, 31914983424 bytes
4 heads, 16 sectors/track, 973968 cylinders, total 62333952 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
Disk identifier: 0x0009bf4f

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    62333951    31105536   83  Linux

Disk /dev/sda: 500.1 GB, 500074283008 bytes
255 heads, 63 sectors/track, 60797 cylinders, total 976707584 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
Disk identifier: 0xb78e8ac4

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   976707583   488352768    7  HPFS/NTFS/exFAT
So I changed the fstab file to be "auto" so that the pi would fully boot again, but I still don't know why the drive isn't mounting automatically. Any help would be appreciated.
Last edited by cacophony555 on Wed May 06, 2015 5:59 pm, edited 1 time in total.

cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Re: Can't get USB drive to auto mount

Wed May 06, 2015 5:23 pm

There's also this output, which seems to indicate it is ext4:

Code: Select all

pi@raspberrypi ~ $ sudo blkid -c /dev/null
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="140A-14B7" TYPE="vfat"
/dev/mmcblk0p2: UUID="f24a4949-f4b2-4cad-a780-a138695079ec" TYPE="ext4"
/dev/sda1: LABEL="downloads" UUID="dad3727d-6b29-4f64-b7be-abacc0c90a23" TYPE="ext4"

User avatar
DougieLawson
Posts: 34762
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Can't get USB drive to auto mount

Wed May 06, 2015 7:20 pm

Try this

sudo blkid

Which should get something like
pi@eagle:~$ sudo blkid
/dev/mmcblk0: PTUUID="0002c262" PTTYPE="dos"
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="24A3-1E5A" TYPE="vfat" PARTUUID="0002c262-01"
/dev/mmcblk0p2: UUID="548da502-ebde-45c0-9ab2-de5e2431ee0b" TYPE="ext4" PARTUUID="0002c262-02"
/dev/sda1: PARTLABEL="Microsoft reserved partition" PARTUUID="bb424d83-6547-4ade-bcc8-89caa2a04dc3"
/dev/sda2: UUID="8c83aad9-de40-4403-89df-9b6222b69827" TYPE="ext2" PARTLABEL="Basic data partition" PARTUUID="e9349132-492b-4aa7-91c3-21835e5d4f8f"
pi@eagle:~$


You've now got a UUID value that uniquely (hopefully, unless you've been using DD) that defines that disk and no other. If the UUID is not unique use

sudo tune2fs /dev/sda2 -U random

pi@eagle:~$ sudo tune2fs /dev/sda2 -U random
tune2fs 1.42.12 (29-Aug-2014)

Then blkid again to see the new value.

pi@eagle:~$ sudo blkid
[... snipped for clarity ...]
/dev/sda2: UUID="629891a4-1160-489e-8a53-a64c988db6ae" TYPE="ext2" PARTLABEL="Basic data partition" PARTUUID="e9349132-492b-4aa7-91c3-21835e5d4f8f"
[... snipped for clarity ...]
pi@eagle:~$

So we've now got UUID="629891a4-1160-489e-8a53-a64c988db6ae" as the UUID to work with. If the drive is formatted as NTFS or FAT things are slightly different, but you'll get an ID from the blkid command that you can use.

We add a line to /etc/fstab (use sudo nano to edit that)

Code: Select all

UUID=629891a4-1160-489e-8a53-a64c988db6ae /USBdrive     ext4    defaults,noatime       0 1
Save that. Create the mount point
sudo mkdir /USBdrive
then mount it
sudo mount -a

Because it's in fstab it will automount next time you boot.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Re: Can't get USB drive to auto mount

Thu May 07, 2015 3:13 am

I did try using the UUID by adding this to /etc/fstab, but it didn't make a difference:

Code: Select all

UUID=dad3727d-6b29-4f64-b7be-abacc0c90a23 /usbdrive auto defaults,noatime 0 1
As before, doing a "sudo mount -a" works, but following reboot the drive is not mounted.

Perhaps the USB devices aren't even being recognized until after the fstab file is read? Maybe I should try autofs instead?

User avatar
rpdom
Posts: 13535
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Can't get USB drive to auto mount

Thu May 07, 2015 6:02 am

The UUID thing is handy if you may have other storage devices connected as it uniquely identifies the device no matter what /dev/sdX name it is given. However, that is not your problem.

What I suspect is happening is that your drive has not had time to initialise properly before the filesystems are mounted. There is a parameter that you can add to cmdline.txt to make the Pi wait a short time before booting to allow the disk(s) to spin-up.

Try adding bootdelay=5 to the line in cmdline.txt. It can go anywhere in the line, but everything must be on one line still.
If that doesn't work, try changing 5 to 10.

cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Re: Can't get USB drive to auto mount

Thu May 07, 2015 7:23 am

That's a great suggestion rpdom, thanks for the response. I'll give that a try.

User avatar
DougieLawson
Posts: 34762
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Can't get USB drive to auto mount

Thu May 07, 2015 10:59 am

rpdom wrote:The UUID thing is handy if you may have other storage devices connected as it uniquely identifies the device no matter what /dev/sdX name it is given. However, that is not your problem.
It's an excellent thing when you accidentally leave a USB stick inserted when you reboot and the hard drive appears as /dev/sdb rather than /dev/sda.

rootdelay=5 should fix the mount at boot problem.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

Moksu
Posts: 2
Joined: Thu May 07, 2015 7:53 pm

Re: Can't get USB drive to auto mount

Thu May 07, 2015 7:56 pm

DougieLawson wrote:
rpdom wrote:The UUID thing is handy if you may have other storage devices connected as it uniquely identifies the device no matter what /dev/sdX name it is given. However, that is not your problem.
It's an excellent thing when you accidentally leave a USB stick inserted when you reboot and the hard drive appears as /dev/sdb rather than /dev/sda.

rootdelay=5 should fix the mount at boot problem.
Hey,

I just registered this forums to say i have had the same problem than the OP.
But when i saw your respond, where would i need to insert the rootdelay=5 you talked about? (my driver is formated to ntfs-3g tho)

cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Re: Can't get USB drive to auto mount

Fri May 08, 2015 5:28 pm

Moksu wrote:
DougieLawson wrote:
rpdom wrote:The UUID thing is handy if you may have other storage devices connected as it uniquely identifies the device no matter what /dev/sdX name it is given. However, that is not your problem.
It's an excellent thing when you accidentally leave a USB stick inserted when you reboot and the hard drive appears as /dev/sdb rather than /dev/sda.

rootdelay=5 should fix the mount at boot problem.
Hey,

I just registered this forums to say i have had the same problem than the OP.
But when i saw your respond, where would i need to insert the rootdelay=5 you talked about? (my driver is formated to ntfs-3g tho)
It looks like it's here: /boot/cmdline.txt
And the line is bootdelay=5, not rootdelay=5
I'm about to try it...

User avatar
DougieLawson
Posts: 34762
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Can't get USB drive to auto mount

Fri May 08, 2015 5:41 pm

Not on my system it isn't

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=UUID=296e7e22-8bb1-4970-8dfd-c24fd4f03346 rootfstype=ext4 elevator=deadline rootwait rootdelay=5
that system has the root fs on a USB HDD formatted as ext4.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Re: Can't get USB drive to auto mount

Fri May 08, 2015 5:47 pm

Ahh, sorry, didn't notice that you were referring to a slightly different mechanism. Did I get the file location correct?

User avatar
rpdom
Posts: 13535
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Can't get USB drive to auto mount

Fri May 08, 2015 5:48 pm

Actually either rootdelay or bootdelay should work. They have a similar overall effect. rootdelay is specific to waiting for the root device to be ready, while bootdelay is more general.

Yes, /boot/cmdline.txt is correct.

cacophony555
Posts: 140
Joined: Sat Jan 18, 2014 5:54 pm

Re: Can't get USB drive to auto mount

Fri May 08, 2015 7:17 pm

So I initially tried bootdelay=10 and it didn't work. I changed it to rootdelay=10 and it worked.
Thanks again for the help.

zatz
Posts: 4
Joined: Wed May 20, 2015 5:53 am

Re: Can't get USB drive to auto mount

Wed May 20, 2015 5:57 am

Thanks to everyone who has contributed to this thread.

Like cacophony555 I had to use rootdelay to get this to work.

Return to “Troubleshooting”