ede_raspberrypi
Posts: 68
Joined: Wed Nov 11, 2015 4:15 pm

Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 4:51 pm

Hello folks,

I have a raspberry pi 2 Model B and sometimes the energy goes down. I don't understand why but on this structure:

Code: Select all

/folder/pi# ls
usb  usb1  usb2
has create a new folder. Basically I have a pen drive, which I use as a external disk, change path every time my energy goes down. As actual structure you can see which this behaviour happen two times, because I have "usb" -> "usb1" -> "usb2". This gives me problems because inside the usb2 I have a website, and after energy goes down I need access rpi to change path on apache2.conf and sites-available.
As you can see:

Code: Select all

/dev/sda1       7.5G  1.8G  5.3G  26% /folder/pi/usb2
This is a path to my external disk. I don't know why after energy goes down the system mount the usb disk (pen drive) in new path/folder.

How can I solve this issue?
Thanks

ede_raspberrypi
Posts: 68
Joined: Wed Nov 11, 2015 4:15 pm

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 4:54 pm

More information about my system:

Code: Select all

# uname -a
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
# lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie

Heater
Posts: 12751
Joined: Tue Jul 17, 2012 3:02 pm

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 5:33 pm

This is normal.

Years ago somebody thought plug-n-play would be a good idea. We have been suffering from the chaos that causes increasingly eversince.

In this case, when you plug a USB drive in it pops up as /dev/sda1 or whatever. Remove it and plug it in again and it pops up as something else, /dev/sdb1 or whatever. It's really annoying.

There is a system called udev that is listening for devices being plugged in and removed. The udev process allocates the device names.

If you want the same name for the same device you have to tell udev what you want.

That means writing or tweaking the udev configuration files. The udev rules.

See here for the messy details:

https://www.axllent.org/docs/view/udev- ... l-devices/

Ask google for other articles about writing udev rules to assign names to devices.

ejolson
Posts: 3085
Joined: Tue Mar 18, 2014 11:47 am

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 6:10 pm

ede_raspberrypi wrote:
Thu Dec 28, 2017 4:51 pm
How can I solve this issue?
Partition labels and UUIDs are used in Linux to get around the fact that device names in general are not stable. My recommendation is to uniquely label each USB drive. Depending on the filesystem, the commands

e2label /dev/sdb1 mylabel

or

dosfslabel /dev/sdb1 mylabel

make a label for the partition. After this you can mount the partition using the command

mount LABEL=mylabel /mntpoint

and never again have to refer to device names (which are constantly changing). In your case you may also want to put a suitable line in /etc/fstab to specify the mount point.

More importantly, however, would be to solve the power supply issues before your data gets corrupted or hardware damaged. Note that the low-level formatting in a USB stick or SD card can get damaged by low power to the point where the storage device doesn't work anymore.

User avatar
HawaiianPi
Posts: 4286
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 6:28 pm

You could control mounting of the USB flash drive from the /etc/fstab file. If you identify the drive by its UUID or PARTUUID then it should mount to the same location every time.

Open the fstab file for writing:
sudo nano /etc/fstab

And add this to a newline at the end:
UUID=SomeFunkyNumber /folder/pi/usb auto defaults 0 0

Use the command blkid to find your flash drive's UUID.
Last edited by HawaiianPi on Thu Dec 28, 2017 7:02 pm, edited 2 times in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

Heater
Posts: 12751
Joined: Tue Jul 17, 2012 3:02 pm

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 6:37 pm

Well, I never knew that, ejolson, or that, HawaiianPi.

Many ways to skin a cat it seems. Did I say "plug-n-play chaos" ?

Thanks, it just so happens I hit this problem again myself an hour ago.

User avatar
HawaiianPi
Posts: 4286
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 7:00 pm

Oh, forgot to say that if you are mounting a drive in fstab that might not always be connected, then add nofail to the mount options to continue the boot process if the drive is not present.

UUID=SomeFunkyNumber /folder/pi/usb auto defaults,nofail 0 0

And if you know the filesystem in use on the drive, then you should specify that in the mount line where I have auto above.

So your /etc/fstab entry would look something like this:

Code: Select all

UUID=123-456-789   /mnt/usb   vfat   defaults,nofail   0   0
With, of course, your own UUID and mount path specified.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

NotRequired
Posts: 190
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 8:01 pm

Try to look at https://github.com/bswebdk/scripts/blob ... uamount.sh it will create an udev automount rule for you.
Please do not ask questions in private messages, they will not help others.

AJB2K3
Posts: 215
Joined: Sun Aug 11, 2013 3:25 pm

Re: Weird behaviour - after energy goes donw the external disk is mount a new folder

Thu Dec 28, 2017 8:58 pm

This still happens?
I thought the had fixed it.

Have you tried ejecting the device first before reconnecting? using mount and umount?
Back in the old days, we were smarter then the technology.
Nowadays technology makes us look like villages fools in front of the children!

Return to “General discussion”