How to mount USB drive in udev rule?2019 Community Moderator Electionmount is not executed when called by udevWhy does Linux mark FAT as 'dirty' simply due to mounting it?Why is my udev-fired script not working?udev rule for usb attach/detach not triggeringudev triggers rule but script fails to execute properlyUDEV-Rule to mount USB-Stick / execute scriptWhy is my udev mounted device not staying put?udev won't mount the plugged in deviceWhy is my udev rule not working?run mount as root inside udev ruleUDEV issue.. USB triggers script but USB doesn't mount properlyUdev inhibits auto mountMount fuse.mergerfs in udev script
Output visual diagram of picture
python displays `n` instead of breaking a line
Why does the frost depth increase when the surface temperature warms up?
How do I lift the insulation blower into the attic?
Capacitor electron flow
Amorphous proper classes in MK
How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?
Mortal danger in mid-grade literature
How to get directions in deep space?
Why can't I get pgrep output right to variable on bash script?
Checking @@ROWCOUNT failing
Writing in a Christian voice
Not hide and seek
Strange behavior in TikZ draw command
Started in 1987 vs. Starting in 1987
Has the laser at Magurele, Romania reached the tenth of the Sun power?
Why does a 97 / 92 key piano exist by Bosendorfer?
How do you say "Trust your struggle." in French?
When is the exact date for EOL of Ubuntu 14.04 LTS?
Taking the numerator and the denominator
Offset in split text content
Hashing password to increase entropy
Do I have to take mana from my deck or hand when tapping this card?
What do the positive and negative (+/-) transmit and receive pins mean on Ethernet cables?
How to mount USB drive in udev rule?
2019 Community Moderator Electionmount is not executed when called by udevWhy does Linux mark FAT as 'dirty' simply due to mounting it?Why is my udev-fired script not working?udev rule for usb attach/detach not triggeringudev triggers rule but script fails to execute properlyUDEV-Rule to mount USB-Stick / execute scriptWhy is my udev mounted device not staying put?udev won't mount the plugged in deviceWhy is my udev rule not working?run mount as root inside udev ruleUDEV issue.. USB triggers script but USB doesn't mount properlyUdev inhibits auto mountMount fuse.mergerfs in udev script
I setup a rule in udev to run a script in background to automount the USB drive. It managed to run the script fine, but the mounting is failing for some reason.
RULE:
ACTION=="add", KERNEL=="sd[a-z]*", RUN+="/etc/mntUsbChk.sh &"
In this script:
#!/bin/sh
sleep 2
mkdir /mnt/usb
foundUsb=false
if [ -e /dev/sda1 ]; then
mount /dev/sda1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdb1 ]; then
mount /dev/sdb1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdc1 ]; then
mount /dev/sdc1 /mnt/usb
$foundUsb=true
fi
if [ $foundUsb -eq false ]; then
exit
fi
echo "USB MOUNTED"
[ 1610.868626] FAT-fs (sdb1): Volume was not properly unmounted. Some
data may be corrupt. Please run fsck.
EDIT: More details: The script was being executed for sure because the /mnt/usb
folder was created after I plugged in the USB.
And also, if I manually type mount /dev/sda1 /mnt/usb
after I plug in USB before I enable the rule, it was able to mount it just fine. I just don't get it why it cannot mount in the rules udev.
usb udev automounting busybox
|
show 2 more comments
I setup a rule in udev to run a script in background to automount the USB drive. It managed to run the script fine, but the mounting is failing for some reason.
RULE:
ACTION=="add", KERNEL=="sd[a-z]*", RUN+="/etc/mntUsbChk.sh &"
In this script:
#!/bin/sh
sleep 2
mkdir /mnt/usb
foundUsb=false
if [ -e /dev/sda1 ]; then
mount /dev/sda1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdb1 ]; then
mount /dev/sdb1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdc1 ]; then
mount /dev/sdc1 /mnt/usb
$foundUsb=true
fi
if [ $foundUsb -eq false ]; then
exit
fi
echo "USB MOUNTED"
[ 1610.868626] FAT-fs (sdb1): Volume was not properly unmounted. Some
data may be corrupt. Please run fsck.
EDIT: More details: The script was being executed for sure because the /mnt/usb
folder was created after I plugged in the USB.
And also, if I manually type mount /dev/sda1 /mnt/usb
after I plug in USB before I enable the rule, it was able to mount it just fine. I just don't get it why it cannot mount in the rules udev.
usb udev automounting busybox
2
See my answer here.
– jasonwryan
Aug 13 '18 at 4:34
1
What distro are you on?
– Tim
Aug 14 '18 at 10:12
Does you system run only in ram? (busybox tag). Is the filesystem persistent? If it is not persistent, does the script need to run more then once in the lifetime of the boot session?
– Tim
Aug 14 '18 at 10:29
@Tim, busybox. Filesystem is persistent.
– GeneCode
Aug 14 '18 at 23:28
If it's plain BusyBox, how is it you have udev? BusyBox uses mdev.
– Tim
Aug 15 '18 at 6:11
|
show 2 more comments
I setup a rule in udev to run a script in background to automount the USB drive. It managed to run the script fine, but the mounting is failing for some reason.
RULE:
ACTION=="add", KERNEL=="sd[a-z]*", RUN+="/etc/mntUsbChk.sh &"
In this script:
#!/bin/sh
sleep 2
mkdir /mnt/usb
foundUsb=false
if [ -e /dev/sda1 ]; then
mount /dev/sda1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdb1 ]; then
mount /dev/sdb1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdc1 ]; then
mount /dev/sdc1 /mnt/usb
$foundUsb=true
fi
if [ $foundUsb -eq false ]; then
exit
fi
echo "USB MOUNTED"
[ 1610.868626] FAT-fs (sdb1): Volume was not properly unmounted. Some
data may be corrupt. Please run fsck.
EDIT: More details: The script was being executed for sure because the /mnt/usb
folder was created after I plugged in the USB.
And also, if I manually type mount /dev/sda1 /mnt/usb
after I plug in USB before I enable the rule, it was able to mount it just fine. I just don't get it why it cannot mount in the rules udev.
usb udev automounting busybox
I setup a rule in udev to run a script in background to automount the USB drive. It managed to run the script fine, but the mounting is failing for some reason.
RULE:
ACTION=="add", KERNEL=="sd[a-z]*", RUN+="/etc/mntUsbChk.sh &"
In this script:
#!/bin/sh
sleep 2
mkdir /mnt/usb
foundUsb=false
if [ -e /dev/sda1 ]; then
mount /dev/sda1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdb1 ]; then
mount /dev/sdb1 /mnt/usb
$foundUsb=true
fi
if [ -e /dev/sdc1 ]; then
mount /dev/sdc1 /mnt/usb
$foundUsb=true
fi
if [ $foundUsb -eq false ]; then
exit
fi
echo "USB MOUNTED"
[ 1610.868626] FAT-fs (sdb1): Volume was not properly unmounted. Some
data may be corrupt. Please run fsck.
EDIT: More details: The script was being executed for sure because the /mnt/usb
folder was created after I plugged in the USB.
And also, if I manually type mount /dev/sda1 /mnt/usb
after I plug in USB before I enable the rule, it was able to mount it just fine. I just don't get it why it cannot mount in the rules udev.
usb udev automounting busybox
usb udev automounting busybox
edited Aug 19 '18 at 19:16
slm♦
254k71537687
254k71537687
asked Aug 10 '18 at 0:59
GeneCodeGeneCode
659
659
2
See my answer here.
– jasonwryan
Aug 13 '18 at 4:34
1
What distro are you on?
– Tim
Aug 14 '18 at 10:12
Does you system run only in ram? (busybox tag). Is the filesystem persistent? If it is not persistent, does the script need to run more then once in the lifetime of the boot session?
– Tim
Aug 14 '18 at 10:29
@Tim, busybox. Filesystem is persistent.
– GeneCode
Aug 14 '18 at 23:28
If it's plain BusyBox, how is it you have udev? BusyBox uses mdev.
– Tim
Aug 15 '18 at 6:11
|
show 2 more comments
2
See my answer here.
– jasonwryan
Aug 13 '18 at 4:34
1
What distro are you on?
– Tim
Aug 14 '18 at 10:12
Does you system run only in ram? (busybox tag). Is the filesystem persistent? If it is not persistent, does the script need to run more then once in the lifetime of the boot session?
– Tim
Aug 14 '18 at 10:29
@Tim, busybox. Filesystem is persistent.
– GeneCode
Aug 14 '18 at 23:28
If it's plain BusyBox, how is it you have udev? BusyBox uses mdev.
– Tim
Aug 15 '18 at 6:11
2
2
See my answer here.
– jasonwryan
Aug 13 '18 at 4:34
See my answer here.
– jasonwryan
Aug 13 '18 at 4:34
1
1
What distro are you on?
– Tim
Aug 14 '18 at 10:12
What distro are you on?
– Tim
Aug 14 '18 at 10:12
Does you system run only in ram? (busybox tag). Is the filesystem persistent? If it is not persistent, does the script need to run more then once in the lifetime of the boot session?
– Tim
Aug 14 '18 at 10:29
Does you system run only in ram? (busybox tag). Is the filesystem persistent? If it is not persistent, does the script need to run more then once in the lifetime of the boot session?
– Tim
Aug 14 '18 at 10:29
@Tim, busybox. Filesystem is persistent.
– GeneCode
Aug 14 '18 at 23:28
@Tim, busybox. Filesystem is persistent.
– GeneCode
Aug 14 '18 at 23:28
If it's plain BusyBox, how is it you have udev? BusyBox uses mdev.
– Tim
Aug 15 '18 at 6:11
If it's plain BusyBox, how is it you have udev? BusyBox uses mdev.
– Tim
Aug 15 '18 at 6:11
|
show 2 more comments
3 Answers
3
active
oldest
votes
This script will fail is /mnt/usb
already exists. Not sure if this is the source of the problem, but it is for sure an error of the script.
mount /mnt/usb
Use instead:
mount -p /mnt/usb
From man mount
:
-p, --parents
no error if existing, make parent directories as needed
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
add a comment |
You have no guarantee the USB drive will be sda1,sdb1,sdc1 on add. I think some better logic may be needed there, but completely unrelated to the question.
For the question, see the existing link below:
Why does Linux mark FAT as 'dirty' simply due to mounting it?
My understanding is just pulling a usb from a Windows machine w/o ejecting doesn't clear the dirty bit on the drive. Linux assumes the worst when the dirty bit is set. I'm assuming here you can automatically run fsck to clear the dirty bit on this error message if present, then proceed to mount again. Although I'm not sure if a call to umount or fsck would clear the dirty bit.
I hope this heads in the right direction.
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
add a comment |
Although it is not very well documented, you are not supposed to run mount
from a Udev rule.
Please see my answer to a similar question for alternatives.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461700%2fhow-to-mount-usb-drive-in-udev-rule%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This script will fail is /mnt/usb
already exists. Not sure if this is the source of the problem, but it is for sure an error of the script.
mount /mnt/usb
Use instead:
mount -p /mnt/usb
From man mount
:
-p, --parents
no error if existing, make parent directories as needed
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
add a comment |
This script will fail is /mnt/usb
already exists. Not sure if this is the source of the problem, but it is for sure an error of the script.
mount /mnt/usb
Use instead:
mount -p /mnt/usb
From man mount
:
-p, --parents
no error if existing, make parent directories as needed
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
add a comment |
This script will fail is /mnt/usb
already exists. Not sure if this is the source of the problem, but it is for sure an error of the script.
mount /mnt/usb
Use instead:
mount -p /mnt/usb
From man mount
:
-p, --parents
no error if existing, make parent directories as needed
This script will fail is /mnt/usb
already exists. Not sure if this is the source of the problem, but it is for sure an error of the script.
mount /mnt/usb
Use instead:
mount -p /mnt/usb
From man mount
:
-p, --parents
no error if existing, make parent directories as needed
answered Aug 14 '18 at 10:35
TimTim
531211
531211
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
add a comment |
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
Good to know about the -p flag. But I always delete the /mnt/usb first before i plug in my usb.
– GeneCode
Aug 14 '18 at 23:28
add a comment |
You have no guarantee the USB drive will be sda1,sdb1,sdc1 on add. I think some better logic may be needed there, but completely unrelated to the question.
For the question, see the existing link below:
Why does Linux mark FAT as 'dirty' simply due to mounting it?
My understanding is just pulling a usb from a Windows machine w/o ejecting doesn't clear the dirty bit on the drive. Linux assumes the worst when the dirty bit is set. I'm assuming here you can automatically run fsck to clear the dirty bit on this error message if present, then proceed to mount again. Although I'm not sure if a call to umount or fsck would clear the dirty bit.
I hope this heads in the right direction.
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
add a comment |
You have no guarantee the USB drive will be sda1,sdb1,sdc1 on add. I think some better logic may be needed there, but completely unrelated to the question.
For the question, see the existing link below:
Why does Linux mark FAT as 'dirty' simply due to mounting it?
My understanding is just pulling a usb from a Windows machine w/o ejecting doesn't clear the dirty bit on the drive. Linux assumes the worst when the dirty bit is set. I'm assuming here you can automatically run fsck to clear the dirty bit on this error message if present, then proceed to mount again. Although I'm not sure if a call to umount or fsck would clear the dirty bit.
I hope this heads in the right direction.
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
add a comment |
You have no guarantee the USB drive will be sda1,sdb1,sdc1 on add. I think some better logic may be needed there, but completely unrelated to the question.
For the question, see the existing link below:
Why does Linux mark FAT as 'dirty' simply due to mounting it?
My understanding is just pulling a usb from a Windows machine w/o ejecting doesn't clear the dirty bit on the drive. Linux assumes the worst when the dirty bit is set. I'm assuming here you can automatically run fsck to clear the dirty bit on this error message if present, then proceed to mount again. Although I'm not sure if a call to umount or fsck would clear the dirty bit.
I hope this heads in the right direction.
You have no guarantee the USB drive will be sda1,sdb1,sdc1 on add. I think some better logic may be needed there, but completely unrelated to the question.
For the question, see the existing link below:
Why does Linux mark FAT as 'dirty' simply due to mounting it?
My understanding is just pulling a usb from a Windows machine w/o ejecting doesn't clear the dirty bit on the drive. Linux assumes the worst when the dirty bit is set. I'm assuming here you can automatically run fsck to clear the dirty bit on this error message if present, then proceed to mount again. Although I'm not sure if a call to umount or fsck would clear the dirty bit.
I hope this heads in the right direction.
answered Aug 13 '18 at 5:34
MalformedPacketMalformedPacket
113
113
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
add a comment |
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
Helps if I add the link reference: unix.stackexchange.com/questions/230181/…
– MalformedPacket
Aug 13 '18 at 5:35
add a comment |
Although it is not very well documented, you are not supposed to run mount
from a Udev rule.
Please see my answer to a similar question for alternatives.
add a comment |
Although it is not very well documented, you are not supposed to run mount
from a Udev rule.
Please see my answer to a similar question for alternatives.
add a comment |
Although it is not very well documented, you are not supposed to run mount
from a Udev rule.
Please see my answer to a similar question for alternatives.
Although it is not very well documented, you are not supposed to run mount
from a Udev rule.
Please see my answer to a similar question for alternatives.
answered 14 hours ago
MetamorphicMetamorphic
356110
356110
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461700%2fhow-to-mount-usb-drive-in-udev-rule%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
See my answer here.
– jasonwryan
Aug 13 '18 at 4:34
1
What distro are you on?
– Tim
Aug 14 '18 at 10:12
Does you system run only in ram? (busybox tag). Is the filesystem persistent? If it is not persistent, does the script need to run more then once in the lifetime of the boot session?
– Tim
Aug 14 '18 at 10:29
@Tim, busybox. Filesystem is persistent.
– GeneCode
Aug 14 '18 at 23:28
If it's plain BusyBox, how is it you have udev? BusyBox uses mdev.
– Tim
Aug 15 '18 at 6:11