Building a local Ubuntu server – Part 1: The hardware

My home network server: mother

In this post, I’ll talk about how I built my new home network server, “mother” (you know, like the main computer on the Nostromo in the original Alien movie).

The picture below shows the top of the bureau where I have my “server stuff”. From left to right: The Samsung SCX-3405W printer, the ZyXEL router (behind the lamp), the Nespresso U Black coffee machine (what can I say – I cannot be bothered to walk all the way to the kitchen when I’m sitting by the computer), the Western Digital MyCloud 2TB NAS, and my brand new orange and black server.

My new server (orange and black) and some other stuff.

My first multi-page post

This happens to be my first multi-page blog post. Splitting a post into more than one page turned out to be simple in WordPress, but I had some problems with getting the page navigation to work as I wanted. I spent quite a few hours on that before I gave up on using the built-in navigation functions and implemented my own page navigation “bar”. I guess I’ll make a separate post about that later…


IMAX Mini. Not the same model as mine, but similar enough.

IMAX Mini. Not the same model as mine, but similar enough.

I recently decided that it was time to set up a server on my home network. There are several reasons, but the main one is that it would make my web development work easier. Initially, I just wanted to try out the concept of having a server, so I dug up my old Packard Bell IMAX Mini N3600 from the cupboard to try it on.

It was relatively simple to install and set up Ubuntu Server on it, and since then it has been standing on the top of a bookshelf, doing its thing. The only cable connected to it is the power cord. There is no monitor, mouse or keyboard attached (I use SSH to administer it over the network from another computer), and I use its built-in WiFi to connect it to the network.

Sounds good, right? So whats the problem? Well, simply put: Lack of processing power and speed.

The IMAX Mini is not intended for doing any heavy lifting. I don’t remember when I bought it, but must have been 2010 or earlier, and it wasn’t exactly a high performer then either. It has an Intel Atom 230 CPU, 2GB (DDR2) RAM, and what appears to be the slowest mechanical hard drive in the known universe, so I didn’t expect it to last long as a server. In fact, I had already made a list of components for its replacement, and was pretty much ready to send an order – I just hadn’t gotten around to it yet – when the IMAX Mini decided that it’d had enough and committed suicide. Nah, that’s not quite true, is it? It was me. Is Computer-slaughter a word?

Anyway, that was yesterday afternoon, and I quickly realized just how dependent I had become of having a (working) server on the network in just the week or two I’d had it. So I spent a couple of hours revising my component list against what they had in stock at the only local computer store (which luckily is open on Sundays) and today I was there right after they opened at noon with my purchase list.

I felt rather lucky getting all of the components on the list since all of them, except for the hard drives, where listed as having just one item left in stock. In fact, while I was waiting by the counter for the guy who ran off to pick up my stuff, I overheard the customer at the next counter trying to buy “the cheapest internal DVD writer”, and the cashier replying that he was in luck – they had a single one left. The customer was happy for about three seconds before I said that I was pretty sure that “my” cashier was out fetching that writer for me. Turned out I was right.

AJAX example: The phone-book

Programming with BosseThis example was supposed to be included in the previous post, How to use AJAX with JSON and without jQuery, but that post just kept growing, to the point where it got to long be manageable. So what you see here is just the phone-book example that I mentioned in that post.

We will create a simple phone-book web application, consisting of a phone-book database in the form of a JSON file, an HTML web page where you search for people in the database, and a server-side PHP script that responds to the AJAX requests from the JavaScript code in the HTML page.

Please remember that this is about learning how to use AJAX – not about creating a good phone-book. This is a very simple application; The database file contains 50 made-up persons, and there is no functionality for editing the database – you can only search what is already there. That’s the only functionality of the application: searching the database.

The HTML page has a text-box where you type letters. Every time that the contents of that box changes, the associated JavaScript code will send an AJAX request to the server, requesting a list of matching names from the phone-book database. Both first and last names are checked, so if you for example enter “br”, it will match first names like Brad and Bryan, but also last names like Brogden and Breed. The list of matching names will be displayed in a list-box, and clicking on a name there will generate a new AJAX request to get the person’s phone number.

If you don’t feel like implementing the example yourself, you can still try it out on my web site through this link.

If you do want to implement the example yourself, it’s as easy as copying all three files below to the same directory on a web server.

The application components

The application components all reside on the web server, and the only one that you will access directly is phonebook.html, which is the HTML document that you will open in your web browser.

Then there is the PHP script phonebook_connector.php. You can open this directly in your web browser, but that would be pointless. This script is listening for AJAX requests on JSON format, and navigating to it through your browser will just get you a pages with two square brackets, “[]“. If you know a little about the JSON format, you might recognize this as representing an empty JSON array, and that is what the script gives you when you don’t ask for anything in particular.

And finally there is the phone-book database file, people.json.

I have placed the description of each of the three components on a separate page below.

How to use AJAX with JSON and without jQuery

Programming with BosseI’d like to begin by explaining the “without jQuery” part of the title; jQuery is a really neat JavaScript library. It very useful, for example when using AJAX, and very, very common. So why not use it here, then? Well, I have two major problems with jQuery: 1) I am a programmer who actually enjoys programming, and I want to learn and get good at the programming languages that I use. Using the “macro” shortcuts that jQuery provides instead of actually writing a (JavaScript) program to do the job doesn’t really work for me. And, 2) for different reasons, I cannot use jQuery at work.

AJAX is a method and set of techniques for creating asynchronous web applications. Sounds a bit vague, you say? Well, it’s difficult to explain in just a few words. Let’s try it this way; Consider the “levels” of web pages that you might visit daily:

  • A static web page doesn’t change unless someone alters the source for it. This is typically a “pure” HTML document.
  • The contents of a dynamic web page is determined when the document is requested from (and generated by) the web server. This can, for example, be done using specialized languages like PHP or ASP, or by practically any language through CGI (Common Gateway Interface).

In both cases, once the web page has been loaded to the viewer’s web browser, it doesn’t change (though it can contain client-side code to, for example, let the viewer hide or show different sections of the page). If you want to create a web page where the contents can actually change without forcing the web browser to reload the document from the server, you will need to use a technique like AJAX to do it.

Still vague? OK, an example then – one that you probably use many times a day; Google Search (or whatever flavor of search engine you prefer – I like Google myself).

When you start typing characters in the Google Search text field, a drop-down list will appear below the text field to display the five(-ish) most likely ways to complete the search criteria you have started to type. Have you thought about where this information comes from? Has your web browser downloaded the absolutely massive database from the Google servers? Of course not. As you keep typing, the web page continually uses AJAX queries to send the current text to the Google search engine, which returns the list of suitable “completions” to display.

I started this blog post with the intention of including a working example of using AJAX in a similar way as above to search entries in a phone-book database. However, as the post grew, I had more and more problems with editing it, so finally I lifted the example to a separate entry: AJAX example: The phone-book

How it works

AJAX stands for “Asynchronous JavaScript and XML”, though that description is not entirely accurate.

Asynchronous” requests (which here means to send the request and use an event handler to take care of the response whenever you get it, instead of freezing the application while waiting for the response) makes sense in a web application where you don’t know how long it will take to get the response, but you are not forced to do it that way. It can be very frustrating for a user when a delayed response suddenly updates (for example) a list of data that he is currently trying to select an item in. My AJAX applications typically use a mix of synchronous and asynchronous requests, depending on the task to be performed.

XML” refers to the format of the data passed between the server and client (the web browser). Using XML is usually a good choice, but you don’t need to do that either. I prefer to use the JSON (JavaScript Object Notation) format in most cases, so that is what we’ll do here.

To initiate an AJAX request, you first create (from JavaScript in the client) an XML HTTP object. You specify things like whether you want the request to be synchronous or asynchronous, whether it should use the GET or POST method, the URL to send the request to, etc, and then you invoke its Send method.

If the request is synchronous, you will get the response directly from the Send invocation (or to be more precise, the Send invocation will not return until the response have been received from the server). If the request is asynchronous, the Send invocation will return immediately, and the response (and any status updates) will trigger events that are handled by the event handler that you specified when creating the request object.

The components of an AJAX application

I feel that I should repeat that you don’t need to use JSON for both request and response data (or at all). The way I see it though, this is a solution that will work for virtually any task, and it is really no more complicated than, say, using the GET method and just pass a parameter string. So I’ll keep promoting the JSON way.

Client side JavaScript

In the sub sections below, we use the XMLHttpRequest class to instantiate the XML HTTP object that we need to perform the AJAX request. This works with all common web browsers except MSIE browsers older than version 7. If you want to make sure that your JavaScript works for older MSIE browsers, you can do something like this:

About using JSON in JavaScript: We will be using the stringify and parse methods of the common JSON class to encode and decode the JSON data. There is a potential problem here in that the JSON class may not be available in older web browsers.

To make sure that the JavaScript code will work on any browser, you can for example use json2.js. This JavaScript will add a JSON class with stringify and parse methods if it does not already exist. You can download it and put it on your website, but it’s simpler to just link to it on a CDN (Content Delevery Network), for example cdnjs, by adding a line like this in the HEAD section of your HTML code:

An asynchronous request

An asynchronous request means that when you send the request, you also assign an event handler to it for the readyStateChange event. Your JavaScript code can then continue to do other stuff while the server processes the request, and when the server sends the response, it will invoke your event handler.

Create the XML HTML object to use for the request:

Now attach the event handler function, here named myAjaxResponseHandler, that you have created (see further down).

We want to pass the XML HTTP request object to the event handler as a parameter rather than declaring it as a global variable, mainly because a global variable could only be used for one request at a time – this way we are not limited in how many simultaneous requests we might want to juggle. Passing parameters to an event handler is however a bit tricky in JavaScript, so we end up with this rather un-intuitive piece of code. What we do is to attach an anonymous function to the event, which in turn will invoke our own event handler and pass it the request object (httpRegObj) as parameter. The e parameter is the event object itself.

The reason that I use the call method above instead of invoking myAjaxResponseHandler directly, is that this piece of code is typically inside a generic “send-an-AJAX-request” function, and what I here called myAjaxResponseHandler is not the actual event handler function, but rather the name of the parameter through which the event handler is passed to this function.

Open the request. “POST” is the method that we want to use, <<url>> should be replaced with the URL of the PHP script (or similar) that the request is to be sent to, and “true” means that this will be an asynchronous request (false would make it synchronous).

Assign a header that indicates that we will be sending data on JSON format with the request.

And finally, send the request by invoking the Send method. The parameter to the Send method should be the request data encoded as JSON string. The invocation below assumes that the requestData variable is something that can be encoded to a JSON string, so I included an example assignment (a simple JSON object) for clarification.

Earlier, we added a handler for the readyStateChange event of the request. This is what the frame for that function could look like:

You might have noticed that this function only takes a single parameter, while the invocation of it from the anonymous function that we attached as event handler earlier sends two parameters. That’s because the first of those parameters was the event object itself, and within this function that object can be accessed directly as this (if you should need it).

The event that will invoke this function is the readyStateChange event. readyState is also an attribute of the request object, meaning that in the function, we can examine it as httpReq.readyState. This integer attribute will typically change through the whole sequence of 0 to 4, and this function will be called on each change:

  1. Request not initialized.
  2. Request has been set up.
  3. Request has been sent.
  4. Request is being processed.
  5. Request is complete.

Though you might want to use the other states for updating a status field or something, typically you will only be interested in handling the final state, 4, which is when you will get the results.

The second attribute that we look at in the function, httpReq.status, is an integer attribute. Note that this is only defined when the request is completed, that is when httpReq.readyState is 4. Status 200 means that the request was successful and that the result is available, so when we have seen that this is the case, we can decode the returned JSON data with:

And that is the end of the AJAX request. Now you just have to deal with the data that you got from the server.

A synchronous request

A synchronous request is where the JavaScript code will “freeze” until it has received the final response from the server.

What you need do here is pretty much the same as for the asynchronous request described in the previous section – the difference being that there is no need for an event handler. So I’ll just condense it into a short example snippet – see above for additional explanations.

Note that the third parameter to the open method above is false (true for asynchronous requests). Also, testing for readyState == 4 is probably not necessary for a synchronous request, but better to be safe than sorry.

Server side PHP

We are POSTing our requests from the client as JSON data, which means that in the PHP script that receives the requests, the JSON data will be encoded in the global variable $HTTP_RAW_POST_DATA. To decode the JSON data into the $req_data variable (or whatever you want to call it) as “mixed” PHP format, we can do this:

Setting the second parameter to json_decode() to true as above, means that any JSON objects in the data will be decoded as associative arrays (a set of key/value pairs) instead of actual PHP objects.

For example the “dummy” JSON data that I used for the requests in the two previous sections was a single JSON object (denoted by the curly brackets) containing a single JSON pair with the key cmd and the value “do something”:

When the server receives this data and decodes it using the code line above, the JSON object will turned into an associative array with one element that you can access like this (for example):

The response data for the request will be the “document” generated by the PHP script, meaning that anything you want to return to the caller should just be echo:ed from code. Remember that our client expects the response to be a JSON string, so anything that you echo from the script will need to be JSON encoded.

I prefer to do this by having just one single echo statement in the whole script, and that is on the very last line of the script:

$response_arr is a global array that I usually create on the first line of the script, and everything that should be returned from the script is added to that array:

Above, I create the array and initializes it to indicate an unspecified error. Later on, the status and message fields can and will be updated to indicate success or possibly a more specific failure. Like:


And that is all there is to it.

Sharing a CDROM over the network with Ubuntu 14.04

My home network server: mother

My home network server: mother

It’s been a couple of years since any of my computers at home had an internal CDROM (or optical drive, or DVD reader/writer, or what you want to call it – I’m old so I allow myself to keep calling it a CDROM). I’ve used an external USB-connected CDROM instead, but when I recently built my new home network server, “mother”, I decided to fit it with an internal CDROM that I could share to the other computers on the network.

Yesterday, I finally got around to setting up the share, and that turned out to be a bit trickier than I had anticipated. Not that it’s difficult once you learn how to do it, but the help that I found on the Internet wasn’t really much help at all to me. At least it gave me enough clues to keep searching, and eventually I got it to work. So I thought that I should share what I learned.

The basics

There are different ways to share a CDROM from Linux. You can for example use NFS or SMB to share the file contents of an inserted disk, but we will use NBD (Network Block Device) to share the CDROM device itself.

To be able to use NBD, we will install the NBD server package (nbd-server) on the computer exporting the physical CDROM, and the NBD client package (nbd-client) on any computer that wants to access the remote CDROM.

The device name of my physical CDROM is /dev/cdrom. I suppose there is a chance that yours is something else, so you might want to check that (and adjust the instructions below accordingly).

About access rights to the CDROM; If you look at the device file /dev/cdrom, you will see that everyone has read and write access to it. But if you look closer, you’ll see that this is just a link to the actual CDROM device file (/dev/sr0 in my case), which has a much stricter access list. More specifically, only the root user and the cdrom group can even read it. This is why we change the group parameter for the NBD server to cdrom, and let the nbd user join the cdrom group (see the next section).

On the computer with the physical CDROM

First we need to install the NBD server package:

sudo apt-get install nbd-server

You will get a warning about that the NBD server is quitting since there are no configured exports. Don’t worry about it – we’ll fix that soon.

The NBD server will by default run as the user nbd which was created automatically when you installed the package above. However, nbd does not currently have access to the CDROM device – only the root user and the cdrom user group have that. We don’t want to change the access list for the CDROM, and we don’t want the NBD server to run as root. Instead we will let nbd join the cdrom group. Use the adduser utility to do that:

sudo adduser nbd cdrom

Now it’s time to configure the NBD server. Open the file /etc/nbd-server/config for editing

sudo nano -Bw /etc/nbd-server/config

There are a couple of things we want to do in this configuration file:

  1. Export the CDROM by adding an export section for it. I want the name of the exported CDROM to be cdrom, so the export section tag will be [cdrom]. The only parameters we’ll set here are exportname (the device name of the CDROM, which is /dev/cdrom on my system), and readonly which we will set to true to avoid warnings (I don’t expect to use the CDROM to write anything, but if you do you should skip this parameter or set it to false).
  2. Above we joined the nbd user to the cdrom group. This allows nbd to use that group’s privileges, but the NBD server will not do that unless we explicitly tell it to. So we will set the group parameter in the [generic] section to the value cdrom.
  3. Optional: If you want to be able to get a list of the exported devices from a client, you need to tell the server to allow that. If so, add a line where you set the allowlist parameter to true.

So – add the following lines (assuming the device name for your CDROM is /dev/cdrom) at the bottom of the file:

Then find (in the [generic] section at the top of the file) the line for the group parameter, and change its value to cdrom. Also, if you want to allow clients to list the available exports from this NBD server, add a line here (it may already exist) setting the allowlist option to true:

Now we’re done fiddling around with the settings, so save the file and then start (or re-start as the case may be) the NBD server:

sudo /etc/init.d/nbd-server restart 

On computers using the exported CDROM

Install the NBD client package:

During the installation, you will be asked what to do when the NBD client is told to stop. Answer “Yes” to the question “Disconnect all NBD devices on stop?” (unless you know what you are doing and are not satisfied with that selection).

Now that the client is installed, we can run an instance of it to import the CDROM device that we just exported from the server. The command below will do that; The first argument (mother in this case) is the hostname (or IP address) of the computer that exports the device. The -name option states that we want to import the device called cdrom, which is the name that we gave the exported CDROM in the previous section. The final argument (/dev/nbd0) is the local NBD device file that we want to use to connect the remote device:

Hopefully, you didn’t get any error messages, and then you can test that the NBD device is mounted:

The response you want to see from the command above is a single number, which will be the PID (Process ID) of the process that connected the device (you have no use for it, just be happy if you see it). If you don’t get any response at all, run this command directly after the one above ($? holds the status code for the previously executed command):

The value should be “0” if all want well, and otherwise “1” (meaning that the device you queried about is not connected or does not exist) or “2” (meaning that an error occurred). If you believe that you performed the steps above correctly and it still didn’t work, go to the server and use the dmsg command to look at the syslog and check for any error messages or warnings related to NBD.

So, now you have a local CDROM (sort of) with the device name /dev/nbd0 (or whichever one of the NBD device file names you used). In the same way as if it was an actual local CDROM, you must now mount it in order to use it. Unless you have already done so, you must first create an empty mount point directory (I chose to mount the CDROM as /mnt/cdrom):

The -t iso9660 option to the mount command tells mount that this is a CDROM. The -r option tells mount to mount the device as read-only.

That’s it. Now you can, for example, list the contents of the disk in the CDROM with:

Don’t forget to dismount the CDROM when you don’t need it anymore, and by then you should also disconnect the remote CDROM device:

Edit: I had missed the -t iso9660 option when mounting the CDROM above. Added it 2014-10-10.

Installing a new drive in Ubuntu Server 14.04

This last weekend I built a new home network server on which I run Ubuntu Server 14.04. There is a long post coming on that (as soon as I’ve cleaned it up and added the pictures), but I’ll start small with this one since I need to link to it from the other post.

Power down the server, install the drive and connect the cables, power the server up again and log on.

Finding the device name of the drive

Ubuntu will detect all the installed drives, and will give each one a device name (or “logical name”). Hard drives (HDDs and SSDs alike) are named with the prefix letters “sd” (which I believe stands for SCSI Device – not that they generally are SCSI devices, but what do I care) followed by a third letter that represents the order in which the device was (originally) detected.

So on my server, the system drive, which was the first hard drive ever detected by the system, has the name sda. Now that I’ve have installed a second hard drive (the data drive as I’ll call it), it will have been named sdb. If I ever install a third hard disk, it will become sdc, and so on.

Guessing the name would of course be silly, so we use the lshw command to make sure:

The output will be a section like the one below for each drive (including any optical drive) on your system. Not that I forgot to keep the output for my new drive before I partitioned and mounted it, so this is the description of the new drive after I had already done that.

Use the output from lshw to find the “logical name” for your new drive (sdb in my case).

Partitioning and formatting the drive

Before you can store any data on a hard drive, it must be partitioned and formatted. Partitioning a drive means splitting it up into one ore more sections (partitions). Each partition must then be formatted, meaning that the partition is prepared for use as a specific file system type (a few example file systems that you may recognize are ext3 or ext4 if you are only going to use it from Linux, or FAT32 or NTFS if you also need to access it from Windows).

If your data drive has already been partitioned and formatted, and you are satisfied with that, then you can just skip to Mounting the drive now. In my case, though, the disk is brand new, and needs to be partitioned before I can use it.

IMPORTANT NOTE: The commands below assume that the new drive has the device name sdb. Make sure to replace that name with the actual device name of your own new drive, since these commands will destroy any existing data on the drive!

I will just make one single, large partition of the whole 1TB drive. If you want something else, you’ll just have to find the information elsewhere. Use the fdisk utility for partitioning the drive, which you access through the device file that represents the drive in the /dev directory:

The drive is now partitioned, and has a single partition on it. This means that the /dev directory now should contain two entries for the drive; /dev/sdb which is the device file representing the physical drive, and /dev/sdb1 which represents the first (and only in this case) partition on that drive.

So when we now format the drive, it is not the drive itself (/dev/sdb) that we want to format, but rather the only partition on the drive, /dev/sdb1.

So what file system should we use for this partition? There are loads to choose from, but with the latest Ubuntu Server version installed, all new hardware, no older software installed to check compatibility for, and the knowledge that this drive will be for internal use only (not shared with any Windows computers over the network and no dual boot with Windows involved), I chose the ext4 file system.

Use the mkfs command to format partition 1 on the drive for the ext4 file system:

The drive is now ready for use, but there is one final thing that I want to do here. By default, the system reserves 5% of the total size of the partition for the super user. This is to ensure that critical operations will not fail due to the disk getting full, and to make sure that there won’t be a problem defragmenting the disk when it’s (close to) full.

For a data disk such as this, that is an unnecessary waste of space (5% of 1TB is 50GB of space on the disk that you will not be able to use). You can use the tune2fs command to adjust the size of the reserved data. The -m option sets the percentage of disk space to reserve (the default is 5% as mentioned above). Below, I set it to 0%, since I don’t want to waste any space at all. You could set it to (for example) 1% if it makes you feel safer, but 5% is much too much for a data drive.

Mounting the drive

So. The drive is now ready for use, but we need to mount it (the formatted partition) before we can access it.

We could mount it using the same handle as above (/dev/sdb1), and would probably never see any problems with it. Not related to that anyway :) However, it is recommended to mount drives using their UUIDs rather than their device names, since the device name (at least in theory) can change between boots – so we’ll do that.

The UUID (Universally Unique Identifier) is guarantied to always point to the same physical device. You can determine the UUID for a device in different ways. I’ll use the blkid command (remember that the device file for the only partition on our new drive is /dev/sdb1):

The output will be similar to this:

As you can see, the UUID is a rather long string of characters. Not something you would like to try to remember, but guaranteed to be unique over time.

I must admit that I still have a bit of a hard time understanding the best place to put stuff in the Ubuntu file hierarchy. There are lots of opinions on the web, but I haven’t (yet) found a good source, though “man hier” gives a lot of good clues. I would, for example, have said that the best place to mount this new drive would be under /mnt, but apparently, the Ubuntu “standard” choice for these things is to mount it under /media. Well, it doesn’t really matter to me, so let’s go with the latter.

To mount a device, we must first have an empty directory to use as mount point. I’ll call the new drive “data1“, so the mount point will be /media/data1:

We don’t want to have to mount this drive manually whenever we need it, so we will add a line for it in the fstab file to have it mounted automatically when the system boots. So, open the fstab file for editing:

Add a line like this in the file (read below it here before saving):

Note that you must replace the UUID value above with what you got from the blkid command earlier, even if your device name is the same as mine (universally unique id – remember?). And the mount point must of course correspond with the directory you just created for it. Also, if you used a different file system than I did (ext4), you need to change that too (check the output from the blkid command above if you are unsure about that).

Save the file and run this command to mount it:

You can now check the drive through /media/data1.

Finally, you need to decide who will have access to the drive and its contents. The command below gives all users full access to the drive, which is the way I want it.

That’s it. Have fun with your new drive :)

Moving my web site (again)

A couple of months back I moved my web site to JustHost, and now I’m moving it again. I actually quite liked JustHost, but I still need to move it for two main reasons: Their web server is annoyingly slow, and they cannot handle domain names in the .eu top domain (meaning I have to use a separate domain registring service just for that domain).

So I have started using GoDaddy, and I’m now in the progress of moving everything on my old site (actually my old sites) there.

I’ve just finished moving the WordPress part of my site, and this short post is mainly a test to see that everything, including the plugin for sharing my posts on Facebook, is still working.

Installing Windows 8.1 and Ubuntu 14.04 on the Lenovo Yoga 2

Ubuntu 14.04 and Windows 8.1When I bought my Lenovo Yoga 2 11, I removed Windows 8.1 and replaced it with Ubuntu Linux 14.04. After a couple of weeks I decided to replace the HDD with an SSD, and in doing so, I also wanted to re-install Windows 8.1 (together with Ubuntu in a dual boot configuration) to use with the Yoga in “pad mode”.

I didn’t find a complete instruction on how to do this (had to search a lot to complete different parts), so I decided to write it all down while doing it in the hope that it might make it easier for someone else.

You can also use this post if you just want to install Ubuntu 14.04 – either together with an already installed Windows 8 or as a replacement to Windows 8. Just skip the irrelevant parts.

Problem with the Internet connection

When you install Windows, the installer will not be able to properly detect the Yoga’s WiFi adapter. So it will not not install the appropriate drivers, meaning that you will not have WiFi during or after installation of Windows until you have fixed this by downloading the correct drivers.

When you install Ubuntu, it contains a broken kernel module for Lenovo laptops, meaning that you will not have WiFi in Ubuntu either. At least not until after the installation when you can fix this as described further down.

The installation of both operating systems, as well as fixing the problems after the installation, will go much smoother if you have an Internet connection from the beginning. So I strongly recommend that you get yourself an Ethernet-to-USB adapter, like this one (since the Yoga 2 11 doesn’t have an RJ45 Ethernet contact).

Both Windows and Ubuntu will be able to use that from the start. All you need to do is to plug the USB contact into the Yoga 2, and a network cable into the RJ45 connector in the adapter.

Alternatively, you can “thether” your mobile phone to the laptop over USB (WiFi doesn’t work, remember? and neither does Bluetooth – at least not on Ubuntu) and use it to connect to Internet. Both Windows and Ubuntu will however want to download quite a lot of stuff, so this option might be both slow and expensive.

You could also get away with downloading what you need from another computer and move it to the Yoga on a USB flash-drive, but for this guide, I will assume that you have the USB-to-Ethernet adapter that I recommend.

What you need

List of stuff:

  • A Windows 8.1 installation DVD.
  • A USB-connected DVD reader, like this one.
  • An empty USB flash-drive. Note that it must be an actual flash drive – not some memory card adapter.
  • An Ethernet-to-USB adapter, like this one.

The DVD reader and the Windows DVD is only for the Windows installation, so if Windows is already installed on your Yoga, you won’t need those.


For the Yoga 2 laptop

Connect the laptop to the power adapter (installing the OS on battery power is not the best idea).

Connect the DVD reader to a USB port on the laptop (if installing Windows).

Connect the USB-to-Ethernet adapter to a network cable, and to the other USB port on the laptop.

Remember that only one of the USB ports on the Yoga 2 11 is a USB 3 port. So if any of the devices above have a USB 3 connector, you might want to use the “right” port for it to gain reading speed.

The “Lenovo button” is the tiny round button next to the power button on the right-hand side of the Yoga 2.

  1. Press the Lenovo button and select BIOS Setup from the menu.
  2. Go to the Security page and see to that Secure Boot is set to Disabled.
  3. Go to the Boot page and see to that USB Boot is set to Enabled.
  4. Save and exit.

Prepare a Live Ubuntu USB to install Ubuntu from

You need to prepare a Ubuntu Live USB to install Ubuntu from. The only trick to this is that the USB needs to be prepared for UEFI boot to work on the Yoga 2. Never mind what that means for now, just follow the simple instructions below.

First you download an Ubuntu 14.04 ISO image. Note that it needs to be a 64-bit version for it to work with UEFI. Just follow this link and select the version you want.

To write the Ubuntu image to a bootable USB flash-drive, you will need a small piece of software called Rufus (assuming that you do this from a Windows PC). I’m sure there are others that work just as fine, but I like Rufus. Download it from here (it’s free).

Insert the USB flash-drive, and then run Rufus and select the Ubuntu ISO image file that you just downloaded as source (“Create a bootable disk using [ISO Image]”). That should set the other Rufus options to the right values, but this is what it should look like:

Settings for Rufus

Settings for Rufus

Click Start and wait until it’s done. It will take a couple of minutes.

Install Windows

Obviously, you can skip this section if you already have Windows installed on the Yoga.

Note 1: If the hard drive in the laptop is empty (for example if you are now installing the OS because you replaced the HDD with an SSD), you will probably get the message “No Bootable Device. Hit any key.” at some point(s) during this process. If that’s not obvious by itself, just do as it says and press any key to continue (though in this case you actually need to press the Enter key – other keys do nothing here).

Note 2: When starting up the laptop with a bootable CD/DVD in the reader, you will sometimes (randomly it seems) get to the Boot Selection menu instead of just getting the “Press any key to boot from CD or DVD” message. If that happens, just select the DVD reader from the menu and continue from there.

Note 3: I’m going to assume that the hard drive is empty, or that you at least will allow any previous content to be destroyed. If you have stuff on it that you want to keep, or if you want to make some extra clever partitioning of the drive, then you will need to take care of that on your own (and adjust the instructions below accordingly).

Step by step

  1. Start the laptop, open the DVD and insert the Windows 8.1 installation disk.
  2. Restart the laptop.
  3. When the laptop restarts, you will see the message “Press any key to boot from CD or DVD”. You will then have a couple of seconds to do that. If you’re not fast enough, the Yoga will skip the DVD boot, and what happens then depends on what is currently on your hard drive. In any case you will just have to reboot to get the option to boot from DVD again.

After that, you just have to follow the instructions on the screen to install Windows.

Yoga-specific drivers

Unfortunately, the Windows installer will not be able to find the right drivers for several of the devices in the Yoga 2 – for example the WiFi adapter. So we need to install these manually.

Go to the Lenovo support page for the Yoga 2 11. In the Downloads tab, select “Windows 8.1 (64-bit)” in the Operating System drop-box. The list of downloads now shows all the available stuff for your Yoga 2. There are quite a lot of them, but not all are strictly speaking needed.

I installed all of it (except for the BIOS update which I assumed was already installed) just to be safe, but you could also go with installing it as you find that you need it. You will likely want to install the WiFi (“WLAN Driver (Broadcom, Qualcomm Atheros, Intel)”) drivers at the very least, though.

Install Ubuntu

Preparations to make from Windows

The Windows installation is currently using all of the space on your hard drive. Well, not using it, but the Windows installer have created one large partition on the hard drive using all the free space, and Windows is reserving that one for itself. So we need to shrink that partition to make room for Ubuntu.

Start up Windows on the laptop, and open the Disk Management Tool. Now, I’m not comfortable around Windows 8.1, so I’m not really sure about the easiest way to find stuff, but at least I found this tool in the context menu when right-clicking the bottom left Windows icon.

In the Disk Management window, right-click the C: drive, and select Shrink Volume from the context menu.

A dialog will now open that tells you about the size of the disk volume and how much you can shrink it. Unless you have already started playing around with Windows and have installed new stuff, it shouldn’t currently occupy more than 10-15 GB.

How much of the drive you should use for Ubuntu and how much for Windows depends on which one you think you’ll be using more. I’m not really sure about that myself, but I decided that from the 250 GB SSD that I installed, I would use 60 GB as C: for the Windows system, 100 GB as a common data partition (shared between Windows and Ubuntu), and the rest for the Ubuntu system.

So the first thing I did here was to shrink C: to 60 GB. You need to enter the number of MB to shrink it with rather than how big you want it to be, so I guesstimated a number and ended up making it 61.47 GB – close enough.

Then I created the shared partition that I wanted (which of course is completely optional). Right-click the “Unallocated” section of the disk and select “New Simple Volume” from the context menu. This starts the New Simple Volume Wizard, which is pretty straightforward. I used it to create a 100 GB NTFS partition named “DATA” and assigned it the drive letter D: (had to unplug the DVD reader and reboot to make D: available).

Just leave the rest of the disk as “Unallocated”. We’ll be dealing with that during the Ubuntu installation.


Turn off the laptop, unplug the DVD reader (if you haven’t already) and insert the Live Ubuntu USB drive that you prepared earlier.

Press the Lenovo button and select Boot Menu from the menu. Then select EFI USB Device (your flash-drive) in the Boot Manager, and press Enter.

When you get to the GNU GRUB boot menu, select Install Ubuntu. After that, just follow the instructions on the screen until you get to the “Installation type” screen.

The default option here is to “Erase disk and install Ubuntu” but that will of course wipe the Windows 8.1 installation.

Select the Something else option, and click Continue.

This brings you to a presentation of the disk file system. The “free space” item in the list represents the part of the hard drive that you left as “Unallocated” when shrinking the Windows partition earlier. Here you will create three partitions for the Ubuntu installation.

Note that there might be more than one item named “free space”. The one we are talking about here is the large one, consisting of as many gigabytes that you left free earlier when shrinking the Windows partition. The other ones (if there are any) will be just a couple of megabytes in size.

[[ It has been pointed out to me that you don’t really need to make a specific home partition – meaning that you only need a root and a swap partition. I didn’t want to rewrite the three-partition instruction below since I haven’t tried this myself, but if you want to try it, create the swap partition first, and then the root partition with all the remaining free space. ]]

Select the “free space” item in the list and click the “+” button below the list. This opens the Create partition dialog where you enter the attributes of the new partition to create.

The first partition you want to create is the root partition, which is where the Ubuntu system will be placed. You will probably get away with a root of a lot less than 10 GB, but I’ll go with 20 GB so I’ll never have to worry about it. Select the following options and then click OK:

  • Size: 20000 MB
  • Type for the new partition: Primary
  • Location for the new partition: Beginning of this space
  • Use as: Ext4 journaling file system
  • Mount point: /

Select “free space” and click the “+” button a second time to create a partition for the swap area. The general rule of thumb for the swap area is to set it to twice the size of installed memory. As far as I know, all Yoga 2 11 variants have 4 GB of RAM, so we’ll go with 8 GB of swap. Select the following options and then click OK:

  • Size: 8096 MB
  • Type for the new partition: Primary
  • Location for the new partition: Beginning of this space
  • Use as: swap area

Select “free space” and click the “+” button a third time to create a home partition. This is where all your personal files, music, video, and whatever, will be stored. So you’ll want to use the rest of the free space on the hard drive for this. Select the following options and then click OK:

  • Size: Just leave the default value to make this partition use all the rest of the free space
  • Type for the new partition: Primary
  • Location for the new partition: Beginning of this space
  • Use as: Ext4 journaling file system
  • Mount point: /home

In my case, the home partition got to be 48031 MB (47 GB). If that sounds a bit on the small side, remember that we’ll also have the shared 100 GB “DATA” partition to store stuff on.

The installer will know how to use the new partitions by what mount points you assigned, so now you can click the Install Now button to start the actual installation.

When installation is complete, you will be told to reboot. When you do this you will find that starting your laptop will now open the GRUB boot menu, where you can select to boot Ubuntu or Windows. By default, Ubuntu is pre-selected and will boot after a couple of seconds unless you press a key.

Things to take care of in Ubuntu after installation

There are a couple of things you need to take care of after the installation in order to make Ubuntu work better on your Yoga.

Fixing WiFi and Bluetooth

As you may already have noticed, neither WiFi nor Bluetooth is working in Ubuntu. The reason for this is a broken module, specific for the Lenovo Ideapad laptops. The module is named ideapad-laptop, and is a core Linux module, meaning that the problem is with Linux in general, and not with Ubuntu specifically.

Follow the instructions in my earlier post, Activating WiFi in Ubuntu on Lenovo Yoga 2, to correct the ideapad-laptop module and amend these problems.

Fixing the screen back-light controls

You may also have noticed that you cannot use the (F11 and F12) back-light control buttons. If you press them, you will see the light control slider go up and down, but the back-light intensity doesn’t actually change.

To fix this you need to add a configuration file that tells Ubuntu how the back-light works on this computer. Create a file named 20-intel.conf in the /usr/share/X11/xorg.conf.d/ folder, with the following contents:

You can download the file by right-clicking this link and select to save it from the context menu. Save it in ~/workspace/ideapad first (you don’t have permission to save it where you want it to be), and then copy it to the target folder with:

Or if you want to create it by yourself, use:

Copy the file contents from above and save the file.

Reboot the Yoga and you should now be able to control the back-light intensity.

Fixing the touchpad

If you open the Mouse & Touchpad dialog in System Settings, you will see that there are no touchpad settings at all. There is something wrong with the drivers for the ElanTech touchpad of the Yoga 2, but I didn’t bother to learn the details. I did however find a fix for it here (post #137 by kendatsuba).

Download the file provided by kendatsuba by right-clicking this link (this is just a copy of the original file posted in the forum mentioned above) and save it in ~/workspace/ideapad.

Now build and install the corrected psmouse module by entering these commands:

If the first command above gives you an error message telling you that dkms cannot be found, you need to install dkms first:

And that’s it. You can see that it worked by opening the Mouse & Touchpad dialog in System Settings again. Now there is a section with settings for the touchpad.



Replacing the HDD with an SSD on Lenovo Yoga 2

So. I decided to speed up my relatively new Lenovo Yoga 2 11 laptop by replacing the 5400 rpm HDD with a fast SSD.

I had read about people doing this mentioning that the Yoga 2 is designed for a 5 mm high hard drive, but that you could still squeeze in a 7 mm drive (which is the typical size for SSDs – making those a lot cheaper than the 5 mm SSDs). So I bought a Samsung 840 EVO 250 GB drive. I already had two of those in different computers and know that they are fast and problem-free, and I also hoped that the fact that it’s “only” 6.8 mm might make it a better fit. It fit perfectly, but a 7 mm drive probably wouldn’t have been a problem either.

I feel that I should mention that there are ways to clone the contents of the existing drive onto the new one (before changing it) – meaning that after the switch, you should be able to just start up the laptop and it will work just the same as before, only faster. In my case, I wanted to install both Windows 8.1 and Ubuntu from scratch, so I didn’t have any need to do something like that.

What you need

You won’t need much to do this, but:

  • An SSD (obviously).
  • A TORX T5 screwdriver for the back cover of the laptop.
  • A Phillips #0 (or #00) screwdriver for the HDD/SSD and cradle. The #0 is perfect, but a #00 will work if you don’t have a #0.

Step by step

The Yoga 2 upside down with the TORX T5 scredriver ready for action

The Yoga 2 upside down with the TORX T5 scredriver ready for action

Turn off the laptop, close it, and place it with the backside up on the table.

Use your TORX T5 screwdriver to remove all ten (4+2+4) screws holding the back panel in place. There are no other screws on it so this is easy.

The back panel is also held in place with a couple of hooks similar to those that most mobile phones have. Gently yank the panel loose like when you remove the back of your mobile phone.

Back panel removed. You see the HDD covered with a metal foil in the bottom, left corner.

Back panel removed. You see the HDD covered with a metal foil in the bottom, left corner.

With the back panel removed, you can now see the HDD in its cradle beside the rather large battery. Well, I call it a cradle though it’s actually just two strips of soft metal loosely held together by the piece of metal foil covering the top side of the HDD.

Use your Philips #0 screwdriver (a #00 should work if you don’t have a #0, but then you need to be careful not to damage the screws) to remove the four screws holding the cradle in place.

The HDD loose in its cradle.

The HDD loose in its cradle.

You can now lift up the HDD with the cradle and remove the SATA contact. The cable looks and feels rather fragile, so you’d better be careful with it.

Notice the blue strip of foam rubber where the HDD sat. If your SSD is a bit too thick, you might want to remove that before inserting the new drive.

Old HDD left (with the foil and side strips removed) and new SDD right (with the far side strip attached and near strip ready to be screwed on).

Old HDD left (with the “cradle” side strips removed) and new SSD right (with the far side strip attached and near strip ready to be screwed on).

Use the Phillips screwdriver again to remove the four screws holding the HDD in the cradle. I strongly recommend that you remove one strip at the time and put it on the new SSD before moving on to the next. That way it’s easier to make sure that you don’t put them the wrong way on the new drive.

If the strips stick to the old drive it’s just because of the adhesive on the metal foil. So just tear them loose, but be careful – the strips are made of very soft metal.

The SSD with strips and SATA cable attached, ready to be screwed into place.

The SSD with strips and SATA cable attached, ready to be screwed into place.

Now you can attach the SATA contact to the new drive (remember to be careful with the cable) and place the drive in its slot. Fasten it with the four screws you removed earlier.

An SSD drive has a closed casing and doesn’t need it, but if you’re using this instruction to install a new HDD you will probably want to remove the metal foil from the old HDD and place it on the new one.

Make sure that the SATA cable is placed so that it doesn’t get squashed by something when you replace the back panel.

The SSD screwed into place. Notice how the SATA cable is drawn to avoid getting mangled.

The SSD screwed into place. Notice how the SATA cable is drawn to avoid getting mangled.

Put the back panel into place and press it down gently to make the hooks snap into place.

Before screwing it into place, you might want to check the edges around where the SSD is located and make sure that there is no gap between the back panel and the rest of the laptop. At least not when you press the parts together. The SSD that I used is “only” 6.8″, which seems to fit perfectly, but if there is a gap you should probably remove the back panel again and remove the foam rubber strip from the inside of the panel where the SSD now sits (you don’t really need that for an SSD). If there’s still a gap, there is another strip of foam rubber under the drive that you can also remove.

If there’s still a gap I guess you’ll either have to live with that (might want to open and clean the laptop now and then in that case) or get yourself a slimmer SSD.

Replace the ten TORX T5 screws holding the back panel, and you’re done.

2014 Summer in Thailand – Bulletin I

Chaweng beach just outside my hotel, looking south

Chaweng beach just outside my hotel, looking south

Usually when I travel abroad, I write a few emails about what’s happening during the trip and send them to friends and family as Travel Reports (“Reserapporter” in Swedish). This time I decided to use my blog instead. That way I can just email the URL once to those I normally send the reports to and tell them to subscribe to the blog if they want get future travel updates :) Just this once (since I mentioned it) I’ll add the subscription token here in the post (otherwise you find in the Meta section to the right):



As a creature of habit, I find myself in Thailand once again. I have lost count on how many times I’ve been here since the late 90’s (some years two or three times), but why go somewhere else when you’ve found the perfect spot? I even stay at the same hotel most of the times, so it’s almost like a home away from home to me.

What? No fun in coach?

What? No fun in coach?

This trip is slightly different though. I’m traveling with my old buddy Masse this time (I usually go alone), and since he is as poor as a church mouse, I’ve had to make some sacrifices. It’s been years since I got fed up with travelling coach, so now I only fly Premium or Business Class. It’s expensive, but when you spend 11+12 hours (it’s always an hour more on the way back since we’re flying against the trade winds then) on the plane, it’s worth it if you can afford it. Now I had to ride coach though :O Well, I didn’t strictly speaking have to, but I wanted to sit with Masse. It was alright though since we flew with a brand new Boeing Dreamliner which is rather comfortable even in coach.

At our destination, Koh Samui, I always stay at Aloha Resort on Lamai Beach. I chose Lamai over Chaweng Beach since the latter is too crowded for my taste. Masse is more of an action man than me though, so this time I’m on Chaweng.

Linköping to Chaweng Beach

We took the bus from Linköping to Stockholm, and then Arlanda Express to Arlanda airport. The bus was a good choice since the trains were delayed (as they so often are).

A Norwegian-787-8 from the outside...

A Norwegian-787-8 from the outside…

We flew with Norwegian from Arlanda to Bangkok. The plane was a new Boeing Dreamliner (a 787-8 to be precise). You may have noticed that there have been, and still are, lots of problems with the Dreamliners. We got lucky though. The day before we left I checked all Norwegian flights with the 787 for the last couple of days, and they were all delayed. The flight with the least delay lifted one hour after plan!

Our flight was actually right on schedule, and boarded in time. The take-off was still delayed for half an hour though (but not due to any problems with the aircraft). We were supposed to fly over Ukraine, but after that Malaysian passenger flight was shot down there by pro-Russian “rebels” a week ago, no airlines fly there. So we were to take a detour farther south, but since all flights did that, in addition to all the flights that go that way normally, we had to wait for a slot. So at least the wait was for a good cause :)

...and inside

…and inside

The flight lasted eleven hours. Masse dosed off a couple of times, but I wasn’t tired at all and stayed awake the whole time.

Flying economy class with Norwegian means that absolutely nothing is included except for the seat. You have to use a credit card to pay with if you want food, water, drinks, a blanket, headphones, and anything else you might need. But at least they have made it easy to order and pay. You just select the “shop” from the touchscreen in front of your nose, pick out what you want, swipe your credit card in the slot, and within moments a flight attendant comes along with your stuff.

At least you didn’t have to pay for the entertainment system (apart from the headphones if you don’t have your own with you – I had, but not Masse). I played some games, listened to music, and watched two movies. Well, one and a half. I started to watch Gravity, but that movie doesn’t really work on such a small screen, but I think I made it halfway through it anyway (I’ve seen it before). The Hobbit II (The Desolation of Smaug) that I watched next is of course also made for a big screen, but at least it has some actual contents (as compared to Gravity), so the visuals isn’t everything :)

We landed in Bangkok about 35 minutes late at 7:30 am, so I had 90 minutes before my Bangkok Airways flight to Koh Samui took off (Masse stayed in Bangkok for a couple of nights). I had already checked in over Internet, and I don’t have any baggage to check, so all I needed to do was to show up at the gate 40 minutes before boarding. Easy, right? Nope. After getting off the plane I had to walk a kilometer or so to the main building, wait in line at Immigration, get through Customs, and climb the escalator to Departures on the 4th floor. When I made it there I realized that my phone wouldn’t connect to any network (roaming didn’t work), so I couldn’t get at the email with my electronic boarding card.

Great! What to do now? The lines at the check-in counters were huge, and by the looks of the passengers waiting there, I would have been lynched if I had tried to cut in. The check-in machines (correctly) noted that I had already checked in and refused to let me do it again. I remembered that I had my old Thai SIM card in the wallet and tried to use it, but it was dead (probably disconnected since I hadn’t used it for so long).

By now I had already given up, but I started to look for a TrueMove (the operator that I prefer to use in Thailand) booth to get a new SIM card), and for a while I could still have made it in time, but it took me too long to find it. To ask for directions never hit me as an option – remember that I was stressed out and hadn’t slept for a long time…

Anyway, I bought a new TrueMove-H “3G Tourist Inter SIM” package with 30 days (cheaper than 2*7 days) Internet over 3G (up to 6 GB data). It works great, and TrueMove also have WiFi hot-spots everywhere, and they are free when you have that package.

Didn’t help me at the time though. So I went to Bangkok Airways ticket office at the 6th floor, fully expecting to have to buy a new ticket, but resigned to accept that in the hope of at least finding a new flight on the same day. I told my story (in short-form) to the lady behind the counter, and she simply re-booked me on the next available flight – at no extra cost?! Unfortunately, that flight wasn’t until 5:45 pm, but she also put me on the standby list and told me to check at the check-in counter every hour. I got really lucky and was one of three standby passengers to get on the next flight at 10:20, only 80 minutes later than planned :)

The flight was delayed 30 minutes, and it was a smaller, slower propeller plane, but I landed on Koh Samui around noon without further problems. The hotel was then just a ten minute taxi ride away.


Looking north up the beach road from just outside the hotel

Looking north up the beach road from just outside the hotel…

I had found a really nice bungalow village by the beach in the southern, less crowded, part of the beach. The full name of the “hotel” is Tradewinds by LAWANA, but here it’s known as just Tradewinds. I have a “garden view” bungalow, but I can still see part of the pool, and beyond it the sea, from my porch.

...and inside the gates looking east down the path to my bungalow and the sea.

…and inside the gates looking east down the path to my bungalow and the sea.

I arrived here three days ago on July 25, so I’ve had a couple of days to settle in, and I really like it here. I was a bit worried about the noise at night (I generally go to bed quite early), but here in the garden I hear nothing but the waves of the ocean, and weak base tunes from the nearby bars. And the rain of course – it is after all the rain season, so there is a shower now and then…

Not my bungalow, but they are identical.

Not my bungalow, but they are identical.

The bungalows are quite big, and orange with blue splines and red tile roofs. The porches are also big with stone tile floor and wooden furniture (I don’t like the plastic stuff that is so common down here). I couldn’t get a good picture of my own bungalow since it is surrounded by that green stuff, but there is a picture of the one next to mine somewhere on this page.

There’s no minibar, but a large fridge that I fill with drinks and snacks from the store across the street. And my snus for the trip of course.

Last night I woke up from a scratching sound by the window. It turned out to be two Gecko lizards playing around. I like those little creatures, and they eat mosquitoes and other annoying insects, so I let them be and went back to sleep.

View from the poolside stairs down to the beach where I take my morning bath

View from the poolside stairs down to the beach where I take my morning bath

Sunrise is at 6:10 am, so I get up at six, sit on the porch until seven when breakfast is served in the beach-side restaurant 15 meters away. After breakfast I go for a swim in the sea, and then it’s back to the porch again.

It’s about an hour to sunset now (happens at 6:43 pm) and the mosquitoes are beginning to get aggressive. There are lots of places for them to breed here in the garden, which I guess is pretty much the only negative thing about staying here instead of at a “real” hotel.

Looking North along Chaweng beach from just outside my hotel

Looking North along Chaweng beach from just outside my hotel

Ok, one final picture from the beach and that’s it for now.

Activating WiFi in Ubuntu on Lenovo Yoga 2

Lenovo Yoga 2 11

Lenovo Yoga 2 11

Updated August 2

As I prepare to replace the hard drive in my Yoga with an SSD, I revisited some of the issues that I had with Ubuntu since I will have to fix them again. I then found a newer and better solution to this WiFi problem. It is still about fixing the ideapad-laptop module, but with this new fix, the changes to the module are not just an ugly hack which you then had to turn off – in effect disabling some other functionality of the module.

This new fix repairs the module and leaves it active.

I have updated the post for the new solution, and I have also updated the files for download. As with the previous solution, it wasn’t me who created it. This time it was a clever guy named Hans De Goede, and the new ideapad-laptop.c source file is copied straight from the original author”s space at I didn’t want to link to it there since the link the Hans wrote in a forum post only two months ago is already broken.


Two days ago I bought a Lenovo Ideapad Yoga 2 11 laptop. It came with Windows 8.1 pre-installed, but as I’ve written about earlier, I really hate Windows 8. I had planned to “downgrade” (in quotes since I actually consider it an upgrade) to Windows 7, but decided to give Ubuntu Linux a (new) try first.

Installing Ubuntu 14.4 “Trusty Tahr” (or just “Trusty”) went rather smoothly once I found out how to boot from a USB drive, but I immediately noticed that WiFi wasn’t working. Ubuntu reported that the laptop’s WiFi hardware switch was OFF, which was rather confusing since the Yoga 2 doesn’t even have a physical switch for WiFi.

Searching the web soon revealed that the Linux module for Ideapad laptops is broken. It clears (sets to zero) a couple of enable-bits that it shouldn’t touch and thereby turns the RF hardware OFF. I suppose this will be corrected eventually, but until then there is another fix. It takes a bit of work, but it’s not hard to do if following the instructions below.

I want to be clear on that I did not come up with this solution. I copied almost all of it from a forum post by the signature haohe, who in turn got the idea from an earlier post by the signature kainz. I have clarified the instructions somewhat, and worked some steps into the make-file to make it a bit easier.

Update: The new solution is similar to, but not the same as, the one described in the links above, but I wanted to keep the links anyway since I still use the instructions on how to prepare, build and load the new module from those. The solution described below is however taken from this post written (and created) by Hans De Goede.

Is this why my WiFi doesn’t work?

This solution will work (I hope) if you can answer yes to all three statements below:

  • Your laptop is a Lenovo Ideapad Yoga 2 (not Pro). For example, mine is a Yoga 2 11, meaning that it has an 11″ screen.
  • You have installed Ubuntu 14.04 (Trusty Tahr) on it.
  • WiFi doesn’t work (cannot be activated) and entering the command “rfkill list” in a terminal window tells you that your Wireless LAN is “Hard blocked”.

The solution

The solution is to build a new version of the Linux ideapad-laptop module, and replace the existing one with it.

Sounds complex? Well, it is complex, but not difficult if you follow the detailed instructions below.


In order to build the module, you will need to download the source for the Linux kernel. This is a simple thing to do, but it (of course) requires an internet connection. For this you need a USB-to-Ethernet Adapter (like this one) since you don’t have WiFi and the Yoga 2 doesn’t have en RJ-45 connector. Just plug it in – there’s nothing more to it.

I suppose you could also connect your laptop to the Internet through a mobile phone or similar, though I haven’t tried that myself on Ubuntu.

If you cannot somehow connect your laptop to the Internet, you will need to download to another computer and copy the files to the Yoga. I’m just going to assume that your Yoga is now connected to the Internet.

First you need a directory to work in. In the instructions below, we create the directory ~/workspace/ideapad for this. You can use any directory you want, but then you will need to determine for yourself how to modify the instructions accordingly.

Open a terminal window and enter the commands below.

Step 1 – Download the kernel source

Updated September 28: It has been reported to me that this step is no longer necessary after I modified the solution in August. I haven’t had time to verify that myself, but you might want to try to skip this. If the “make” command in Step 3 fails, you can always come back here and download the build essentials and the Linux headers (the “sudo apt-get” command below) after that. In any case, you do not need to download the kernel source code (the “git clone” command below) unless you want to have the original source code for the module to compare the changes with.

By entering the commands below, you will download the source code you need to build modules (and other stuff too). After doing this, you can find the original ideapad-laptop.c source file in ~/workspace/ubuntu-trusty/drivers/platform/x86/ should you need it for some reason (such as to compare the new source file with if you want to see what changes that have been made to it).

Step 2 – Download the make-file and new source code

Download the following two files by right-clicking on each link below and save with the same names (“Makefile” and “ideapad-laptop.c” respectively) in ~/workspace/ideapad:

Step 3 – Build and use the new module

Now that you have Makefile in your work directory, building a new version of the module is as simple as giving the following command:

Do this. You shouldn’t get any errors unless you made any changes of your own to the files. If you did, check and correct your changes, run “make” again, and repeat until it works without errors.

Once you have built the new module, all you need to do to load it and use it to turn on WiFi is to run the following command:

This will unload the current ideapad-laptop module and load your new version. If this does not automatically turn on WiFi (and Bluetooth), enter the following command.

You should now be able to turn on and off WiFi and Bluetooth from the usual menus.

If something went wrong so that you want to revert to the original module after running “make install”, the original module file (ideapad-laptop.ko) has been backed up as ideapad.ko.backup_<date-and-time> where <date-and-time> is the time-stamp for when the module was replaced. To restore it, rename this backup file as ideapad-laptop.ko and run “make install” again.

That’s it. Easy as doughnuts :)

Contents of the file Makefile