<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>James Little</title>
	
	<link>http://www.jameslittle.me.uk</link>
	<description />
	<lastBuildDate>Sun, 04 Apr 2010 06:16:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/james-little" /><feedburner:info uri="james-little" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fjames-little" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fjames-little" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fjames-little" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/james-little" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fjames-little" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fjames-little" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fjames-little" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>The Asus Eee PC 1005PE &amp; Ubuntu</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/TFKv4oi-CHY/</link>
		<comments>http://www.jameslittle.me.uk/asus-1005pe-ubuntu/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 06:13:42 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[netbook]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/?p=61</guid>
		<description><![CDATA[It seems there&#8217;s some mixed information about whether the wireless chip in this model works out-of-the-box with Ubuntu. I&#8217;ve tested with Karmic and the Lucid Beta (Netbook Remix versions) and for me it didn&#8217;t work. The chip in my model is the Atheros AR2427, which although not a new chip, seems to have an an [...]]]></description>
			<content:encoded><![CDATA[<p>It seems there&#8217;s some <a href="https://wiki.ubuntu.com/HardwareSupport/Machines/Netbooks#Asus%20Eee%20PC%201005PE" target="_blank">mixed information</a> about whether the wireless chip in this model works out-of-the-box with Ubuntu. I&#8217;ve tested with Karmic and the Lucid Beta (Netbook Remix versions) and for me it didn&#8217;t work. The chip in my model is the Atheros AR2427, which although not a new chip, seems to have an an unfamiliar hardware device ID of <code>002c</code>, and so is not picked up by the ath9k wifi driver found in the kernel. The driver has been patched by the <a href="http://wireless.kernel.org/" target="_blank">Linux Wireless</a> developers but this patch has not worked its way into a kernel release yet, so the solution is to compile and install the latest bleeding edge wireless drivers, which is actually a pretty painless operation. It&#8217;s also a very safe operation, because the installer leaves the original kernel drivers intact and provides an uninstall script; but I have not needed to revert.</p>
<p><span id="more-61"></span> In order to compile the driver you&#8217;ll need at least a C compiler and the make utility, so I suggest installing the build-essential package:</p>
<p><code>sudo apt-get install build-essential</code><br />
You&#8217;ll need an internet connection to download packages via apt-get, so hook up to a router using a network cable if possible. If not, then download the package from packages.ubuntu.com. For Karmic for example: <a href="http://packages.ubuntu.com/karmic/devel/build-essential" target="_blank">http://packages.ubuntu.com/karmic/devel/build-essential</a>. Then use a USB key to transfer the package to your netbook and run <code>dpkg -i &lt;<em>file_name&gt;</em></code> to install.</p>
<p>You&#8217;ll also need your kernel headers installed, but they should be by default. Double check that the directory <code>/lib/modules/`uname -r`/build</code> exists.</p>
<p>Download the latest bleeding edge (updated every day) drivers from <a href="http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2.6.tar.bz2">http://wireless.kernel.org/download/compat-wireless-2.6/compat-wireless-2.6.tar.bz2</a>. Unwrap the tarball and cd into the resulting directory:<br />
<code>james@netbook:~$ tar -xvjf compat-wireless-2.6.tar.bz2<br />
james@netbook:~$ cd compat-wireless-2010-03-31</code></p>
<p><em>Notice that the directory name will change depending on what day you downloaded <img src='http://www.jameslittle.me.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<p>The AR2427 chip is covered by the ath9k driver, so we prep the make utility for making this driver:<br />
<code>$james@netbook:~/compat-wireless-2010-03-31$ ./scripts/driver-select ath9k</code></p>
<p>And then build and install:<br />
<code>james@netbook:~$ make<br />
james@netbook:~/compat-wireless-2010-03-31$ <strong>sudo</strong> make install</code></p>
<p>This will take a couple of minutes. After installation you should just need to modprobe the driver:<br />
<code>james@netbook:~/compat-wireless-2010-03-31$ sudo modprobe ath9k</code></p>
<p>and the device will appear under <code>iwconfig</code> and also a new icon at the top of the screen. To double check you have the right driver installed and active, run a modinfo:<br />
<code>james@netbook:~/compat-wireless-2010-03-31$ modinfo ath9k<br />
filename:       /lib/modules/2.6.32-18-generic/updates/drivers/net/wireless/ath/ath9k/ath9k.ko<br />
license:        Dual BSD/GPL<br />
description:    Support for Atheros 802.11n wireless LAN cards.<br />
author:         Atheros Communications<br />
srcversion:     A50A865BAAB45E03B5852F0<br />
alias:          pci:v0000168Cd0000002Esv*sd*bc*sc*i*<br />
alias:          pci:v0000168Cd0000002Dsv*sd*bc*sc*i*<br />
<strong> alias:          pci:v0000168Cd0000002Csv*sd*bc*sc*i*</strong><br />
alias:          pci:v0000168Cd0000002Bsv*sd*bc*sc*i*<br />
alias:          pci:v0000168Cd0000002Asv*sd*bc*sc*i*<br />
alias:          pci:v0000168Cd00000029sv*sd*bc*sc*i*<br />
alias:          pci:v0000168Cd00000027sv*sd*bc*sc*i*<br />
alias:          pci:v0000168Cd00000024sv*sd*bc*sc*i*<br />
alias:          pci:v0000168Cd00000023sv*sd*bc*sc*i*<br />
depends:        ath9k_hw,mac80211,led-class,ath,cfg80211,ath9k_common<br />
vermagic:       2.6.32-18-generic SMP mod_unload modversions 586<br />
parm:           debug:Debugging mask (uint)<br />
parm:           nohwcrypt:Disable hardware encryption (int)</code></p>
<p>The important line is in bold because this is the new device ID for the 1005PE&#8217;s chip, and the one that was added to the driver by the recent patch.</p>
<p>Compiling and installing the driver should work for earlier versions of Ubuntu too.</p>
<p>Aside from the wifi issue, there is also some strange behaviour when using the brightness buttons on the keyboard, but I can live with that for now. Everything else seems to work nicely and Lucid Beta1 seems very stable.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=TFKv4oi-CHY:95mNuaEhqbs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=TFKv4oi-CHY:95mNuaEhqbs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=TFKv4oi-CHY:95mNuaEhqbs:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/TFKv4oi-CHY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/asus-1005pe-ubuntu/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/asus-1005pe-ubuntu/</feedburner:origLink></item>
		<item>
		<title>Call to undefined function imagetypes()</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/QlJHJ9VS5lA/</link>
		<comments>http://www.jameslittle.me.uk/call-to-undefined-function-imagetypes/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 00:56:29 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/?p=51</guid>
		<description><![CDATA[I came across this PHP error after installing the Wordpress plugin Contact Form 7 and then using Really Simple CAPTCHA. The exact error given was:
Fatal error: Call to undefined function imagetypes() in ... on line 201.
After searching around for a while, I found that the GD library is required on the server, and (on linux [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this PHP error after installing the Wordpress plugin Contact Form 7 and then using <a href="http://wordpress.org/extend/plugins/really-simple-captcha/" target="_blank">Really Simple CAPTCHA</a>. The exact error given was:<br />
<code>Fatal error: Call to undefined function imagetypes() in ... on line 201.</code></p>
<p>After searching around for a while, I found that the <a href="http://www.boutell.com/gd/">GD library</a> is required on the server, and (on linux at least) it&#8217;s a simple case of installing the library from the repository. So on Ubuntu/Debian, run:<br />
<code>sudo apt-get install php5-gd</code></p>
<p>and on Redhat/CentOS, etc. <code>sudo yum install php-gd</code> should do the trick. This will install several dependencies, such as the underlying C Library itself.</p>
<p>Obviously if you don&#8217;t have full control over your server, you will have to ask your hosting company or administrator to do this for you.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=QlJHJ9VS5lA:XJJHuQPEGkU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=QlJHJ9VS5lA:XJJHuQPEGkU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=QlJHJ9VS5lA:XJJHuQPEGkU:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/QlJHJ9VS5lA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/call-to-undefined-function-imagetypes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/call-to-undefined-function-imagetypes/</feedburner:origLink></item>
		<item>
		<title>Macbook Uptime</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/0Z__ZfVEO7c/</link>
		<comments>http://www.jameslittle.me.uk/macbook-uptime/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 07:46:24 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[macbook]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/?p=31</guid>
		<description><![CDATA[I knew there was a reason I bought a Mac! 47 days of uptime is pretty impressive for any non-server system, let alone a laptop which often rattles around in my bag (when cycling), comes on holiday, stays &#8220;asleep&#8221; for a whole weekend, etc. etc.
And I guess that&#8217;s the point really: the sleep function on [...]]]></description>
			<content:encoded><![CDATA[<p>I knew there was a reason I bought a Mac! 47 days of uptime is pretty impressive for any non-server system, let alone a laptop which often rattles around in my bag (when cycling), comes on holiday, stays &#8220;asleep&#8221; for a whole weekend, etc. etc.</p>
<div id="attachment_35" class="wp-caption aligncenter" style="width: 616px"><a href="http://www.jameslittle.me.uk/wp-content/uploads/2009/10/macbook_uptime2.jpg"><img class="size-full wp-image-35" title="macbook uptime" src="http://www.jameslittle.me.uk/wp-content/uploads/2009/10/macbook_uptime2.jpg" alt="My Macbook's Uptime" width="606" height="258" /></a><p class="wp-caption-text">My Macbook&#39;s Uptime</p></div>
<p>And I guess that&#8217;s the point really: the sleep function on Apple&#8217;s laptops &#8220;just works&#8221;. In this case I only had to reboot after 47 days for a system update. Of course, it&#8217;s generally easy to avoid reboots on most *nix systems, but I&#8217;m yet to find a Linux desktop distro/hardware combination where the sleep function reliably works. If anyone out there would like to correct me, that would be most appreciated <img src='http://www.jameslittle.me.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also, who can beat 47 days on a Macbook (or MB Pro)?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=0Z__ZfVEO7c:9ICREMI8FPo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=0Z__ZfVEO7c:9ICREMI8FPo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=0Z__ZfVEO7c:9ICREMI8FPo:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/0Z__ZfVEO7c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/macbook-uptime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/macbook-uptime/</feedburner:origLink></item>
		<item>
		<title>Detect visitor’s country with PHP &amp; MySQL</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/BREUId9hgAA/</link>
		<comments>http://www.jameslittle.me.uk/detect-visitors-country-with-php-mysql/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 10:17:56 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/detect-visitors-country-with-php-mysql/</guid>
		<description><![CDATA[Of course you don&#8217;t have to use PHP, or MySQL for that matter. But it&#8217;s my method of choice for most web apps, and it&#8217;s also a pretty common one. The general gist is to do a lookup on a database of geographical locations for IP addresses, having taken your visitor&#8217;s IP address from the [...]]]></description>
			<content:encoded><![CDATA[<p>Of course you don&#8217;t have to use PHP, or MySQL for that matter. But it&#8217;s my method of choice for most web apps, and it&#8217;s also a pretty common one. The general gist is to do a lookup on a database of geographical locations for IP addresses, having taken your visitor&#8217;s IP address from the PHP superglobal array <a href="http://www.php.net/reserved.variables.server" target="_blank">$_SERVER</a>. Yes there are caveats: the database is not 100% complete/accurate, and some ISPs (like AOL!) use proxies across different countries so the user will appear to come from somewhere other than their true country of origin. Boo hoo, let&#8217;s do it anyway; <a href="http://www.maxmind.com/app/geolitecountry" target="_blank">according to MaxMind</a>, their free(!) GeoLite Country database is 99.3% accurate, and their licensed version, 99.8%.</p>
<p>The database is released monthly in CSV format, so I&#8217;ll have to import it into MySQL using <a href="http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html" target="_blank">mysqlimport</a>, or <a href="http://dev.mysql.com/doc/refman/5.0/en/load-data.html" target="_blank">LOAD DATA INFILE</a>. I prefer the first option. Those of you that are MySQL fans probably know that there is a <a href="http://dev.mysql.com/tech-resources/articles/csv-storage-engine.html" target="_blank">CSV storage engine</a> available, but that&#8217;s only in version 5.1 which is still in Release Candidate stage, so I&#8217;ll stick to mysqlimport.</p>
<p><a href="http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" target="_blank">Download the GeoLite database</a> from Maxmind, extract the CSV file and rename it to something more convenient; mysqlimport uses the filename for the name of the MySQL table it imports into:<br />
<code>root@jim-desktop:/home/jim/data# wget http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip<br />
root@jim-desktop:/home/jim/data# unzip GeoIPCountryCSV.zip<br />
root@jim-desktop:/home/jim/data# mv GeoIPCountryWhois.csv geo_csv.csv</code></p>
<p>Before we import the data into MySQL we need to create a table for it to go into. The following DDL accurately describes the structure of the data. Obviously create a new database if you want; here I have one called geo_ip:<br />
<code>CREATE TABLE  `geo_ip`.`geo_csv` (<br />
`start_ip` char(15) NOT NULL,<br />
`end_ip` char(15) NOT NULL,<br />
`start` int(10) unsigned NOT NULL,<br />
`end` int(10) unsigned NOT NULL,<br />
`cc` char(2) NOT NULL,<br />
`cn` varchar(50) NOT NULL<br />
) ENGINE=MyISAM DEFAULT CHARSET=latin1</code></p>
<p>If you look at the data in the CSV file you&#8217;ll see it&#8217;s delimited by commas and the text is qualified by double quotes. With that in mind, we use the following statement to import the data:<br />
<code>root@jim-desktop:/home/jim/data# mysqlimport --fields-terminated-by=","  --fields-optionally-enclosed-by="\"" --lines-terminated-by="\n" geo_ip /home/jim/data/geo_csv.csv<br />
geo_ip.geo_csv: Records: 102957  Deleted: 0  Skipped: 0  Warnings: 0</code></p>
<p>If the mysqlimport binary is not in your environment path, use locate to find it. If you don&#8217;t have it at all then use LOAD DATA INFILE.</p>
<p>So we now have the raw data imported into MySQL, but how do we use it? First let&#8217;s take a look at the data:<br />
<code>mysql&gt; select * from geo_csv order by rand() limit 10;<br />
+---------------+----------------+------------+------------+----+----------------+<br />
| start_ip      | end_ip         | start      | end        | cc | cn             |<br />
+---------------+----------------+------------+------------+----+----------------+<br />
| 207.209.7.0   | 207.209.7.255  | 3486582528 | 3486582783 | AU | Australia      |<br />
| 79.99.200.0   | 79.99.207.255  | 1331939328 | 1331941375 | BE | Belgium        |<br />
| 217.27.192.0  | 217.27.207.255 | 3642474496 | 3642478591 | DE | Germany        |<br />
| 194.59.180.0  | 194.59.180.255 | 3258692608 | 3258692863 | FR | France         |<br />
| 81.16.160.0   | 81.16.175.255  | 1360044032 | 1360048127 | SE | Sweden         |<br />
| 62.23.198.192 | 62.23.198.207  | 1041745600 | 1041745615 | GB | United Kingdom |<br />
| 64.49.231.240 | 64.49.232.15   | 1077012464 | 1077012495 | US | United States  |<br />
| 83.217.68.32  | 83.217.68.95   | 1406747680 | 1406747743 | BE | Belgium        |<br />
| 91.193.20.0   | 91.193.23.255  | 1539380224 | 1539381247 | CH | Switzerland    |<br />
| 194.37.249.0  | 194.37.249.255 | 3257268480 | 3257268735 | SE | Sweden         |<br />
+---------------+----------------+------------+------------+----+----------------+<br />
10 rows in set (0.22 sec)</code></p>
<p>The table is essentially a big list (~103k records) of IP ranges, given in both <a href="http://en.wikipedia.org/wiki/IPv4#Address_representations" target="_blank">dot-decimal and decimal form</a>. The decimal form is the most efficient to search on as the datatype int requires less memory than char, and with integers we can reliably make use of operators such as greater than, less than, BETWEEN, etc. Exactly how you will use the data will depend on your scenario. I began looking into this when I was working on a German website that wanted to know when a visitor was from Switzerland, so it could display prices in CHF rather than Euros. So in fact, all I needed to know was whether the visitor was Swiss, and if they were from any other country, they would see Euros. So the only columns I&#8217;ll need from the table are start and end, and all the rows belonging to Switzerland, or &#8216;CH&#8217;. So to make searches more efficient I&#8217;ll grab only the data I need and put it in a new table called ch_ip:<br />
<code>mysql&gt; create table ch_ip as select start,end from geo_csv where cc='CH';<br />
Query OK, 2023 rows affected (0.05 sec)<br />
Records: 2023  Duplicates: 0  Warnings: 0</code><br />
Great, that&#8217;s cut the data from nearly 103 thousand records to just over 2 thousand, and we&#8217;ve also lopped off four columns. I&#8217;ll now be searching on a table that&#8217;s 18K in size, rather than the original 5.3MB. Maybe you need every row of data in your scenario, but in many cases you only need a fraction. And in any case, you really don&#8217;t need the start_ip and end_ip columns (as you will see shortly). You could also split off the country names (cn column) into another table so that cc becomes a foreign key. Or you could ditch the country names completely and create an array of CC =&gt; CN in your application; there are only 239 unique CCs after all:<br />
<code>mysql&gt; select count(distinct cc) from geo_csv;<br />
+--------------------+<br />
| count(distinct cc) |<br />
+--------------------+<br />
|                239 |<br />
+--------------------+<br />
1 row in set (0.05 sec)<br />
</code><br />
So I have my table of 2,023 Swiss IP ranges. Now I need to grab a visitor&#8217;s IP address and convert it into decimal notation. For this we can use PHP&#8217;s built-in function <a href="http://www.php.net/ip2long" target="_blank">ip2long</a>. We use sprintf to ensure the result is always unsigned:<br />
<code>&lt;?php<br />
$ip_num = sprintf("%u", ip2long($_SERVER['REMOTE_ADDR']));<br />
?&gt;</code></p>
<p>Once we have $ip_num we can create our MySQL query:<br />
<code>$qry = "SELECT '' FROM ch_ip WHERE $ip_num BETWEEN start AND end";</code></p>
<p>All we need to know is whether the query returns &gt; 0 rows. If it does, then the visitor is Swiss and we&#8217;ll set their locale appropriately. Obviously we don&#8217;t want to be performing this query on every page, so once it has been performed once for the visitor we&#8217;ll set a session variable. So the final code looks like this:<br />
<code>&lt;?php<br />
session_start();<br />
if (!session_is_registered("locale")) { //check if the session variable has already been set first<br />
$con = mysql_connect('localhost', 'geo_user', 'geo_password');<br />
if ($con) {<br />
$ip_num = sprintf("%u", ip2long($_SERVER['REMOTE_ADDR']));<br />
mysql_select_db("geo_ip", $con);<br />
$result = mysql_query( "SELECT '' FROM ch_ip WHERE $ip_num BETWEEN start AND end" );<br />
$num_rows = mysql_num_rows($result);</p>
<p>if ($num_rows &gt; 0) {<br />
$_SESSION['locale'] = "ch";<br />
}<br />
else { $_SESSION['locale'] = "de"; }<br />
}<br />
else { $_SESSION['locale'] = "de"; //If no db connection can be made then set their locale to German }<br />
}<br />
?&gt;</code></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=BREUId9hgAA:MzDgR6QXb5E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=BREUId9hgAA:MzDgR6QXb5E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=BREUId9hgAA:MzDgR6QXb5E:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/BREUId9hgAA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/detect-visitors-country-with-php-mysql/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/detect-visitors-country-with-php-mysql/</feedburner:origLink></item>
		<item>
		<title>mysqlslap for MySQL 5.0</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/QCH8eDutkV8/</link>
		<comments>http://www.jameslittle.me.uk/mysqlslap-for-mysql-50/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 07:18:13 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysqlslap]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/mysqlslap-for-mysql-50/</guid>
		<description><![CDATA[mysqlslap is a very useful tool for emulating client load, something that would normally be very difficult in the real world (until you go live!). The binary is bundled into the MySQL 5.1 releases (still at Release Candidate stage) but not 5.0, so the only option is to compile from 5.1 source and then you [...]]]></description>
			<content:encoded><![CDATA[<p>mysqlslap is a very useful tool for emulating client load, something that would normally be very difficult in the real world (until you go live!). The binary is bundled into the MySQL 5.1 releases (still at Release Candidate stage) but not 5.0, so the only option is to compile from 5.1 source and then you can use it with your 5.0 server installation.</p>
<p>Fortunately when compiling you can save some time by configuring with the <code>--without-server</code> option, which will compile just the client tools (mysqldump, mysqlbinlog, mysql CLI, etc.). The following worked for me on an installation of CentOS5 64-bit, on the same machine that runs my 5.0 server.</p>
<p>1. Download the MySQL 5.1 source code in compressed tar format (.tar.gz). Go to the <a href="http://dev.mysql.com/downloads/mysql/5.1.html#source">download page</a>, or do a wget (in my case from the Mirror Service from the University of Kent, UK). Version  5.1.23-rc was current at the time of writing:<br />
<code>wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.23-rc.tar.gz/from/http://www.mirrorservice.org/sites/ftp.mysql.com/</code></p>
<p>2. Unpack the archive:<br />
<code>tar -xvvzf mysql-5.1.23-rc.tar.gz</code></p>
<p>3. Install required development packages and compile:<br />
<code>cd mysql-5.1.23-rc<br />
yum install glibc gcc libtool ncurses-devel gcc-c++<br />
./configure --without-server --disable-shared<br />
make<br />
make install</code></p>
<p>The &#8216;make&#8217; stage will take some time. Why configure with <code>--disable-shared</code>? I wanted my binary to be portable so I could share amongst a group of similar-spec machines, and I can&#8217;t be sure that the shared libraries are all in the same location. See the <a href="http://dev.mysql.com/doc/refman/5.1/en/configure-options.html" target="_blank">MySQL Installation pages</a> for more details on configuration options; you may want to make use of <code>--libdir=...</code> instead.</p>
<p>4. Copy/move the mysqlslap binary (it will be in /usr/local/bin  by default) to wherever the rest of your v5.0 client binaries are. For example:<br />
<code>cp /usr/local/bin/mysqlslap  /usr/local/mysql/bin/mysqlslap</code><br />
5. Test it out! Run something like:<br />
<code>./mysqlslap --user=root --auto-generate-sql --concurrency=100 --iterations=5</code><br />
as a quick test, and check out the <a href="http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html" target="_blank">MySQL Documentation</a> for a more detailed use-guide.</p>
<p>Since compiling I have thrown the binary around various other Intel machines (and VMs) running CentOS, without any problems.<span id="more-21"></span><!--more--></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=QCH8eDutkV8:iC1eoYW5qHI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=QCH8eDutkV8:iC1eoYW5qHI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=QCH8eDutkV8:iC1eoYW5qHI:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/QCH8eDutkV8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/mysqlslap-for-mysql-50/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/mysqlslap-for-mysql-50/</feedburner:origLink></item>
		<item>
		<title>mprime for Mac</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/m2ykMLWZt7c/</link>
		<comments>http://www.jameslittle.me.uk/mprime-for-mac/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 13:50:04 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[number theory]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/mprime-for-mac/</guid>
		<description><![CDATA[For those of you that don&#8217;t know what a Mersenne Prime is (most people I suspect), it&#8217;s a prime number of the form 2^n -1 where n is a natural number. The largest known prime number, 2^32,582,657 -1 is a Mersenne prime.  Many, no doubt fascinating individuals (like me for example) like the idea [...]]]></description>
			<content:encoded><![CDATA[<p>For those of you that don&#8217;t know what a Mersenne Prime is (most people I suspect), it&#8217;s a prime number of the form 2^n -1 where n is a <a href="http://en.wikipedia.org/wiki/Natural_number" target="_blank">natural number</a>. The largest known prime number, 2^32,582,657 -1 is a Mersenne prime.  Many, no doubt fascinating individuals (like me for example) like the idea of finding the first prime number that is &gt; 10 million digits long because 1) there&#8217;s a $100,000 reward and 2) because it would be cool (sort of). Check out <a href="http://www.mersenne.org/" target="_blank">GIMPS</a> and <a href="http://en.wikipedia.org/wiki/Mersenne_prime" target="_blank">Wikipedia</a> for more info.</p>
<p>I searched around for ages for a version of mprime (highly optimized software used to search for Mersenne Primes) compiled for Intel Macs and didn&#8217;t have much luck; for some reason it doesn&#8217;t seem to be linked from the GIMPS website. Eventually I found a random link to <a href="http://www.mersenne.org/gimps" target="_blank">this page</a> which contains all the software downloads. So if you want to contribute to the worldwide distributed search and you use a Mac, please download it. And you never know, you might get lucky!</p>
<p><em> For those of you that couldn&#8217;t care less about Mersenne primes (most people I suspect), but want to do some stress testing/benchmarking  on their Mac, mprime is a very useful tool. Overclockers of the Windows variety will be familiar with the Prime95 app, a Windows GUI version of mprime. </em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=m2ykMLWZt7c:G__y75uHoZs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=m2ykMLWZt7c:G__y75uHoZs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=m2ykMLWZt7c:G__y75uHoZs:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/m2ykMLWZt7c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/mprime-for-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/mprime-for-mac/</feedburner:origLink></item>
		<item>
		<title>Installing CentOS 5 on a Dell R200</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/T3vXP7CrN5Y/</link>
		<comments>http://www.jameslittle.me.uk/installing-centos-5-on-a-dell-r200/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 11:51:38 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[dell]]></category>
		<category><![CDATA[drivers]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/installing-centos-5-on-a-dell-r200/</guid>
		<description><![CDATA[This is the latest value rackmount offering from Dell. It&#8217;s a great spec for the price,  but installation of CentOS 5 seems surprisingly difficult, thanks to the SATA DVD drive used in the unit. RHEL/CentOS doesn&#8217;t have the driver for the controller so can&#8217;t find the DVD during installation. I&#8217;m sure there are other [...]]]></description>
			<content:encoded><![CDATA[<p>This is the latest value rackmount offering from Dell. It&#8217;s a great spec for the price,  but installation of CentOS 5 seems surprisingly difficult, thanks to the SATA DVD drive used in the unit. RHEL/CentOS doesn&#8217;t have the driver for the controller so can&#8217;t find the DVD during installation. I&#8217;m sure there are other workarounds (network install, USB DVD drive etc.), but eventually I got hold of a Redhat driver disk from Dell Support (it doesn&#8217;t seem to be on the Dell site btw).</p>
<p>I&#8217;ve uploaded the disk image <a href="http://www.jameslittle.me.uk/wp-content/uploads/2008/02/ata_piix-2001dell-manykernels-ddimg.gz">here</a>; just uncompress it and <strong>copy the .img file</strong> onto a USB key. At the installation command-prompt type &#8216;linux dd&#8217; and then hit Enter. You&#8217;ll then be asked for the location of the driver disk image; just navigate to the USB disk, select the image, and you&#8217;re in business.</p>
<p><a title="SATA driver disk" href="http://www.jameslittle.me.uk/wp-content/uploads/2008/02/ata_piix-2001dell-manykernels-ddimg.gz">SATA driver disk<br />
<a href="http://www.jameslittle.me.uk/wp-content/uploads/2008/02/ata_piix-2001dell-manykernels-ddimg.zip">.</a></a><a href="http://www.jameslittle.me.uk/wp-content/uploads/2008/02/ata_piix-2001dell-manykernels-ddimg.zip">zip version</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=T3vXP7CrN5Y:zb6qmuVrSzc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=T3vXP7CrN5Y:zb6qmuVrSzc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=T3vXP7CrN5Y:zb6qmuVrSzc:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/T3vXP7CrN5Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/installing-centos-5-on-a-dell-r200/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/installing-centos-5-on-a-dell-r200/</feedburner:origLink></item>
		<item>
		<title>How to Access MySQL with an SSH Tunnel</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/bxBO3vQs1X4/</link>
		<comments>http://www.jameslittle.me.uk/how-to-access-mysql-with-an-ssh-tunnel/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 14:18:24 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.jameslittle.me.uk/how-to-access-mysql-with-an-ssh-tunnel/</guid>
		<description><![CDATA[This is a particularly useful method for gaining access to your remote MySQL databases, such as those held on a  web hosting account where the MySQL port may not be open. You can use this method to gain access to other services too (SMTP, IMAP, FTP), but in this post I&#8217;ll explain how I [...]]]></description>
			<content:encoded><![CDATA[<p>This is a particularly useful method for gaining access to your remote MySQL databases, such as those held on a  web hosting account where the MySQL port may not be open. You can use this method to gain access to other services too (SMTP, IMAP, FTP), but in this post I&#8217;ll explain how I use it in combination with <a href="http://www.mysql.com/products/tools/query-browser/" target="_blank">MySQL Query Browser</a> to administrate my DBs with a GUI. You need to have SSH access to your remote server (normally over port 22) for this to work. My instructions are for Ubuntu but it&#8217;s easily transferred to other distros, Mac OS X, and Windows (just download an SSH client).</p>
<p>Run <code>sudo apt-get install ssh</code> if it isn&#8217;t installed already, which will install several SSH connectivity tools (more info <a href="http://www.openssh.com/" target="_blank">here</a>). Query Browser is an excellent tool with which to run queries, updates, create views and stored procedures, and loads more besides. Run <code>sudo apt-get install mysql-query-browser</code>. Now to create the SSH tunnel by using port forwarding; here&#8217;s how I access a MySQL instance on my local network:<br />
<code>james@james-laptop:~$ ssh -L 3307:localhost:3306 root@192.168.1.211<br />
root@192.168.1.211's password:</code></p>
<p>Essentially this forwards all traffic on port 3307 on the local machine (james-laptop) to port 3306 on 192.168.1.211. The general format is <code><br />
ssh -L localport:host:hostport</code>. Note that in my example I used localhost, but this is resolved after the connection has been made to 192.168.1.211 and so it refers to that IP address.</p>
<p>Effectively we can now access port 3306 (the default MySQL port) on 192.168.1.211 via port 3307 on james-laptop even though port 22 (the SSH port) is the only port open on 192.168.1.211. Keep the connection open (i.e. don&#8217;t close the terminal) and open Query Browser. In the connection dialogue set the hostname to 127.0.0.1 and the port to 3307 and enter a username/password as required. Hit connect and you should see a graphical representation of your database(s). Note that in *nix OSs (including Mac OS X) you must use 127.0.0.1 rather than &#8216;localhost&#8217; or the connection will be made via a named pipe rather than TCP.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=bxBO3vQs1X4:bXbJ6Z0xCAw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=bxBO3vQs1X4:bXbJ6Z0xCAw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=bxBO3vQs1X4:bXbJ6Z0xCAw:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/bxBO3vQs1X4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/how-to-access-mysql-with-an-ssh-tunnel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/how-to-access-mysql-with-an-ssh-tunnel/</feedburner:origLink></item>
		<item>
		<title>Installing Ubuntu Feisty on Santa Rosa</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/kcHEDozjl68/</link>
		<comments>http://www.jameslittle.me.uk/installing-ubuntu-feisty-on-santa-rosa/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 13:40:42 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://james.local/installing-ubuntu-feisty-on-santa-rosa/</guid>
		<description><![CDATA[If you&#8217;ve recently bought a laptop with an Intel Core 2 Duo CPU, the chances are it&#8217;s running on the Santa Rosa platform. Having wiped off the unfortunate Windows installation, you&#8217;ll want to install some flavour of linux, such as Ubuntu Feisty. Unfortunately the installation process is not as smooth as you might as expect. [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve recently bought a laptop with an Intel Core 2 Duo CPU, the chances are it&#8217;s running on the Santa Rosa platform. Having wiped off the unfortunate Windows installation, you&#8217;ll want to install some flavour of linux, such as Ubuntu Feisty. Unfortunately the installation process is not as smooth as you might as expect. In fact, it prooved so troublesome for me that in the end I decided that upgrading to Gutsy would be a better idea. But first I&#8217;ll talk you through how you can go about getting Feisty installed:</p>
<p>When booting from the Feisty Live CD, the first problem you&#8217;ll encounter will probably be something like:<br />
<code>/bin/sh: can't access tty: job control turned off<br />
(initramfs)</code></p>
<p>and the OS will not continue to load. I&#8217;m not sure on the cause of this, but to get round it hit F6 at the boot menu and append break=top to the list of options. You should then see a slightly different error message, and underneath it you should type:<br />
<code>modprobe piix<br />
exit</code></p>
<p>The LiveCD should then continue to load the OS. After a minute or so you&#8217;ll probably see a lovely blue screen with a &#8220;Failed to start the X server&#8230;&#8221; error message. Hit Yes or No (whatever you fancy) and you&#8217;ll be dumped at the command line where you should type:<br />
<code>sudo dpkg-reconfigure  xserver-xorg</code></p>
<p>Remember the sudo bit or you&#8217;ll be reminded that you are not a superuser; no password is required. The Xorg configuration screen will appear and you&#8217;ll be asked (a lot) of questions. Keep the driver on &#8220;vesa&#8221; and continue through the questions, providing the default answers. At the bit where it asks you something about monitor config options and gives you the choice of &#8220;Simple&#8221;, &#8220;Medium&#8221; and &#8220;Advanced&#8221; I hit Medium and continued through. The vesa driver might not support your resolution if you have a widescreen aspect ratio (1280&#215;800, 1440&#215;900, etc.). Don&#8217;t worry about this for now and continue. Eventually you&#8217;ll be dumped back to the command line. Now type:<br />
<code>sudo /etc/init.d/gdm restart</code><br />
and the Gnome desktop environment should start to load.  From here you can perform your installation as required.</p>
<p>When you boot Feisty for the first time you&#8217;ll notice some more problems, such as the lack of an Intel graphics driver if your laptop uses the onboard Intel GMA965 chip, and non-functional sound &amp; wireless. For me it was the lack of graphics driver that prompted me to upgrade to Gutsy, since the solution for Feisty involved upgrading the kernel to 2.6.22 anyway, which is the kernel version used in Gutsy (see <a href="http://ubuntuforums.org/showthread.php?t=494943" target="_blank">http://ubuntuforums.org/showthread.php?t=494943</a> for more info). At the time of writing, Gutsy Tribe 5 has just been released and it seems to be stable. You can save yourself a lot of hassle where Santa Rosa is concerned by <a href="http://www.ubuntu.com/testing" title="Download Ubuntu Gutsy" target="_blank">downloading the tribe 5 live CD</a> which boots with no problems whatsoever for me, including desktop effects, wireless (my laptop has the 4965AGN chip) and sound. If you&#8217;ve already installed feisty you can upgrade to Gutsy by running &#8220;update-manager -d&#8221;.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=kcHEDozjl68:G38onRx2Yrk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=kcHEDozjl68:G38onRx2Yrk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=kcHEDozjl68:G38onRx2Yrk:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/kcHEDozjl68" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/installing-ubuntu-feisty-on-santa-rosa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/installing-ubuntu-feisty-on-santa-rosa/</feedburner:origLink></item>
		<item>
		<title>How to Mount VMDK files in Linux</title>
		<link>http://feedproxy.google.com/~r/james-little/~3/p_WNrjTf2f0/</link>
		<comments>http://www.jameslittle.me.uk/how-to-mount-vmdk-files-in-linux/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 13:31:06 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[filesystems]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://james.local/how-to-mount-vmdk-files-in-linux/</guid>
		<description><![CDATA[There&#8217;s various tools for Windows that allow you to mount VMware images, which offers a convenient way to transfer files to/from the Virtual Machine. The solution in linux seems to be a little less well-known, but it is effectve nonetheless, and I find it preferable to using SSH/FTP/NFS etc. to transfer files.
First you&#8217;ll need to [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s various tools for Windows that allow you to mount VMware images, which offers a convenient way to transfer files to/from the Virtual Machine. The solution in linux seems to be a little less well-known, but it is effectve nonetheless, and I find it preferable to using SSH/FTP/NFS etc. to transfer files.</p>
<p>First you&#8217;ll need to <a href="http://www.vmware.com/download/server/" target="_blank">download a copy of VMware server</a>, which is free. You may be using VMware player to run your virtual machines, but unfortunately it doesn&#8217;t include the tool needed to mount VMware images. It&#8217;s not a major problem though; just unpack the VMware server archive you just downloaded and copy the files &#8220;vmware-mount.pl&#8221; and &#8220;vmware-loop&#8221; from its &#8220;bin&#8221; directory to your <code>/usr/bin</code> directory (or whatever directory you have VMware Player installed). There&#8217;s no need to install VMware Server if you already have Player. If you have neither installed then obviously you will need to install one of them. Now navigate to that installation directory and follow my lead:</p>
<p><code>jim@jim-desktop:/usr/bin$ ./vmware-mount.pl</code></p>
<p><code>This script requires 3 (not 0) mandatory argument(s).</code></p>
<p><code>Usage: ./vmware-mount.pl<br />
-p          : Print the partition table<br />
disk        : Name of the Virtual Hard Disk file<br />
or<br />
disk        : Name of the Virtual Hard Disk file<br />
partition   : Number of the partition<br />
[-t type]   : Partition type<br />
[-o options]: Partition mount options(s)<br />
mount-point : Directory where to mount the partition</code></p>
<p>Here we see the usage instructions for the vmware-mount script. I&#8217;ll run with the &#8216;-p&#8217; option so I can see the partition structure of my image:</p>
<p><code>root@jim-desktop:/usr/bin# ./vmware-mount.pl -p /home/jim/'My Virtual Machines'/windows.vmdk'</code></p>
<p><code>--------------------------------------------<br />
VMware for Linux - Virtual Hard Disk Mounter<br />
Version: 1.0 build-44356<br />
Copyright 1998 VMware, Inc.  All rights reserved. -- VMware Confidential<br />
--------------------------------------------</code></p>
<p><code>Nr      Start       Size Type Id Sytem</code><br />
<code>-- ---------- ---------- ---- -- ------------------------</code><br />
<code>1         63    2097088 BIOS  6 FAT16</code></p>
<p>That tells me that the partition number I&#8217;ll need is 1, and it&#8217;s the only partition available. So to mount the image I run the following:</p>
<p><code>root@jim-desktop:/usr/bin# mkdir /media/vmware-image<br />
root@jim-desktop:/usr/bin# ./vmware-mount.pl /home/jim/'My Virtual Machines'/windows.vmdk 1 /media/vmware-image</code></p>
<p>The script warns you about untested support for kernels &gt; 2.4 and has a whinge about network block devices, but type &#8216;Y&#8217; on both counts to continue and the image will mount to your specified location (in this case, /media/vmware-image). You can now open another terminal window and explore the image. In Ubuntu w/ Gnome I&#8217;m able navigate via Nautilus, and it even creates a nice image on the desktop for me. You may find additional switches such as &#8220;-o ro&#8221; to make the image read-only will come in handy.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/james-little?a=p_WNrjTf2f0:t22ysQEEyiM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/james-little?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/james-little?a=p_WNrjTf2f0:t22ysQEEyiM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/james-little?i=p_WNrjTf2f0:t22ysQEEyiM:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/james-little/~4/p_WNrjTf2f0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jameslittle.me.uk/how-to-mount-vmdk-files-in-linux/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.jameslittle.me.uk/how-to-mount-vmdk-files-in-linux/</feedburner:origLink></item>
	</channel>
</rss>
