LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 06-20-2011, 02:04 PM   #1
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Rep: Reputation: 16
How to auto-mount virtual machine locations when VMware image finishes loading?


I mount a few locations from a VMware virtual machine, but currently every time I start up VMware I need to re-mount the locations once the VMware image has started up fully, which gets tedious. I'd like to be able to mount them automatically when VMware is started.

I generally double-click the .VMX file (which is associated with VMware Player) to launch the virtual machine, but once it has finished loading I would need to run the mount commands manually or execute a bash script that does it.

Is there any way you can think of to have it done automatically? One way I can think of is to start my virtual machine by running a script that starts VMware player, sleeps for a minute or so, then runs the mount command - but setting the right sleep interval would be difficult because this varies a fair bit - and overall, it's a solution that's kinda icky and that I'd like to avoid if there's some better option. Any ideas?

Last edited by veeruk101; 06-20-2011 at 02:06 PM.
 
Old 06-20-2011, 05:49 PM   #2
eegerda
LQ Newbie
 
Registered: Apr 2005
Location: NJ
Distribution: Centos 5.5
Posts: 15

Rep: Reputation: 1
There are different ways you can do this, here are two that I can tihnk of:
1. You can write a script to start your virtual machine (I'm not familiar with vmware so you may need to look up the syntax on starting a vm from the command line). Then have the same script ping the virtual machine. If the virtual machine is pingable then mount the file system. You can use the following code to mount test if the machine if pingable and mount the file system:
Code:
#!/bin/bash
#put code to start VM here

#Now test if VM started using this code
if [ $? -eq 0 ]; then
   VM=192.168.1.5
    #Lets use the while loop to ping the server, if is pingable then we will mount the FS    
     while true; do
         ping -c 1 -w 1 $VM >/dev/null 2>&1 && MOUNT COMMAND GOES HERE  && exit
         sleep 1
     done
fi
2.Another solution is to set up ssh-keys for passwordless ssh authentication. On the virutal machine then set up your /etc/rc.local file on the VM to mount the file system on the host:
Add the following line to the /etc/rc.local file on the VMs, just make sure to add the host name on which you want to run the mount command
Code:
ssh root@HOST mount command goes here
 
Old 06-20-2011, 08:03 PM   #3
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
Those are both interesting ideas.

With the first option, could there be times where the machine is pingable but the file system isn't ready yet? I'm not too familiar with this stuff but for example if networking services are brought up first then the machine would be pinged successfully but before everything else is initialized... (I know the loop in the script would just handle it whenever it is ready, but I'm more just asking for my own learning - I guess my bigger question here is what does a successful ping actually imply about a system?)

With the second option, if I've understood correctly then the VM is the ssh client and the main system containing the VM is the ssh server, in which case the main system would be configured to accept incoming logins from the VM without a password? (But I think this option works only if the VM is booted up rather than being brought out of a suspended state, because in the latter case the startup scripts wouldn't get called. So it's not a viable option for me because most of the time I don't shut down the VM but simply suspend it and close VMware player, unless I've got it wrong.)
 
Old 06-20-2011, 09:18 PM   #4
eegerda
LQ Newbie
 
Registered: Apr 2005
Location: NJ
Distribution: Centos 5.5
Posts: 15

Rep: Reputation: 1
Good catch. In the first option there may be times in which the network services are up but your shared file system may not be ready. May I ask, how are you sharing the file system? NFS? Also what distro are you using?
I'm going to assume that you are using Centos/Rhel/Fedora since those are the distros I'm most familiar with. I'm also going to assume that you are using NFS to share the file system.
We can make the following changes to option 1 to check and make sure that nfs service is running on the VM:
Code:
#!/bin/bash
#put code to start VM here

#Now test if VM started using this code
if [ $? -eq 0 ]; then
   VM=192.168.1.5
    #Lets use the while loop to ping the server, if is pingable then we will mount the FS    
     while true; do
        if ( ping -c 1 -w 1 $VM >/dev/null 2>&1 ); then
            ssh root@$VM /sbin/service nfs status | grep running > /dev/null 2>&1 && MOUNT COMMAND GOES HERE  && exit
        fi
         sleep 1
     done
fi
The following line assumes that an ssh server is enabled on the VM, it will then check that nfs service is running, if it is it will mount your file system and then exit. In this case the ssh server is your VM and the host is the client.
Code:
if ( ping -c 1 -w 1 $VM >/dev/null 2>&1 ); then
            ssh root@$VM /sbin/service nfs status | grep running > /dev/null 2>&1 && MOUNT COMMAND GOES HERE  && exit
You will need to set up ssh-key authentication. On the ssh client do:
Code:
ssh-keygen
#assuming that you created an rsa key and that you are running the script as root, do the following
ln -s /root/.ssh/id_rsa.pub /root/.ssh/identity.pub

#Then copy the key to the VM:
ssh-copy-id VM
If ssh-copy-id does not work, you can manually copy the contents of /root/.ssh/id_rsa.pub from the host to /root/.ssh/authorized_keys on the VM. Make sure that authorized_keys has a 400 permission once you are done copying the keys. Also use an empty passphrase when creating the ssh-key pair.

As for option two. You are right, if you normally suspend your VM, option 2 will not work for you. I hope I didn't confuse you.
 
1 members found this post helpful.
  


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
vmware: trouble with loading of vmmon -- already compilled Adony Linux - Software 6 01-17-2012 11:11 PM
error loading operating system virtual box loading vmware xp the_ultimate_samurai Linux - Virtualization and Cloud 2 02-09-2010 04:25 PM
issues loading vmware 1.06 on centos5 Torensmith Linux - Newbie 1 09-05-2008 02:35 PM
Tar files loading into VMware tanu221984 Linux - Software 7 04-13-2007 01:31 PM
VMWare / GRUB loading Error 18 philipina SUSE / openSUSE 4 04-11-2006 10:16 AM


All times are GMT -5. The time now is 01:10 PM.

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