TurnKey Linux Virtual Appliance Library

LAMP and VirtualBox 4 Shared Folders

I am using the following setup to test various sites on different computers using a single external disk.  This allows me to not only ferry the data around (10 GB) between different computers with very different operating systems, I also decoupled the data from the VMs for easy portability and to keep the VMs small.  I have had virtual machines crash, lockup and burn with strange errors, especially when moving them around with tons of data.  This way, my data stays safe on my external RAID box and the VMs act as pure application containers.  If one dies, I replace with another real easily.  This has worked successfully with different Turnkey versions and through various OS upgrades.   The steps below take all of 20 minutes from install to application goodness.

  1. Install Turnkey LAMP, etc using ISO in VirtualBox (4.02, in my case).
  2. Set networking to Host-only Adapter to create a private network between host and guest.  Actually, it's best to set the networking to bridged to get access to the outside world for downloads.  Don't type the stuff in parenthesis.
  3. prompt> ssh root@xxx.xxx.xxx.xxx
  4. VM shell> apt-get install aptitude   (I like to use aptitude)
  5. VM shell> aptitude install bzip2
  6. VM shell> aptitude install dkms  (http://en.wikipedia.org/wiki/Dynamic_Kernel_Module_Support)
  7. VM shell> aptitude install build-essential linux-header-`uname -r` (headers for current kernel)
  8. VirtualBox Devices menu -> Install Guest Additions...
  9. VM shell> mkdir /media/cdrom (had to do this for Turnkey 11 due to bug in Ubuntu)
  10. VM shell> mount /dev/cdrom /media/cdrom (mount VirtualBox iso in /media/cdrom)
  11. VM shell> cd /media/cdrom
  12. VM shell> ./VBoxLinuxAdditions.run (ignore error about Window System driver failure)
  13. Add a shared folder using VirtualBox Devices menu; keep track of Shared Folder name.  In my case, I shared a folder from my external SATA disk.
  14. VM shell> mkdir /var/shares/share_name (replace share_name with actual shared folder name)
  15. VM shell> mount -t vboxsf share_name /var/shares/share_name (attach share to filesystem in VM at location /var/shares/share_name, ad infinitum)
  16. From here, it's easy to edit the config files--Apache, etc--to link to the shared folder for a website
  17. As easy way is to copy the default file in /etc/apache2/sites-available so that its configuation can be used as starting point; delete the 000-default link in /etc/apache2/sites-enabled; create a link to the copy of the default file.
  18. VM shell> cp /etc/apache2/sites-enabled/default /etc/apache2/sites-enabled/default-x
  19. VM shell> rm /etc/apache2/sites-enabled/000-default
  20. VM shell> ln -s /etc/apache2/sites-available/default-x /etc/apache2/sites-enables/000-default
  21. VM shell> /etc/init.d/apache2 restart
  22. Step 15 can be automated, but I have found it easier to just type it in after I have plugged in the external disk.
Jeremy (aka JedMeister)'s picture

Thanks for sharing :)

I'm sure others may find this useful.


Resolved: "Error! Your kernel headers for kernel 2.6.32-28-g..."

 

  • 1. I got the below error when trying to install Virtual Box Additions in Turnkey LAMP Appliance.
********************
root@lamp /media/cdrom# ./VBoxLinuxAdditions.run                                                      
...
The headers for the current running kernel were not found. If the following                           
module compilation fails then this could be the reason.                                               
 ...fail!                                                                                             
...
********************
  • 2. Below is the error message from the log file
********************
...
Error! Your kernel headers for kernel 2.6.32-28-generic cannot be found at                            
/lib/modules/2.6.32-28-generic/build or /lib/modules/2.6.32-28-generic/source.                        
...
********************
  • 3. As per instructions from the Log file, I installed the below package via Apt-Get through Webmin.
********************
package installed => linux-headers-2.6.32-28-generic
 
...Installing package(s) with command apt-get -y --force-yes -f install linux-headers-2.6.32-28-generic
********************
  • 4. Now running ./VBoxLinuxAdditions.run installs the Additions
********************
root@lamp /media/cdrom# ./VBoxLinuxAdditions.run                                                      
...Building the VirtualBox Guest Additions kernel modulesDoing non-kernel setup of the Guest Additions ..
.done.                                                                                                
...
********************

Thank you!

Useful tutorial, thank you!

Sean O'Rourke's picture

missing linux-header

 

I didn't even get to that step. I got:

apt-get install linux-header-`uname -r`

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package linux-header-2.6.32-26-generic

Not sure what log I should be checking for errors, but in /lib/modules I have

/2.6.32-26-generic  and /2.6.32-30-generic

and neither have a /build or a /source directory.


Jeremy (aka JedMeister)'s picture

Typo...

Should be linux-headers-2.6.32-26-generic (not linux-header-...)

Ie:

apt-get install linux-headers-`uname -r`


Sean O'Rourke's picture

Doh!!

Thanks.


Jeremy (aka JedMeister)'s picture

No worries :)

Happens to the best of us! Hopefully it'll all work ok from here on in.

BTW hope you don't mind but I deleted the other post you put up (with your sources.list) as it wasn't really relevant in the end.


dante jarabelo's picture

/sbin/mount.vboxsf: mounting failed with the error: No such devi

I had been searching for the solution for:

/sbin/mount.vboxsf: mounting failed with the error: No such device

... and apparently there's a difference between:

apt-get install build-essential linux-headers-`uname -r`and

apt-get install build-essential linux-header-`uname -r`

The former saved me from the error.

In case you'll encounter another error with the word "protocol", just change the folder name in the edit share sectio of the virtualbox, then try the mount command again and you're good to experience relief.

Philippine Yii Framework Users Group
http://bit.ly/PhilYiiUsersGroup

Suggestion

I would suggest that once you get the base image perfected you make one final tweak before making the image multi-attach.

You should edit the file /etc/udev/rules.d/70-persistent-net.rules to remove the entries there.  It links a network interface to a specific MAC address that will probably change for each instance you are running.

I also use a config file in /etc/mysql/conf.d to redirect mysql to use an auto-mounted shared folder for DB storage.

this needs to be under how to

This needs to be under how to for turnkey documentation along with tomcat/apache deploying a war on the turnkey instance. And like how to deploy a war and configure apache like this http://www.atentia.net/2011/02/turnkey-linux-getting-my-app-running-on-tomcat-easy-wa

Thank you so much!!!

Thank you mate, you saved me!

The bit about installing the correct version of the kernel headers was really helpful, because that was where i was stuck! (I had dumbly run apt-get install linux-kernel-headers and forgot about it:) )

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)