Virtualbox boot mount won't unmount

thejartender picture thejartender · Jan 13, 2012 · Viewed 8.3k times · Source

I have what I think is a very useful script here if you use NetBeans on VirtualBox guest. There seems to be one problem:

If you look at the script, it writes to a boot scripts that in turn, mounts NetBeansProjects from the Host system to Guest. This works fine. However an additional script is created and moved to the users local bin. In fact, two scripts are created: 1)To allow user to mount and 2)Unmount the mounted folder to allow flexibility.

I test the scripts and everything works on my Ubuntu guest, except the 'netbeans-unmount.sh' script.

It will not unmount the sirectory that was mounted at boot and I have tried giving the scripts file 'root' access...

Any clues as to if this will work and how? :

#!/bin/bash
#Author: Yucca Nel http://thejarbar.org
#Will restart system
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH

#Modify these variables as needed...
tempWork=/tmp/work
startupScript=/etc/init.d/rc.local
defaultNetBeansVersion=7.0.1

echo "Provide NetBeans version (7.0.1 is default) then hit [Enter] :"
  read NetBeansVersion

  if [ -z "$NetBeansVersion" ]
    then
    $NetBeansVersion=$defaultNetBeansVersion
  fi

mkdir -p /$tempWork;
cd /$tempWork;

wget http://dlc.sun.com.edgesuite.net/netbeans/7.0.1/final/bundles/netbeans-$NetBeansVersion-ml-javase-linux.sh;
sh $tempWork/*sh;


#Add Netbeans launcher to your PATH. Doing so allows you to run 'netbeans' command from the terminal
#This line will need to be changed if you changed the default install location (IOW Netbeans is not in ~/)
sudo ln -f -s ~/netbeans-$NetBeansVersion/bin/netbeans /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'NetBeansProjects'
mkdir -p $HOME/NetBeansProjects

if [ -f /sbin/mount.vboxsf ]
then
    sudo /sbin/umount /home/$HOME/NetBeansProjects
    sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects
fi

if mountpoint -q ~/NetBeansProjects
then
#Add it to the universal start script to automate process...
    sudo sed -ie '$d' $startupScript
    echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects"| sudo tee -a $startupScript
    echo "exit 0"| sudo tee -a $startupScript
    sudo chmod +x $startupScript

#Create a mount and unmount script file and add it to users local bin
    rm -rf $tempWork/*
    echo '#!/bin/bash' > $tempWork/netbeans-mount.sh
    echo '#!/bin/bash' > $tempWork/netbeans-umount.sh
    echo '#!/bin/bash' > $tempWork/mount-from-host.sh
    echo '#!/bin/bash' > $tempWork/unmount-from-host.sh
    echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" >> $tempWork/netbeans-mount.sh
    echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" >> $tempWork/mount-from-host.sh
    echo "sudo umount $HOME/NetBeansProjects" >> $tempWork/netbeans-umount.sh
    echo "sudo umount $HOME/NetBeansProjects" >> $tempWork/unmount-from-host.sh
    echo "exit 0" >> $tempWork/unmount-from-host.sh
    echo "exit 0" >> $tempWork/mount-from-host.sh
    echo "exit 0" >> $tempWork/netbeans-mount.sh
    echo "exit 0" >> $tempWork/netbeans-umount.sh

    sudo chmod +x $tempWork/*
    sudo mv -f $tempWork/*.sh /usr/local/bin
    rm -rf $tempWork
fi

#This function is used to cleanly exit with an error code.
function error_exit {
    sleep 7
    exit 1
}
#restart
sudo reboot
exit 0

Update: Hand coded unmounting in terminal also fails to unmount the NetBeans Projects folder. So I guess I need to ask if it's even possible to unmount this folder if the system initialization mounted the folder?

Update2:Still Stuck, but I have some new info after looking in etc/mtab. Here is what I see:

...
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
NetBeansProjects /home/yucca/NetBeansProjects vboxsf rw 0 0
...

It is clear that I have to run sudo unmount ~/NetBeansProjects many times!!

Additional mount options like 'f-l-a-t' won't work either as it unmounts everything and I only want my targeted directory unmounted.

Answer

Sérgio picture Sérgio · May 6, 2015

you may unmount all shares with:

sudo umount -a -t vboxsf 

or use fusermount -u

sudo fusermount -u /mnt