Showing posts with label fedora 8. Show all posts
Showing posts with label fedora 8. Show all posts

Wednesday, December 16, 2009

Unmounting --rbind mounts in Linux

My latest confusion with using mount and its handy --bind and --rbind options is with unmounting such mounts. It should have been as simple as:

umount /my/mount/point

But when executing such a command I end up with:
umount: /my/mount/point: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))

So the error had me baffled as the mount shouldn't have been in use. I initially thought some process was grabbing a hold of it and causing me some headache. So I used lsof and fuser command to identify who was tying my mount up. It turned out that there were lots of processes tying it up. Here is a more specific example that I was working with:
mount --rbind /home /export/home

I used --rbind because /home contains a couple of mount points that I also wanted to export as part of binding /home to /export/home. Seemed simple enough. Well, after using the umount command and getting the aforementioned error I used lsof and fuser to see that just about every process from /home showed up as using both /home and /export/home.


So, I did a bit more research and found this RFE (although old): https://bugzilla.redhat.com/show_bug.cgi?id=194342


Basically it was talking about recursive binds not being able to be unmounted due to mounts inside the mount having to be unmounted first. So I immediately ran:

umount /export/home/share1
umount /export/home/share2

Yes! No error! So, now:
umount /export/home

No! The error is still there. I couldn't figure this out. I banged my head against the keyboard a few times and then decided to analyse the workaround command provided in the RFE's comments:
mount | awk '{print $3}' | grep ^/dev | sed -e s,/dev,/tmp/dev, | xargs umount
umount /tmp/dev

I plugged /home in for /dev and /export/home for /tmp/dev and executed without the xargs command on the end (I wanted to see what it was going to output):
/export/home
/export/home/share1
/export/home/share2
/export/home/user01/.gvfs

Well wouldn't you know it! I forgot about gvfs. Anyway, that prompted me to throw a quick script together. It is very raw and might not be 100% correct but it gets the job done for me and makes it so I don't have to go back and figure out where all my child-mounts are.


#!/bin/sh

MOUNTS=`mount`
OFS=$IFS

IFS=$'\n'
if [ -d "$1" ]; then
OLDWD="`pwd`"
cd "$1"
rootMount="`pwd`"
cd "$OLDWD"
else
rootMount="${1%/}"
fi

for mount in $MOUNTS; do
umountTgt=`echo $mount | awk '{print $3}'`
if [ "$umountTgt" = "$rootMount" ]; then
mountSrc=`echo $mount | awk '{print $1}'`
umountList=$umountList`mount | awk '{print $3}' | grep ^$mountSrc | sed -e s,$mountSrc,$rootMount, `$'\n'
for umount in $umountList; do
if [ "$umount" != "$rootMount" ]; then
echo "Unmounting $umount..."
/bin/umount "$umount"
fi
done
fi
done

IFS=$OFS

echo "Unmounting $rootMount..."
/bin/umount "$rootMount"

Monday, February 25, 2008

USB Tether AT&T Tilt (WM6) to Linux Laptop (Fedora 8)

I spent sometime over the weekend trying to get my Windows Mobile 6 phone tethered to my laptop so that I could use my phone's Internet access from my laptop. This, in most cases, is a simple process but for some reason it seems a bit more difficult with WM6 on my AT&T Tilt (HTC 8925).

I had done some searching for instructions on how to do this but for the most part, came up empty handed. I should probably mention that I am attempting to tether to a laptop running Fedora 8 (Linux Kernel 2.6.23).

I will say that I found some interesting information that got me pointed in the right direction on the SuSE forums, so I must give credit where credit is due and tell you that http://suseforums.net/index.php?showtopic=41219 is where I found the actual process on how to get the tether to work. I will say that the only relevant thing here is the information on creating the network interface configuration file (ifcfg-rndis0). In my case, this file went in /etc/sysconfig/network-scripts as I am using Fedora. I did not have to get the usb-rndis-lite kernel patches from SVN like the posting indicated I needed to do but this might just be due to the fact that I have the functionality from somewhere/something else. So, if you aren't able to get it to recognize your phone as a network device when you plug in the USB cable, you might want to look at patching the kernel with the usb-rndis-lite package.

Now, here is where I stumbled for some time. In the forum posting referenced above, you are instructed to enable Internet Sharing via USB on the phone. Well, in my case (and from searching, many other cases) the utility that provides Internet Sharing functionality has been replaced by the Wireless Modem utility. From the looks and sounds of it, the Wireless Modem utility does not work. I will admit that I didn't spend too much time trying to get it to work either. I just know that my initial effort proved to go nowhere so I quickly started looking for a way to get the Internet Sharing utility installed and working.

So, I jumped back on the web and starting searching for the utility. What I ran across was many references to installing a CAB from xda-developers that would add the Internet Sharing utility. Although I hate to install applications on my phone (especially when posted on a forum) I decided that I would at least download it and pull it apart to see what it did. Well, that is when I found out that I would have to register for a forum account on xds-developers to continue with a download. Well, this isn't fun and really not fair. So, my next task was to do a search for the CAB file name itself. My thought was that someone would have to had reposted it in some other forum or blog that would not require me to sign-up for an account in order to download it. Well, no luck!

I did not give up though. I remembered that when I first got my phone a few months ago I had stumbled across some Internet or sharing utility of some kind on my phone. I just could not remember what or where I stumbled across it at. So, I began to browse my phone from WM6 File Explorer. After sometime of browsing I came up empty handed. I took a break for an hour or so and then started browsing again. My second browse turned success.

It turns out that Internet Sharing is already installed on my AT&T Tilt (and probably other WM6 devices that are in the same situation). The utility just isn't accessible from the Start menu or Programs/Settings. But this is an easy fix! No need to install or run some custom CAB from some forum posting. Instead, just add the shortcut that already exists on your phone to the Start menu or to Programs. It is that simple!

The shortcut for Internet Sharing is named, wait for it... Internet Sharing. And it is located in the Windows directory. If for some reason you do not have the Internet Sharing shortcut already created on your device in the Windows directory, maybe you can use the IntShrUI shortcut. And if that shortcut doesn't exist, maybe just create your own shortcut referencing the program file name IntShrUI (also located in the Windows directory).

In my case, I simply copied /Windows/Internet Sharing to /Windows/Start Menu/Programs/Tools. Then I was done. I could then start Internet Sharing by going to my Start menu and selecting Programs and then Tools and then Internet Sharing.

Now that I had Internet Sharing up and running on my phone, I could enable it as instructed in the forum posting. Once I did this and created my network interface configuration file (ifcfg- rndis0) I plugged my phone into my laptop via USB and sure enough, I had a new network interface named rndis0 that now had an IP address of 192.168.0.102. Not only did my WM6 phone give my laptop and IP address, it also took care of DNS by giving my laptop a DNS address of 192.168.0.1 (which also happens to be the gateway address).

My next goal is to get this working via Bluetooth. I just like the idea of having my phone on my hip and checking my e-mail from my laptop without the need of pulling on the USB cable or hooking anything up. Of course, if I do get it working via Bluetooth, I would only use such a connection for limited or short sessions. USB is a much better solution as it is a bit more secure and my phone can charge while I am using its Internet access.