LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-09-2015, 10:44 AM   #1
mangya
Member
 
Registered: Jul 2015
Distribution: CentOS
Posts: 89

Rep: Reputation: Disabled
Help me on how to umount partition when its opened on another shell...


Hello All

I've a LUKS parition on /dev/sda3. I don't want to mount this partition on boot, so I've written this script to mount and umount as and when its required. I've put this script in /etc/bash.bashrc

Any time I want to open this partition, I type 'yama 1'. To close I type 'yama 0'. I've also ensured, while umounting partition, if I'm in the same partition (directory), I'll be moved to home directory - and then it will be umounted. But this works fine when I'm on the same shell. While I'm on the partition in one tab, and if I open a new tab, and there I type 'yama 0', then I get error and partition will not be umounted.

How do I ensure, no matter where i issue command, the partition will be umounted successfully.

This is my script
Code:
function yama() {
  # Opens or closes ym filesystem
  # To open : yama 1
  # To close: yama 0

  choice=$1

  if [[ $# -ne 1 ]] ; then
    echo "No arguments given. Give '1' to mount, '0' to umnount."
    exit
  elif [[ $choice -eq 1 ]]; then
    if mountpoint -q "/ym"; then
      echo "Yama already mounted. Doing nothing."
    else
      echo "Mounting Yama..."
      sudo cryptsetup luksOpen /dev/sda3 drdo
      sudo mount /dev/mapper/drdo /ym 
      echo "Yama Opened."
      cd /ym 
    fi  
  elif [[ $choice -eq 0 ]]; then
    if mountpoint -q "/ym"; then
      echo "Unmounting Yama..."
      cd ~
      sudo umount /ym 
      sudo cryptsetup luksClose drdo
      echo "Yama Closed"
    else
      echo "Yama Not mounted. Doing nothing."
    fi  
  else
    echo "I dont know what you said"
  fi  
}
Result
Code:
[abc@xyz ~]$ yama 1
Mounting Yama...
[sudo] password for abc: 
Enter passphrase for /dev/sda3: 
Yama Opened.
[abc@xyz /ym]$

[abc@xyz /ym]$ yama 0
Unmounting Yama...
Yama Closed
[abc@xyz ~]$
This is the error - when I try to close on another tab
Tab 1:
Code:
[abc@xyz ~]$ yama 1
Mounting Yama...
[sudo] password for abc: 
Enter passphrase for /dev/sda3: 
Yama Opened.
[abc@xyz /ym]$
Tab 2:
Code:
[abc@xyz ~]$ yama 0
Unmounting Yama...
[sudo] password for abc: 
umount: /ym: target is busy
        (In some cases useful info about processes that
         use the device is found by lsof(8) or fuser(1).)
device-mapper: remove ioctl on drdo failed: Device or resource busy
device-mapper: remove ioctl on drdo failed: Device or resource busy
device-mapper: remove ioctl on drdo failed: Device or resource busy
device-mapper: remove ioctl on drdo failed: Device or resource busy
device-mapper: remove ioctl on drdo failed: Device or resource busy
The error message is suggesting to use lsof or fuser, but I know what's the problem - its opened in another tab.

How do i solve this?

Thanks
 
Old 12-09-2015, 10:54 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
You might be able to script lsof or fuser to get the terminal ID of the one sitting in the directory, and then use one of the suggestions here to send it a cd command to move out:
http://unix.stackexchange.com/questi...ctive-terminal

Or skip the cd and just kill the session that's in the wrong spot.
 
1 members found this post helpful.
Old 12-09-2015, 11:03 AM   #3
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,316

Rep: Reputation: Disabled
Have you tried lazy umount?
 
1 members found this post helpful.
Old 12-09-2015, 12:00 PM   #4
mangya
Member
 
Registered: Jul 2015
Distribution: CentOS
Posts: 89

Original Poster
Rep: Reputation: Disabled
Thank you very much.

@suicidaleggroll, I tried ttyecho, but it doesn't work on my pc (arch linux). Didn't try selector - it looks too complicated. Anyway thanks.
@Emerson, It worked wonderfully. Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
partition's mounted by kernel, how to umount edenCC Linux - Server 4 10-07-2008 06:02 AM
How to close a opened file using shell scripting Ashok_mittal Programming 1 01-02-2008 06:51 AM
Unable to umount partition sgfx Linux - Newbie 3 07-10-2004 10:42 AM
umount a hd swap partition? GoinEasy9 Linux - General 6 04-09-2004 11:34 PM
Partition umount on Mac PowerPC stomcavage Linux - Hardware 0 08-02-2002 02:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration