15

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?

StarShire
  • 287
  • 2
  • 4
  • 8

4 Answers4

18

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.

ios.id0
  • 296
  • 1
  • 4
9

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.

Fred
  • 4,592
  • 19
  • 29
0

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.

Dirk
  • 1
-1

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 enter image description here after enter image description here

gabriel@linux-romania.com

Gabriel
  • 11
  • 1