Virtualbox启动安装不会卸载

时间:2012-01-13 15:07:03

标签: linux bash virtualbox unmount

如果您在VirtualBox guest虚拟机上使用NetBeans,我认为这是一个非常有用的脚本。 似乎有一个问题:

如果查看脚本,它会写入引导脚本,然后将NetBeansProjects从Host系统安装到Guest。这很好用。但是,会创建一个附加脚本并将其移动到用户本地bin。实际上,创建了两个脚本:1)允许用户安装和2)卸载已安装的文件夹以允许灵活性。

我测试脚本,除了'netbeans-unmount.sh'脚本之外,一切都在我的Ubuntu guest上运行。

它不会卸载在启动时挂载的sirectory,我尝试给脚本文件“root”访问...

是否有效以及如何运作的线索? :

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

更新:终端中的手动编码卸载也无法卸载NetBeans项目文件夹。所以我想我需要问一下,如果系统初始化安装了文件夹,是否甚至可以卸载这个文件夹?

Update2:仍然存在,但在查看etc/mtab后我有了一些新信息。 这就是我所看到的:

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

很明显,我必须多次运行sudo unmount~ / NetBeansProjects !!

其他挂载选项(如'f-l-a-t')将无法正常工作,因为它会卸载所有内容,而我只想卸载我的目标目录。

2 个答案:

答案 0 :(得分:7)

您可以通过以下方式卸载所有股票:

sudo umount -a -t vboxsf 

或使用fusermount -u

sudo fusermount -u /mnt

答案 1 :(得分:1)

我重新检查了所有的初始文件,发现有一些额外的挂载添加到/etc/init.d/rc.local我现在测试现有的字符串,然后写这样的(作为示例):

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

然后     echo“JAVA_HOME = $ {javaUsrLib} /jdk1.7.0_01”| sudo tee -a / etc / environment 网络