bash Virtualbox boot mount won't unmount

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8852590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:17:51  来源:igfitidea点击:

Virtualbox boot mount won't unmount

linuxbashvirtualboxunmount

提问by thejartender

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

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.

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.

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...

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? :

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?

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:

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!!

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.

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

采纳答案by thejartender

I rechecked all my init files and found there were some additional mounts added to /etc/init.d/rc.localI now test for existing string before writing like this (as an example):

I rechecked all my init files and found there were some additional mounts added to /etc/init.d/rc.localI now test for existing string before writing like this (as an example):

if ! grep "JAVA_HOME=${javaUsrLib}/jdk1.7.0_01" /etc/environment

then echo "JAVA_HOME=${javaUsrLib}/jdk1.7.0_01" | sudo tee -a /etc/environment fi

then echo "JAVA_HOME=${javaUsrLib}/jdk1.7.0_01" | sudo tee -a /etc/environment fi

回答by Sérgio

you may unmount all shares with:

you may unmount all shares with:

sudo umount -a -t vboxsf 

or use fusermount -u

or use fusermount -u

sudo fusermount -u /mnt