LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-08-2014, 12:34 AM   #1
kewl_samurai
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Rep: Reputation: Disabled
how linux handles sd card remove from usb card reader


I am looking for some technical information. I have USB SD card reader connected linux system. when i connect sd card to USB card reader, "add" event is triggered and i can see sd card is mounted. i am checking on udevadm monitor. When i remove sd card from USB card reader ( not removing USB card reader), i see only "change" event triggered from kernel. No "remove" event. And mounted filesystem is still there and did not unmount. So second time when i connect i dont see any add event.

So i want to know how to unmount filesystem when only sd card is removed from card reader.

As i am new to linux detailed information on this will help me understand better.
 
Old 09-08-2014, 10:53 AM   #2
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,673

Rep: Reputation: 487Reputation: 487Reputation: 487Reputation: 487Reputation: 487
Welcome to Linux Questions!

Like Windows, you shouldn't really remove a USB storage device just by pulling it out. You don't say which distribution you are using but normally you will see the card as a mounted file system on your desktop and also via the window managers view of the /home folder.

Right click and use "safely remove device" or "eject" to unmount it (it will disappear from the desktop) then it's safe to remove. From the command line it would be something like
Code:
umount /media/<SD card name>
Hope that helps

Play Bonny!

 
Old 09-08-2014, 04:13 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,996

Rep: Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628
Most file managers have a gui way to right click a menu for unmount or eject.

From command line the mount command and unmount command are used.
 
Old 09-08-2014, 04:53 PM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member Response

Hi,

That would be mount & umount not unmount;
Quote:
from man umount;

umount - unmount file systems

SYNOPSIS
umount [-hV]

umount -a [-dflnrv] [-t vfstype] [-O options]
umount [-dflnrv] {dir|device}...

DESCRIPTION
The umount command detaches the file system(s) mentioned from the file hierarchy. A file system is specified by giving the directory where it has
been mounted. Giving the special device on which the file system lives may also work, but is obsolete, mainly because it will fail in case this
device was mounted on more than one directory.

Note that a file system cannot be unmounted when it is `busy' - for example, when there are open files on it, or when some process has its working
directory there, or when a swap file on it is in use. The offending process could even be umount itself - it opens libc, and libc in its turn may
open for example locale files. A lazy unmount avoids this problem.
 
Old 09-08-2014, 08:30 PM   #5
kewl_samurai
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
All,
Thank you for your responses, but i am looking for a solution where i can unmount ( actual command umount ) automatically.
my udev rule for usb automatically mounts the sd card when i connect usb card reader ( with sd card inserted).
udev rule for "remove" event actually unmounts the files system, but what i observe is that "remove event is not triggered when i remove sd card from card reader. I see only change event.
udevadm monitor output when i remove sd card
KERNEL[48.611865] change /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.1/1-4.1.1/1-4.1.1:1.0/host3/target3:0:0/3:0:0:0/block/sdb (block)
UDEV [48.613628] change /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.1/1-4.1.1/1-4.1.1:1.0/host3/target3:0:0/3:0:0:0/block/sdb (block)

As there is no remove event, udev doesnt automatically unmounts.
So i want to know, what do i do to unmount it automatically when sd card is removed.
 
Old 09-08-2014, 08:48 PM   #6
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
Usually udisks2 handles the mount and unmount of portable media, unless you specify an entry in fstab for a usb drive and device.
 
Old 09-08-2014, 09:38 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,996

Rep: Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628
You shouldn't just remove the sd card no matter how it connects to system. You unmount it. Maybe I misunderstand the question too.
 
Old 09-09-2014, 12:16 AM   #8
kewl_samurai
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Yes i can do that, but my requirement is to handle sd card removal from usb card reader and system should automatically unmount it.
Either udev rule or some module which can detect sd card removal.
 
Old 09-09-2014, 02:06 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
After removing the card itself from the reader the umount and/or eject command have no any meaning. Umount will prepare the system to safely remove the card. Without umounting the content of the card may be damaged.
 
Old 09-09-2014, 02:21 AM   #10
kewl_samurai
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thats correct, umount has no meaning after sd card removed.
But currently without umount mounted entry points remains, so that is the problem, with umount atleast that entry goes off.
For eg, sd card is mounted to /media/usb-sda1-xx
but even after removing i can see this path and access. I want to remove that path with umount command.
 
Old 09-09-2014, 02:50 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
that won't work because the umount command cannot be completed - successfully.
 
Old 09-09-2014, 02:53 AM   #12
kewl_samurai
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
i tried umount command manually, and it works. So i want that to be automated.
 
Old 09-09-2014, 03:24 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
umount may or may not work.
You may try the following: save a huge file on the card, remove the card without umount/eject/sync and finally try to umount.
 
Old 09-09-2014, 04:54 AM   #14
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,673

Rep: Reputation: 487Reputation: 487Reputation: 487Reputation: 487Reputation: 487
As I understand it, in a Unix/Linux system, when the umount command is issued, the OS ensures that the data held on the storage device is synchronised with anything relevant still held in main memory or cache. If the device is just removed, the OS is obviously unable to complete this synchronisation.

As an example, in the "Bad old days" you used to stop a Unix system with the commands
Code:
#sync
#sync
#halt
which "manually" flushed cache, etc, when closing the whole system down. (OK, so you didn't really need to sync twice... Just belt and Braces! )

Play Bonny!


Last edited by Soadyheid; 09-09-2014 at 04:56 AM. Reason: Additional stuff
 
Old 09-09-2014, 09:19 AM   #15
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member Response

Hi,

I agree with 'Soadyheid'. If you want to manually remove the SD then do from cli as root;
Code:
buck1:~#sync
buck1:~# umount /dev/your_device
By using the 'sync' command you are insuring everything is completed to the SD filesystem then enter the 'umount /dev/your_device'. That way no corruption of the filesystem. If you just pull the SD without insuring everything is completed then a potential corrupt filesystem.

I suggest that you do 'man sync' & 'man umount' to understand the commands.
Hope this helps.
Have fun & enjoy!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
usb device detection, manual insertion card(smart card) reader problem, zapkhiel Linux - Hardware 4 07-17-2009 08:50 AM
MEPIS: how to mount a flash card in an usb card reader for n00b frenchn00b Linux - General 1 08-06-2008 05:26 PM
USB multi-card reader; only one card can be mounted in Slack 10. KidsWriter71 Linux - Hardware 6 09-11-2004 07:24 PM
Recognizing USB card reader when card is inserted hqo201 Fedora 0 08-02-2004 05:08 PM
USB Card Reader - Linux 2.6.1 matthurne Linux - Hardware 14 02-07-2004 03:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration