why udev does not trigger remove event for mounted sdcard partitions?udev: Mount encrypted volume upon USB...
Is there a way to make cleveref distinguish two environments with the same counter?
What is the purpose of a disclaimer like "this is not legal advice"?
Smooth vector fields on a surface modulo diffeomorphisms
What do you call someone who likes to pick fights?
Can the Witch Sight warlock invocation see through the Mirror Image spell?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
Why does Central Limit Theorem break down in my simulation?
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?
Is this Paypal Github SDK reference really a dangerous site?
Do Paladin Auras of Differing Oaths Stack?
Difference between `nmap local-IP-address` and `nmap localhost`
Giving a career talk in my old university, how prominently should I tell students my salary?
When an outsider describes family relationships, which point of view are they using?
Are all players supposed to be able to see each others' character sheets?
Does an unused member variable take up memory?
Writing text next to a table
Is it appropriate to ask a former professor to order a book for me through an inter-library loan?
How to copy the rest of lines of a file to another file
(Codewars) Linked Lists-Sorted Insert
Can I negotiate a patent idea for a raise, under French law?
How to educate team mate to take screenshots for bugs with out unwanted stuff
Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?
Converting from "matrix" data into "coordinate" data
why udev does not trigger remove event for mounted sdcard partitions?
udev: Mount encrypted volume upon USB stick insertionWhat is the workflow for automount in Gnome 2.30?udev rule to auto load keyboard layout when usb keyboard plugged inRemove directory that is actually used by another processioctl LOOP_SET_FD failed: Device or resource busyMount partition to several directories in linuxForce media to be mounted to /dev/sr1 instead of /dev/sr0Automounting USB drives on a headless systemd linux box?How can I automatically format and write data to an SD card when it is plugged in? (Trigger systemd service on change rather than add.)Linux: How to define at what point of boot an external hdd is mounted?
Question (TL;DR):
For an SDcard with multiple partitions, how to get at least "change" event for the mounted nodes from udev, when an uSD or SDcard is removed from USB-SD reader, without disconnecting USB cable from your PC?
Bonus: Get "add/remove" event for "partition" nodes ( e.g "/dev/sdh2" )
What does not work:
When a partition is mounted, udev does not output any event for the partition node, when the card is removed !!!
Steps to reproduce:
- You need a USB-SD reader ( I highly recommend: https://www.kingston.com/en/flash/readers/FCR-HS4 ). But I tested on many other USB-SD readers (Such as GenesysLogic based ones), situation is the same.
- You need an uSD or SDcard , with at least 1 or 2 partition.
Step1:
Create a new udev rule, named as: /etc/udev/rules.d/98-test.rules
Content:
KERNEL!="sd*" , SUBSYSTEM!="block", GOTO="END"
LABEL="WORK"
ACTION=="add", RUN+="/usr/bin/logger *****Received add event for %k*****"
ACTION=="remove", RUN+="/usr/bin/logger *****Received remove event for %k*****"
ACTION=="change", RUN+="/usr/bin/logger *****Received change event for %k*****"
LABEL="END"
Step2:
Install ccze ( sudo apt install ccze ). This will give you beautiful colored logging for events.
Open a terminal, run following command:
journalctl -f | ccze -A
Result:
Mar 09 23:01:32 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:01:32 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:01:33 Ev-Turbo root[19519]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19523]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19545]: *****Received add event for sdh2*****
Mar 09 23:01:33 Ev-Turbo root[19552]: *****Received add event for sdh1*****
Step3:
Now remove the uSD card from the slot, but don't disconnect USB cable from your PC. Watch the log:
Mar 09 23:06:56 Ev-Turbo root[21220]: *****Received change event for sdh*****
Mar 09 23:06:56 Ev-Turbo root[21223]: *****Received remove event for sdh2*****
Mar 09 23:06:56 Ev-Turbo root[21222]: *****Received remove event for sdh1*****
Step4:
Now, insert your uSD card again, you will see:
Mar 09 23:11:21 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:11:21 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:11:21 Ev-Turbo root[22652]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22653]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22679]: *****Received add event for sdh2*****
Mar 09 23:11:21 Ev-Turbo root[22682]: *****Received add event for sdh1*****
And now, try mount one of the partitions to somewhere in your system:
sudo mount /dev/sdh2 /media/uSD2
You can double check if it is really mounted ( run commands: lsblk, mount...etc)
Step5:
Now, while the partition is mounted, remove your uSD card from the slot. Watch the log:
Mar 09 23:12:32 Ev-Turbo root[23049]: *****Received change event for sdh*****
Nothing more... Why there is no "remove" event anymore???
BONUS NOTES (Irrelevant to above question):
1) Most of the info on the web regarding udev/systemd/systemd-udevd and mount scripts are obsolete. Especially, for systemd v239, many of the "solved/working" answers are not usable ( Working on the issue for 2 weeks, read most of the solutions on the web, Tested on Debian 9.7, Linux Mint 18.3, Ubuntu 18.04 )
2) For systemd versions > 212, you need service files to mount your removable devices. Example:
https://serverfault.com/questions/766506/automount-usb-drives-with-systemd
3) Especially for systemd v239, you need to disable PrivateMounts to achieve automatic mounting via systemd units. For details: https://unix.stackexchange.com/questions/464959/udev-rule-to-automount-media-devices-stopped-working-after-systemd-was-updated-t
4) Mount unit files does not fit for every case, for example, when you want to mount to some specific directories based on USB host, port,lun numbers... But for some cases, this approach is very easy: https://dev.to/adarshkkumar/mount-a-volume-using-systemd-1h2f
mount systemd udev
New contributor
add a comment |
Question (TL;DR):
For an SDcard with multiple partitions, how to get at least "change" event for the mounted nodes from udev, when an uSD or SDcard is removed from USB-SD reader, without disconnecting USB cable from your PC?
Bonus: Get "add/remove" event for "partition" nodes ( e.g "/dev/sdh2" )
What does not work:
When a partition is mounted, udev does not output any event for the partition node, when the card is removed !!!
Steps to reproduce:
- You need a USB-SD reader ( I highly recommend: https://www.kingston.com/en/flash/readers/FCR-HS4 ). But I tested on many other USB-SD readers (Such as GenesysLogic based ones), situation is the same.
- You need an uSD or SDcard , with at least 1 or 2 partition.
Step1:
Create a new udev rule, named as: /etc/udev/rules.d/98-test.rules
Content:
KERNEL!="sd*" , SUBSYSTEM!="block", GOTO="END"
LABEL="WORK"
ACTION=="add", RUN+="/usr/bin/logger *****Received add event for %k*****"
ACTION=="remove", RUN+="/usr/bin/logger *****Received remove event for %k*****"
ACTION=="change", RUN+="/usr/bin/logger *****Received change event for %k*****"
LABEL="END"
Step2:
Install ccze ( sudo apt install ccze ). This will give you beautiful colored logging for events.
Open a terminal, run following command:
journalctl -f | ccze -A
Result:
Mar 09 23:01:32 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:01:32 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:01:33 Ev-Turbo root[19519]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19523]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19545]: *****Received add event for sdh2*****
Mar 09 23:01:33 Ev-Turbo root[19552]: *****Received add event for sdh1*****
Step3:
Now remove the uSD card from the slot, but don't disconnect USB cable from your PC. Watch the log:
Mar 09 23:06:56 Ev-Turbo root[21220]: *****Received change event for sdh*****
Mar 09 23:06:56 Ev-Turbo root[21223]: *****Received remove event for sdh2*****
Mar 09 23:06:56 Ev-Turbo root[21222]: *****Received remove event for sdh1*****
Step4:
Now, insert your uSD card again, you will see:
Mar 09 23:11:21 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:11:21 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:11:21 Ev-Turbo root[22652]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22653]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22679]: *****Received add event for sdh2*****
Mar 09 23:11:21 Ev-Turbo root[22682]: *****Received add event for sdh1*****
And now, try mount one of the partitions to somewhere in your system:
sudo mount /dev/sdh2 /media/uSD2
You can double check if it is really mounted ( run commands: lsblk, mount...etc)
Step5:
Now, while the partition is mounted, remove your uSD card from the slot. Watch the log:
Mar 09 23:12:32 Ev-Turbo root[23049]: *****Received change event for sdh*****
Nothing more... Why there is no "remove" event anymore???
BONUS NOTES (Irrelevant to above question):
1) Most of the info on the web regarding udev/systemd/systemd-udevd and mount scripts are obsolete. Especially, for systemd v239, many of the "solved/working" answers are not usable ( Working on the issue for 2 weeks, read most of the solutions on the web, Tested on Debian 9.7, Linux Mint 18.3, Ubuntu 18.04 )
2) For systemd versions > 212, you need service files to mount your removable devices. Example:
https://serverfault.com/questions/766506/automount-usb-drives-with-systemd
3) Especially for systemd v239, you need to disable PrivateMounts to achieve automatic mounting via systemd units. For details: https://unix.stackexchange.com/questions/464959/udev-rule-to-automount-media-devices-stopped-working-after-systemd-was-updated-t
4) Mount unit files does not fit for every case, for example, when you want to mount to some specific directories based on USB host, port,lun numbers... But for some cases, this approach is very easy: https://dev.to/adarshkkumar/mount-a-volume-using-systemd-1h2f
mount systemd udev
New contributor
add a comment |
Question (TL;DR):
For an SDcard with multiple partitions, how to get at least "change" event for the mounted nodes from udev, when an uSD or SDcard is removed from USB-SD reader, without disconnecting USB cable from your PC?
Bonus: Get "add/remove" event for "partition" nodes ( e.g "/dev/sdh2" )
What does not work:
When a partition is mounted, udev does not output any event for the partition node, when the card is removed !!!
Steps to reproduce:
- You need a USB-SD reader ( I highly recommend: https://www.kingston.com/en/flash/readers/FCR-HS4 ). But I tested on many other USB-SD readers (Such as GenesysLogic based ones), situation is the same.
- You need an uSD or SDcard , with at least 1 or 2 partition.
Step1:
Create a new udev rule, named as: /etc/udev/rules.d/98-test.rules
Content:
KERNEL!="sd*" , SUBSYSTEM!="block", GOTO="END"
LABEL="WORK"
ACTION=="add", RUN+="/usr/bin/logger *****Received add event for %k*****"
ACTION=="remove", RUN+="/usr/bin/logger *****Received remove event for %k*****"
ACTION=="change", RUN+="/usr/bin/logger *****Received change event for %k*****"
LABEL="END"
Step2:
Install ccze ( sudo apt install ccze ). This will give you beautiful colored logging for events.
Open a terminal, run following command:
journalctl -f | ccze -A
Result:
Mar 09 23:01:32 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:01:32 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:01:33 Ev-Turbo root[19519]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19523]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19545]: *****Received add event for sdh2*****
Mar 09 23:01:33 Ev-Turbo root[19552]: *****Received add event for sdh1*****
Step3:
Now remove the uSD card from the slot, but don't disconnect USB cable from your PC. Watch the log:
Mar 09 23:06:56 Ev-Turbo root[21220]: *****Received change event for sdh*****
Mar 09 23:06:56 Ev-Turbo root[21223]: *****Received remove event for sdh2*****
Mar 09 23:06:56 Ev-Turbo root[21222]: *****Received remove event for sdh1*****
Step4:
Now, insert your uSD card again, you will see:
Mar 09 23:11:21 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:11:21 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:11:21 Ev-Turbo root[22652]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22653]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22679]: *****Received add event for sdh2*****
Mar 09 23:11:21 Ev-Turbo root[22682]: *****Received add event for sdh1*****
And now, try mount one of the partitions to somewhere in your system:
sudo mount /dev/sdh2 /media/uSD2
You can double check if it is really mounted ( run commands: lsblk, mount...etc)
Step5:
Now, while the partition is mounted, remove your uSD card from the slot. Watch the log:
Mar 09 23:12:32 Ev-Turbo root[23049]: *****Received change event for sdh*****
Nothing more... Why there is no "remove" event anymore???
BONUS NOTES (Irrelevant to above question):
1) Most of the info on the web regarding udev/systemd/systemd-udevd and mount scripts are obsolete. Especially, for systemd v239, many of the "solved/working" answers are not usable ( Working on the issue for 2 weeks, read most of the solutions on the web, Tested on Debian 9.7, Linux Mint 18.3, Ubuntu 18.04 )
2) For systemd versions > 212, you need service files to mount your removable devices. Example:
https://serverfault.com/questions/766506/automount-usb-drives-with-systemd
3) Especially for systemd v239, you need to disable PrivateMounts to achieve automatic mounting via systemd units. For details: https://unix.stackexchange.com/questions/464959/udev-rule-to-automount-media-devices-stopped-working-after-systemd-was-updated-t
4) Mount unit files does not fit for every case, for example, when you want to mount to some specific directories based on USB host, port,lun numbers... But for some cases, this approach is very easy: https://dev.to/adarshkkumar/mount-a-volume-using-systemd-1h2f
mount systemd udev
New contributor
Question (TL;DR):
For an SDcard with multiple partitions, how to get at least "change" event for the mounted nodes from udev, when an uSD or SDcard is removed from USB-SD reader, without disconnecting USB cable from your PC?
Bonus: Get "add/remove" event for "partition" nodes ( e.g "/dev/sdh2" )
What does not work:
When a partition is mounted, udev does not output any event for the partition node, when the card is removed !!!
Steps to reproduce:
- You need a USB-SD reader ( I highly recommend: https://www.kingston.com/en/flash/readers/FCR-HS4 ). But I tested on many other USB-SD readers (Such as GenesysLogic based ones), situation is the same.
- You need an uSD or SDcard , with at least 1 or 2 partition.
Step1:
Create a new udev rule, named as: /etc/udev/rules.d/98-test.rules
Content:
KERNEL!="sd*" , SUBSYSTEM!="block", GOTO="END"
LABEL="WORK"
ACTION=="add", RUN+="/usr/bin/logger *****Received add event for %k*****"
ACTION=="remove", RUN+="/usr/bin/logger *****Received remove event for %k*****"
ACTION=="change", RUN+="/usr/bin/logger *****Received change event for %k*****"
LABEL="END"
Step2:
Install ccze ( sudo apt install ccze ). This will give you beautiful colored logging for events.
Open a terminal, run following command:
journalctl -f | ccze -A
Result:
Mar 09 23:01:32 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:01:32 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:01:33 Ev-Turbo root[19519]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19523]: *****Received change event for sdh*****
Mar 09 23:01:33 Ev-Turbo root[19545]: *****Received add event for sdh2*****
Mar 09 23:01:33 Ev-Turbo root[19552]: *****Received add event for sdh1*****
Step3:
Now remove the uSD card from the slot, but don't disconnect USB cable from your PC. Watch the log:
Mar 09 23:06:56 Ev-Turbo root[21220]: *****Received change event for sdh*****
Mar 09 23:06:56 Ev-Turbo root[21223]: *****Received remove event for sdh2*****
Mar 09 23:06:56 Ev-Turbo root[21222]: *****Received remove event for sdh1*****
Step4:
Now, insert your uSD card again, you will see:
Mar 09 23:11:21 Ev-Turbo kernel: sd 6:0:0:3: [sdh] 30408704 512-byte logical blocks: (15.6 GB/14.5 GiB)
Mar 09 23:11:21 Ev-Turbo kernel: sdh: sdh1 sdh2
Mar 09 23:11:21 Ev-Turbo root[22652]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22653]: *****Received change event for sdh*****
Mar 09 23:11:21 Ev-Turbo root[22679]: *****Received add event for sdh2*****
Mar 09 23:11:21 Ev-Turbo root[22682]: *****Received add event for sdh1*****
And now, try mount one of the partitions to somewhere in your system:
sudo mount /dev/sdh2 /media/uSD2
You can double check if it is really mounted ( run commands: lsblk, mount...etc)
Step5:
Now, while the partition is mounted, remove your uSD card from the slot. Watch the log:
Mar 09 23:12:32 Ev-Turbo root[23049]: *****Received change event for sdh*****
Nothing more... Why there is no "remove" event anymore???
BONUS NOTES (Irrelevant to above question):
1) Most of the info on the web regarding udev/systemd/systemd-udevd and mount scripts are obsolete. Especially, for systemd v239, many of the "solved/working" answers are not usable ( Working on the issue for 2 weeks, read most of the solutions on the web, Tested on Debian 9.7, Linux Mint 18.3, Ubuntu 18.04 )
2) For systemd versions > 212, you need service files to mount your removable devices. Example:
https://serverfault.com/questions/766506/automount-usb-drives-with-systemd
3) Especially for systemd v239, you need to disable PrivateMounts to achieve automatic mounting via systemd units. For details: https://unix.stackexchange.com/questions/464959/udev-rule-to-automount-media-devices-stopped-working-after-systemd-was-updated-t
4) Mount unit files does not fit for every case, for example, when you want to mount to some specific directories based on USB host, port,lun numbers... But for some cases, this approach is very easy: https://dev.to/adarshkkumar/mount-a-volume-using-systemd-1h2f
mount systemd udev
mount systemd udev
New contributor
New contributor
New contributor
asked 14 mins ago
Sertac TULLUKSertac TULLUK
11
11
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
Sertac TULLUK is a new contributor. Be nice, and check out our Code of Conduct.
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%2fsuperuser.com%2fquestions%2f1412775%2fwhy-udev-does-not-trigger-remove-event-for-mounted-sdcard-partitions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sertac TULLUK is a new contributor. Be nice, and check out our Code of Conduct.
Sertac TULLUK is a new contributor. Be nice, and check out our Code of Conduct.
Sertac TULLUK is a new contributor. Be nice, and check out our Code of Conduct.
Sertac TULLUK is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1412775%2fwhy-udev-does-not-trigger-remove-event-for-mounted-sdcard-partitions%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