I generally know how to mount hard drives in a UNIX system. But I am confused with one thing. Say I have disk #1
and disk #2
. I mount disk #1
with sudo mount /dev/sda1 /mnt/drive
. How will I know that sda1
will be assigned to disk #1
and not disk #2
, especially after when the Raspberry Pi restarts? In other words, how can I have sda1
and sdb1
assigned to disk #1 and #2 respectively and prevent it from swapping with each other after reboot?
-
1This is a good question because on a multidisk system /dev/sda isn't always /dev/sda after a reboot.– OctopusMar 20, 2014 at 22:53
4 Answers
Disk drives are distinguished by their UUID(universally unique identifier).
You can find the UUID of your HDs with the command ls -l /dev/disk/by-uuid/
Then you must create the mount points sudo mkdir /MOUNT/POINT1
and change the permissions of them sudo chmod 775 /MOUNT/POINT1
Then you add a line to your fstab file (which is located at /etc/fstab) wich looks like that:
UUID=BLAHBLAH12341234 /MOUNT/POINT1 ntfs-3g rw,defaults 0 0
UUID=12341234BLAHBLAH /MOUNT/POINT2 ext rw,defaults 0 0
Of course you have to change it according to your file system etc. Then save the file and reboot and your HDs will mount automatically to the given mount points.
-
2As I pointed out in my answer, it is not the drives, but the partitions on the drives that are identified by a UUID. (A subtle difference.) If you re-format a drive, that creates a new partition which gets a new UUID.– FredMar 22, 2014 at 16:56
-
What do you mean by "/MOUNT/POINT1"? Is that the literal definition of the mount point? Aug 14, 2016 at 18:55
-
1@IgorGanapolsky its just the name of the folder you want to mount your partitions. Choose as you like.– ios.id0Aug 15, 2016 at 3:24
-
1Better than just restarting is to execute
sudo mount -a
and see if there are any errors. If there were any, it could lead to a system that does not boot.– JanApr 25, 2019 at 0:30
This is strictly a generic Linux question, but the answer anyway is partition UUIDs (Universally Unique Identifiers). Like the name says on the tin, when a partition is formatted, a random unique ID is generated that describes it. You can use this to mount to ensure that you always get the correct partition. The blkid
command gives a list of UUIDs for currently attached devices, e.g:
/dev/sda4: UUID="2d02d277-a79c-4818-adc7-c37484e17c6a" TYPE="ext3"
This will correspond to a /dev device, in this case /dev/disk/by-uuid/2d02d277-a79c-4818-adc7-c37484e17c6a
. You can use that to mount. You can use a slightly shorter notation with in /etc/fstab
to specify that a drive should be mounted:
UUID=2d02d277-a79c-4818-adc7-c37484e17c6a /mnt/backup ext3 defaults 0 0
See here for more details, or look at UUID search results here.
-
1
-
@IgorGanapolsky Try
sudo blkid
. Apparentlyblkid
requires root privileges, but on a Raspberry Pi by default you will log in as the non-privileged userpi
.– herzbubeSep 24, 2016 at 16:30
Thanks for the workaround gabriel, same problem here (Raspberry 2). But I could skip out on the 30 seconds by time the rc.local got to work the device was found, so a
sudo mount -a
in the /etc/rc.local did the job.
Well , true and not true In my case , RPI v2 4 core ,something has changed since v1 version as such: editing fstab in order to automount external hdd at start does not run at all , not using uuid , not using /dev/sda1
the problem is that i have to wait 30 seconds after complete boot in order to mount my external hdd drive , weird is that on USB stick , fstab runs flawlessly. So , i did a script to sleep 30 ; sudo mount -a to run things out .
here is /etc/fstab
pi@raspberrypi ~ $ cat /etc/fstab
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
And added last line
UUID=3d81d9e2-7d1b-4015-8c2c-29ec0875f762 /media/250_gb ext4 defaults 0 0
Here is my /etc/rc.local extension
# Begin all drives remount
clear
echo "Please wait 30 seconsds in order to remount all missing drives !!!"
for x in `seq 1 30`
do
echo -n "."
sleep 1
done
sudo mount -a
sudo service minidlna force-reload
# End drives remount
exit 0
It could be something with jmicron usb adapter, without 30 sec wait it says that device is not present even though lsusb gets correct Jmicron adapter Got to dig it deep underground !!!
Here are 2 of my TV snapshots
Before
after
-
1The question speaks about disk ordering and not about not available device. Mar 18, 2015 at 19:41
-
Not sure why you got downvoted. I noticed this same problem. I have not a problem with SSD. The problem comes when I mount disk drive. Ended up writing a script to delay the mounting to get it to work.– UnikornMar 23, 2020 at 4:45