Speeding up vagrant virtualbox disk access

Virtualbox driver is very slow. You can google about this all over the internet.

There are 2 ways to speed up vagrant disk access using nfs, one way is to use vagrant-bindfs plugin and another way is the traditional way to change permissions in vm. This method outlines the later.

shutdown vagrant using “vagrant halt”
In puphpet folder, update config.yaml
synced_type: nfs
then “vagrant up”
If you are seeing mount nfs error, check your /etc/hosts file. make sure 127.0.0.1 points to localhost

sudo -s, CHANGE THE ROOT PASSWD first so that you can log in again if things break.
then
change the permission for the /var/www (vagrant folder) so that they are the user_id and grp_id of the user in mac, for example,
IN your mac,
the user id is 502 and group id in 20
IN your vm,
vagrant id is 1000 and www-data id is 33
edit etc/passwd and /etc/group and change the id of 1000 to 502 and /etc/group so that the id of www-data is 20
change the own dir to that permission as well, ie /var/www and their files.
change the session dir, ie /var/lib/php/session
exit and do a “vagrant halt” and “vagrant up” again to test.

Creating Dev Environment

The idea is to have a production-like system within your system.

1. Download virtualbox.

2. Download a ready-to-go vm instance.

3. Expand the vm instance to desired size.

4. In instance, create a user and setup samba share.

5. In virtualbox host, create 2 network adapter, one “NAT” and one  “host only”, that way the centos instance can only share files to the host machine. Using vboxsf sharing option is way TOO SLOWWW.

6. Set up LAMP or any other web server in the vm instance. To access the sites in the vm instance, configure the host file in the host to point to the instance. To access the files in the vm instance, just connect to the vm via samba.

7. Now, there is a flexibility of development in host machine or vm (Up to the developer). The vm instance can run the httpd server while changes to the files can be done in any OS.

Virtualbox – samba share from linux guest

vboxsf sharing from virtualbox host to guest is way too SLOWWWWW.

Might as well get samba running in linux host and share it to the host.

To do that. Need to

1. Configure virtualbox to use NAT.

2. Add a second ethernet connection. Choose “host only”. To add the host in the dropdown. You have to create one in the virtualbox menu, not the vm menu. The guest vm should now have 2 ethernet cable.

3. Boot up the vm. the vm should have 2 eth.


eth1 Link encap:Ethernet HWaddr 08:00:27:2E:6C:AC
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe2e:6cac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10383 errors:0 dropped:0 overruns:0 frame:0
TX packets:6942 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13362425 (12.7 MiB) TX bytes:476652 (465.4 KiB)

eth2 Link encap:Ethernet HWaddr 08:00:27:FD:D4:82
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fefd:d482/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:249923 errors:0 dropped:0 overruns:0 frame:0
TX packets:162555 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41877967 (39.9 MiB) TX bytes:132228351 (126.1 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2792 errors:0 dropped:0 overruns:0 frame:0
TX packets:2792 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7643866 (7.2 MiB) TX bytes:7643866 (7.2 MiB)

The host can now connect to the guest samba share using 192.168.56.101

Changing screen resolution of Ubuntu in virtualbox

ubuntu allows screen resolutions bigger than 800 x 600. To get this to work under virtualbox, some tricks are needed.

# if not already done, install the desktop.
sudo apt-get install ubuntu-desktop

# once done, need to configure screen resolution. By default ubuntu only allows 800 x 600 or 640 x 480.
# get linux source first.
sudo apt-get install linux-headers-$(uname -r)

# restart gdm
/etc/init.d/gdm restart

# After logging into the gui, Navigate through the Devices menu to reach the Install Guest Additions option. Click OK when the cdrom dialog box pops up.
# the prompt should install the necessary drivers for you. If not, you have to manually do it yourself

sudo bash /mnt/cdrom/VBoxLinuxAdditions-x86.run

# After that, replace /etc/X11/xorg.conf with the following config. Change the resolution to suit your needs
Section "Device"
	Identifier	"Configured Video Device"
	Driver		"vboxvideo"
EndSection

Section "Monitor"
	Identifier	"Configured Monitor"
EndSection

Section "Screen"
	Identifier	"Default Screen"
	Monitor		"Configured Monitor"
	Device		"Configured Video Device"
	DefaultDepth	24
	Subsection "Display"
		Depth	24
		Modes	"1860x1020"
	EndSubSection
EndSection