(20140208 – This post has been amended to provided an updated version of the Apache directive — iceflatline)
Over this past summer I had the pleasure of cobbling together a few spare parts in order to build a Network Attached Storage (“NAS”) box based on FreeNAS. This device has more than fulfilled my initial requirements for reliable file storage and media server in my network. This post will describe how I configured this FreeNAS box to store web files and serve as a document root for the Apache http server implemented in my Ubuntu server. This approach places my local web files on a solid, reliable and centralized RAID 5 disk storage system, and provides good logical and physical separation between file storage and file server functionality.
The versions for the software used in this post were as follows:
FreeNAS v0.7.1 Shere (revision 5127)
Ubuntu Server v10.04 LTS (x64)
Apache v2.1.14
nfs-common v1:1.2.0-4ubuntu4
portmap v6.0.0-1ubuntu2
Configuring the FreeNAS Server
I began by creating the directory www on /mnt/files, an existing mount point. This directory would serve as my new Apache document root. Then, I enabled the Network File System (“NFS”) service in FreeNAS so that /mnt/files/www could be accessed from the Ubuntu server. To do this, navigate to Services->NFS->Settings and make sure that the check box for enabling NFS is checked and specify the number of servers that will run (the default value of four should easily handle dozens of users). Now select “Save and Restart.” Next, navigate to Services->NFS->Shares and select the “+” icon, where you are presented with the configuration screen for creating a new NFS share. Enter the path to be shared; the network that is authorized to access this shared path; and, make sure that the “All dirs” checkbox selected. The remaining options can retain their defaults (See Figure 1). Now select “Add” then “Apply changes.”
Figure 1
Configuring the Ubuntu Server
To configure the Ubuntu server I needed to add a couple of packages in order to mount the NFS shared path without error. The nfs-common package is needed when a host acts as an NFS client, and includes a number of processes that ensure a particular NFS connection is allowed and may proceed. Because NFS relies upon remote procedure calls to function, the package portmap is also needed to map RPC requests to the NFS service:
1
sudo apt-get install nfs-common portmap
Next, I created a directory so I could mount the NFS shared path. Here you must include the IP address of the FreeNAS server as well as the directory created on it previously:
1
2
sudo mkdir/media/www
sudo mount192.168.10.5:/mnt/files/www/media/www
In order for the shared path to mount automatically at boot time, I added the following lines to the /etc/fstab file:
1
2
3
4
5
6
###Start iceflatline
#Mount the FreeNAS directory /mnt/file/www for use as an Apache document root
I made sure the directory permissions were set correctly, and modified the owner and group associated with /media/www so that the Apache http server could access it:
1
2
3
sudo chmod755/media/www
sudo chown www-data-R/media/www
sudo chgrp www-data-R/media/www
Then edited the /etc/apache2/apache2.conf file, adding an alias for /media/www and a directory directive to the end of the file:
1
2
3
4
5
6
7
8
9
10
11
###Start iceflatline
#Alias and directive for FreeNAS directory /mnt/file/www
Alias/www“/media/www”
<Directory“/media/www”>
Options None
AllowOverride None
Require all granted
</Directory>
###End iceflatline
I created an index.html file and moved it to /media/www to test the above configuration, and made sure the file permissions were set correctly:
XHTML
1
2
3
4
5
6
7
8
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<body>
<h1>
The FreeNAS document root works!
</h1>
</body>
</html>
1
sudo chmod644/media/www/index.html
Finally, I restarted the Apache http server:
1
sudo/etc/init.d/apache2 restart
Conclusion
This concludes the post on how to configure a FreeNAS server as an Apache document root, providing a reliable way to store your web files, while at the same time utilizing the Ubuntu and Apache servers for what they do best – serving up those files.
This post will describe how to install and configure dnsmasq on a Linux- or Unix-based host. Once configured, you’ll be able to use dnsmasq to provide DNS and DHCP services in your home network.
So, why do you even need dnsmasq? Afterall, your ISP provides DNS and your home network gateway/router likely provides DHCP service for your network, right? Perhaps the best way to answer then is to explain the problem I was trying to solve. In my home network I would typically assign a static IP address to each host on my network, and then use its host file to resolve the host’s name to the IP address it was assigned. This approach allowed me to easily communicate between these hosts by simply typing their name rather than trying to remember their static IP address. However, as the number of hosts on my network started to grow, configuring static IP addresses and constantly updating the host files became unwieldy. dnsmasq solves this problem.
dnsmasq is a small, lightweight, and easy to configure caching DNS proxy and DHCP server targeted at small or home networks. It can serve the names of local hosts which are not in the global DNS, and its DHCP server integrates with its DNS server to allow hosts with DHCP-allocated addresses to appear in the DNS along with names configured either in each host or in its configuration file. dnsmasq supports static and dynamic DHCP leases and even BOOTP/TFTP for network booting of diskless hosts. dnsmasq is opensource software and is distributed under the terms of the GPL. Supported platforms include Linux, *BSD, Solaris and Mac OS X.
The versions for the software used in this post were as follows:
FreeBSD 7.2 RELEASE and dnsmasq v2.52,1
Fedora v12 and dnsmasq v2.51-1.fc12
Ubuntu server v9.10 and dnsmasq v2.47-3_all.deb
Download and Install
I chose to install dnsmasq on my Ubuntu server-based machine. However, any host on your network in which you can add one or more external nameservers to /etc/resolv.conf and some or all of your hosts in /etc/hosts, can easily be used for hosting dnsmasq.
To install dnsmasq on a Debian-based distribution like Ubuntu:
1
sudo apt-get install dnsmasq
On Fedora-based distributions:
1
2
$su
# yum install dnsmasq
And on *BSD, if you’ve installed the Ports collection:
1
2
3
$cd/usr/ports/dns/dnsmasq/
$su
# make install clean
Or, if you would prefer to add the package:
1
2
$su
# pkg_add -r dnsmasq
The dnsmasq script will be installed in /etc/init.d, symlinked from runlevels 2-5, and start automatically in a Debian-based distribution like Ubuntu. In Fedora-based distributions, the dnsmasq script is installed in /etc/init.d; however, you will need to create a symbolic link to it from the appropriate runlevel directory in order for it to start automatically at boot time. This is typically done using chkconfig command as root. The following example shows how to add the dnsmasq script to runlevels 2-5 and start dnsmasq in Fedora:
1
2
3
$su
# chkconfig dnsmasq on
# /etc/init.d/dnsmasq start
Newer versions of Fedora, however, may require this set of commands instead:
1
2
3
$su
# systemctl enable dnsmasq.service
# systemctl start dnsmasq.service
In *BSD, the dnsmasq script will be installed in /usr/local/etc/rc.d. To get dnsmasq to start at boot time, add the following line to /etc/rc.conf:
1
dnsmasq_enable="YES"
Then start dnsmasq:
1
2
$su
# /usr/local/etc/rc.d/dnsmasq start
Configure
Configuring dnsmasq is straightforward. The various DHCP and DNS options can be passed via command line when starting dnsmasq, or may be set via its configuration file, dnsmasq.conf. I generally prefer to use dnsmasq’s configuration file; it’s very well commented and easy to follow.
Let’s walk through the changes I made to the default configuration file in order to provision both DNS and DHCP service for my network. Make sure you create a backup copy of your default file before you begin.
To start, I uncommented the following two options to force dnsmasq to filter my local network DNS queries so they did not reach the public DNS servers.
1
2
3
4
5
6
7
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
By default, dnsmasq will send queries to any of the nameservers you define in /etc/resolv.conf, however, it will try to favor those it knows to be up. Uncommenting the following setting forces dnsmasq to use the nameservers listed in /etc/resolv.conf strictly in the order they appear. Since I had a pretty good sense of which DNS servers I wanted to use and in what order I uncommented this line:
1
strict-order
By default dnsmasq will listen for DNS queries on all network interfaces. I have several interfaces on my server (Hamachi, eth0, eth1, etc.), but only one that is physically connected to my local network, so I uncommented the following line in order to force dnsmasq to listen for DHCP and DNS requests on that interface only – in my case eth0. Simply repeat the line with the another interface name if you have additional interfaces you would like dnsmasq to listen to.
1
interface=eth0
The following two lines are optional; however, if used, dnsmasq will append the domain name you choose to the host names defined in dnsmasq.conf and/or /etc/hosts. I use these, but the only real benefit I saw in my network was that I was able to ping devices such as my game consoles based on the names I defined for them using the dhcp-host parameter (see below).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
expand-hosts
# Set the domain for dnsmasq. this is optional, but if it is set, it
# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
# as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
# domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
domain=home.net
To enable dnsmasq’s integrated DHCP server you’ll need to uncomment the following line and provide the range of addresses available for lease in your network, and optionally, a lease time.
1
dhcp-range=192.168.10.100,192.168.10.254,24h
If you have a host on your network that you’d like to have receive the same IP address every lease, then uncomment the following line and provide the host’s MAC address, as well as the preferred IP address – one from the dhcp-range you defined above. For example, I like to have the computer I use most often receive the same IP address. That way I can easily forward ports to it, etc. Alternatively, I could have simply given it a static IP address and defined the name/address combination in the /etc/hosts file of the machine hosting dnsmasq.
1
dhcp-host=00:27:0E:02:A8:AE,192.168.10.100
If your network is anything like mine you probably have devices that don’t have a host names associated with them the same way a computer does (e.g., Xbox 360). The following parameter will assign a name to these devices in dnsmasq. You’ll need to provide the devices’s MAC address and the name you’d like associated with it. Here’s an example of how I have this defined in my network:
1
2
3
4
5
dhcp-host=00:0B:E6:05:38:47,wii
dhcp-host=00:22:48:48:EE:37,xbox2
dhcp-host=00:12:5A:99:67:DE,xbox1
dhcp-host=00:04:5A:A5:26:B0,tivo1
dhcp-host=00:1D:7E:00:E5:58,tivo2
By default dnsmasq assumes that host running dnsmasq is your gateway/router. That wasn’t the case in my network so I needed to specify the IP address of my Cisco gateway/router in the following line:
1
dhcp-option=3,192.168.10.1
The DHCP server needs somewhere keep its lease database file. I simply retained the default location chosen by dnsmasq for my Ubuntu server install. Note that this default location will vary depending on which platform your using to host dnsmasq:
1
#dhcp-leasefile=/var/lib/misc/dnsmasq.leases
Finally, you can adjust the number of entries dnsmasq will keep in its DNS cache in the following line. I retained the default of 150.
1
#cache-size=150
That’s it for configuring dnsmasq.conf. Keep in mind though that the options described here really only scratch the surface. I would strongly urge you to read through dnsmasq.conf thoroughly as there are many more options available for fine-tuning dnsmasq’s numerious capapbilities. But for now let’s move on and consider two additional files, /etc/resolv.conf and /etc/hosts, that are important when configuring dnsmasq.
resolv.conf
dnsmasq will consult a several locations when going about the business of resolving your network’s DNS queries. These locations include its internal cache, for any queries it may have already resolved; /etc/hosts, for any static name/IP address combinations that may be defined there; and, if the DHCP server is being utilized, it will of course know from its configuration file and lease database file which IP addresses it has assigned to the hosts configured to use DHCP. When it can’t resolve DNS queries via these methods, dnsmasq will send queries to the nameservers defined in /etc/resolv.conf. You must have at least one public DNS server defined there and it’s typical to simply use the DNS server(s) provided by your ISP. Following is an example of how I have my /etc/resolv.conf file configured. Recall that I uncommented the strict-order line in dnsmasq.conf as described above so dnsmasq will utilize DNS servers in the order I have them listed here.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Allow applications on the machine hosting dnsmasq to also use it too
nameserver127.0.0.1
#Google DNS
nameserver8.8.8.8
#OpenDNS
nameserver208.67.222.222
nameserver208.67.220.220
#Cox
nameserver68.105.28.11
nameserver68.105.29.11
nameserver68.105.28.12
#An option to use my network gateway/router as the upstream DNS. Note that the #pubic DNS server addresses will need to be defined in the router.
#nameserver 192.168.10.1
/etc/hosts
As I mentioned, dnsmasq will consult the /etc/hosts file on the host its running on when resolving DNS queries. This comes handy when there are hosts in your network that you have assigned, or would like to assign, static IP addresses to. In those cases the host name/IP address combinations can simply be added to /etc/hosts. In fact, if desired, you could elect not to use dnsmasq’s DHCP server at all and rely soley on dnsmasq’s use of /etc/hosts to resolve local IP addresses. In this respect, /etc/hosts is no different than any other host file resident on most computers except that now you only need to maintain the one file. Of course, the tradeoff is that you’ll need to configure static IP addresses on all your hosts. I settled on a hybrid approach for my network. I configured all client hosts (laptops, desktop PCs, game consoles, etc) to use dnsmasq’s DHCP server, and configured all servers and network equipment (access point, router, network printers, etc.) with static IP addresses. Here’s an example of my /etc/hosts file:
1
2
3
4
5
6
7
127.0.0.1localhost
192.168.10.1router
192.168.10.2wap
192.168.10.4server1
192.168.10.11server2
192.168.10.51print-hp
192.168.10.52print-canon
Final Steps
Once dnsmasq.conf, /etc/resolv.conf, and /etc/hosts are configured to your liking restart dnsmasq:
1
# /etc/init.d/dnsmasq restart
Or, if your using *BSD:
1
# /usr/local/etc/rc.d/dnsmasq restart
Make sure to disable any other DHCP servers that may be running in your network, then simply configure your hosts to use DHCP – they should recieve an IP address that’s in the range defined in dnsmasq.conf. If you’re planning on configuring some hosts with static IP addresses, set the IP address of the host running dnsmasq as the DNS server and IP address of the gateway/router as the gateway. You’ll also want to make sure to enter that host/IP address information in /etc/hosts on the host running dnsmasq. That’s it! You now have DNS and DHCP service up and running in your network.
Now let’s run a quick test to make sure dnsmasq is caching DNS queries. The simplest to do that is to use the dig utility:
1
$dig iceflatline.com
When you look at the output from dig and find the line showing the query time. Note the time and run the command again. You should see a noticable improvement in response time indicating that dnsmasq is caching query results locally.
Conclusion
This concludes the article on how to install and configure dnsmasq on your Linux- or Unix-based host. As you can see, dnsmasq isn’t terribly complicated and proves to be a really nice open source package for implementing a small, lightweight caching DNS proxy and DHCP server. For a full list of all the configuration options and other information I encourage you to visit the dnsmasq web site.
One of my favorite things about using Linux and BSD is Conky. Conky is a free, light-weight system monitor that can display nearly any information about your system directly on your desktop. Originally a fork of Torsmo, Conky’s torsmo-based code is BSD licensed. New code in Conky has been licensed under the GPL 3.0.
Installation is easy. On a Debian-based distribution like Ubuntu:
1
$sudo apt-get install conky
On Fedora-based distributions:
1
2
$su
# yum install conky
And on BSD, if you’ve installed the Ports collection:
1
2
3
$cd/usr/ports/sysutils/conky/
$su
# make install clean
Or if you would prefer to add the package:
1
2
$su
# pkg_add -r conky
Conky is very simple to configure. Using a pre-defined set of variables in a configuration file you define what Conky should monitor and where those monitored parameters are displayed on your desktop. The look and feel of what’s displayed is highly customizable.
On most systems the default configuration file location is /etc/conky/. There you will find the sample configuration file conky.conf. You’ll want to copy it to ~/.conkyrc and then start modifying it.
When setting up my Conky configuration, I decided to dispense with the fancy network graphs and other eye candy that I’ve seen in so many others use and go with a more utilitarian approach. I settled on four areas for Conky to monitor:
System – basic system information showing kernel version, uptime, total RAM and Swap usage, etc.
Processor – shows the top five applications or processes based on CPU usage
Memory – shows the top five applications or process based on system RAM usage
Network – shows basic information regarding wired and wireless connections, including IP address, inbound and outbound speed, connection quality, etc.
This minimalistic approach looks good (less “cluttered”) in my humble opinion, and provides just the information I need while not straining system resources.
One of the many cool things about Conky is its support for the use of conditional statements within its configuration file. The ${if_existing} variable, as an example, checks for the existence of a file passed to it as an argument and will display everything between ${if_existing} and the matching ${endif}. I used this particular variable to my advantage when configuring the network monitoring section. Instead of displaying information about each wired and wireless interface, even when they weren’t up, I chose instead to display information about them only if they were up by using the existence of a particular interface (e.g., eth0) in /proc/net/route.
Anyhoo, here’s the configuration file I’m currently using. Feel free use it as is or change it to fit your needs and taste. Post your Conky configuration in the comment section.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
### Conky Display Settings
# set to yes if you want Conky to be forked in the background
background yes
#font
use_xft yes
xftfont Sans:size=8
xftalpha1
# Update interval in seconds
update_interval1.0
# This is the number of times Conky will update before quitting
# Set to zero to run forever.
total_run_times0
# Create own window instead of using desktop (required in nautilus)
own_window yes
# Use pseudo transparency with own_window?
own_window_transparent yes
# If own_window is yes, you may use type normal, desktop or override
own_window_type desktop
# If own_window is yes, these window manager hints may be used
So, you’re a CrunchBang Linux user but you want to get a little web development work done? This post will describe how to install and configure Apache, MySQL, and PHP on your box. Once set up, you’ll be able to use your LAMP server to do basic web development and code testing, maintain local copies of your web sites, etc.
The software discussed in this post are free and open source. Apache is licensed under the terms of the Apache License, a free-software license authored by the Apache Software Foundation. MySQL is available under the terms of the GNU GPL. PHP is distributed under the PHP license v3.01, an open source, BSD-style license certified by the Open Source Initiative. The remaining software, phpMyAdmin and WordPress, are not required, however, they are available under the terms of the GNU GPL. The versions for the software discussed in this post are as follows:
Apache v2.2.11-2ubuntu2
MySQL v5.1.30really5.0.75-0ubuntu10
PHP v5.2.6.dfsg.1-3ubuntu4
phpMyAdmin v4:3.1.2-1
WordPress v2.8.5
Let’s get started.
Install Apache
Let’s grab the latest version of the Apache HTTP server:
1
sudo apt-get install apache2
Once successfully installed, the Apache server will start automatically. You may notice Apache complaining with “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName.” No worries, it simply means that Apache could not find a qualified domain name like foo.com in its configuration file. Let’s prevent this message from popping up though by binding the server name to the localhost IP address. Open /etc/apache2/apache2.conf as root and append the following line to the end of the file:
1
ServerName127.0.0.1
Now restart the Apache server with the following command:
1
sudo/etc/init.dapache2 restart
Let’s also make sure now that the server is working. Open a web browser and enter http://localhost. You should see Apache’s time tested “It Works!” message.
Install MySQL.
Now that the Apache HTTP server is up and running, let’s download and install the MySQL server:
1
sudo apt-get install mysql-server
During the installation you’ll be asked several times to enter a password. You can leave it blank, but for obvious security reasons and to avoid configuration problems later, I would strongly suggest entering a password. Like Apache, once the MySQL server is installed, it will will start automatically. Now, let’s make sure the server is bound to the local host IP address like we did with Apache. Open /etc/mysql/my.cnf as root and make sure the following line exists. If not, simply append it to the end of the file:
1
bind-address=127.0.0.1
Now restart the MySQL server with the following command:
1
sudo/etc/init.d/mysql restart
Install PHP
Almost there. Let’s download and install PHP:
1
sudo apt-get install php5
Brilliant. Now let’s test to make sure PHP was installed correctly. Navigate to /var/www/ (Apache’s web root folder) and create the following file:
1
sudo touch phpinfo.php
Open that file as root and enter the following PHP function:
[php light=”true”]
[/php]
Open your web browser and enter http://localhost/phpinfo.php. You should see a page providing some information regarding your PHP installation (See Figure 1).
Figure 1
A completely optional but handy package to have for administering your MySQL server is phpMyAdmin. This package gives you the ability to create, copy, rename, alter and drop databases and tables using a web interface instead of the terminal. To install phpMyAdmin:
1
sudo apt-get install phpmyadmin
During the installation you’ll be asked to chose the web server that should be automatically configured to run phpMyAdmin. You’ll want to chose Apache2. PhpMyAdmin will also indicate that it needs to have a database installed and configured before it can be used, and offer to set up a temporary configuration for you using db-config. Since we already have our MySQL server up and running we should choose No here. Once the install finishes, open your web browser and enter http://localhost/phpmyadmin. You should see the logon page for phpMyAdmin (See Figure 2).
Figure 2
That’s it for the installation. Now let’s move on make sure everything works together.
Testing our LAMP installation using WordPress
WordPress is a full-featured blogging tool (This web site was built using WordPress. The author is not full-featured) that makes heavy use of Apache, MySQL and PHP. We’ll install it on our LAMP server to ensure we have these packages installed correctly. Let’s start by downloading WordPress directly from the developers site. You can also download and install using Aptitude but I don’t recommend it as the repository’s release is a version or two behind the most current release. Navigate to your home directory (or wherever you’d prefer to download the package to) and download and untar the package:
1
wget http://wordpress.org/latest.tar.gz
1
tar-zxvf latest.tar.gz
Let’s move the extracted wordpress/ directory to Apache’s web root folder:
1
sudo mv wordpress//var/www/
Now let’s create an MySQL database for our WordPress installation. Open phpMyAdmin in your browser. Enter root for the Username and the password you set during the MySQL installation (or simply leave this field blank if you skipped entering a password). To create a database, enter a name for it in the Create a new database field. For purposes of our example, let’s use wordpress as the name. Now select Create (See Figure 3).
Figure 3
Now we need to do a little pre-configuration on one of the wordpress files in preparation for installation. First, navigate to /var/www/wordpress/. As root, copy the file wp-config-sample.php to wp-config.php. Open the latter file and enter the database name as well as your MySQL login and password. If you chose not to create a password when you installed the MySQL server, make sure to leave two single quotes with nothing in between in DB_PASSWORD. When complete, it should look like the following:
1
2
3
4
5
6
7
8
9
10
11
12
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME','wordpress');
/** MySQL database username */
define('DB_USER','root');
/** MySQL database password */
define('DB_PASSWORD','password');
/** MySQL hostname */
define('DB_HOST','localhost');
Now let’s install WordPress. Open your web browser and navigate to http://localhost/wordpress/wp-config.php. If everything is configured as it should be you will be greeted with WordPress’s installation wizard (See Figure 4).
Figure 4
Final thoughts
One issue you may encounter is phpMyAdmin complaining that it can’t load the MySQL extension. More than likely the problem in this case is that phpMyAdmin wants the MySQL PHP module loaded automatically when Apache starts (it isn’t by default). To fix this, open /etc/php5/apache2/php.ini and uncomment following line extension=mysl.so. Save the file and restart Apache.
Finally, you may not want your LAMP server running continuously but rather only when needed. There’s a couple of ways to keep Apache and MySQL from running at boot time. First, you could simply remove their corresponding entries from /etc/rc2.d. A more elegant way to manage these daemons, however, is to download and install sysv-rc-conf.
1
sudo apt-get install sysv-rc-conf.
sysv-rc-conf provides an easy to use interface for managing rc.d symlinks. The interface comes in two different flavors, one that simply allows turning services on or off and another that allows for more fine tuned management of the symlinks. To use it just enter sysv-rc-conf on a command line as root.
When you want to use your LAMP server again you’ll need to start Apache and MySQL from the command line:
1
sudo/etc/init.d/apache2 start
1
sudo/etc/init.d/mysql start
Well, that’s it. With a couple of open source packages and a few minutes of your time you can a get a fully configured web server up and running on your CrunchBang Linux box.
(20140911 — The steps in this post were amended to address changes in recent versions of software. Minor editorial corrections were also made — iceflatline)
This post will describe how to install VirtualBox Guest Additions on your Linux guest operating system.
Oracle’s VirtualBox is a general-purpose x86 machine virtualizer that runs on Windows, Linux/Unix, and OpenSolaris hosts. It supports a large number of guest operating systems, including Linux (kernel versions 2.4 and 2.6) and the usual Windows flavors. Guest Additions consist of drivers and kernel modules that improve the usability and performance of the guest operating system, including the ability to share the mouse pointer seamlessly between the guest and host systems without the need to free the pointer from the guest OS first; the ability to share the clipboard between the guest and host OS; and, better video support through the use of guest drivers for the X Window system that provide higher (and non-standard) video modes as well as accelerated video. VirtualBox and its Guest Additions addon are free software licensed under the GNU GPL.
The versions for the software discussed in this post were as follows:
CrunchBang Linux v11
VirtualBox v4.3.14
Windows 7 Pro
So, let’s get started.
Download and Mount
VirtualBox Guest Additions are designed to be installed to the guest OS after it has been installed. So, if you haven’t already installed your Linux guest OS make sure you do that first.
VirtualBox Guest Additions is provided as a single image. To install, you mount this image as your guest OS’s virtual CD/DVD-ROM drive and install it directly from the drive from within the guest OS. Start your guest OS and release your mouse pointer. Navigate up to the top of the window and select Devices->Install Guest Additions CD Image. The image should automatically mount as your guest OS’s virtual CD/DVD-ROM drive. (you may see a disk icon of some sort on your guest OS desktop). Now, let’s install the Guest Additions. Open up a terminal and navigate to the directory where your virtual CD/DVD-ROM is mounted (e.g.,/media/cdrom0). List the contents of the directory and you’ll notice several scripts. You’ll want to run the Linux script from this directory with the following command:
1
sudo sh VBoxLinuxAdditions.run
The script will do a self-check to verify the integrity of the image, then it will proceed with uncompressing files, building new kernel modules, and installing drivers. After the script finishes, you should reboot your guest OS to ensure that Guest Additions is actually used.
Troubleshooting
One problem I’ve encountered is that the installation will fail, complaining that headers for the current kernel were not found. To fix this problem make sure to first update your packages, then install the necessary kernel headers. For example, in CrunchBang, Ubuntu, and other Debian-based distributions, run the following commands:
1
2
sudo apt-get update
sudo apt-get install linux-headers-$(uname-r)
Conclusion
I’m starting to use VirtualBox a lot now to help test and evaluate various BSD and Linux distributions in a more flexible way. Guest Additions is easy to set up and makes working in your guest OS a much better experience.