Thursday, August 30, 2012

T430 and Ubuntu

Thinkpad T430

As I mentioned in my previous post, I use Ubuntu 12.04 on my new Thinkpad. I wanted to post some tips and tweaks I've made, but as the main post was getting far too long already I thought I'd separate it out into its own post.


It All Works


Basically, you don't have to do to anything in order to get Ubuntu working on this machine. Once I'd installed Ubuntu the system was up and running. Most things work just fine already. Everything below is akin to adding high-performance tyres and racing exhaust, chipping the engine and painting go-faster stripes on your family car. Lots of fun if you're interested, but you can safely skip it all without losing any sleep.

USB3 works and is great with a compatible hard drive. The trackpad and trackpoints all work nicely out of the box, and two-finger scrolling just needs to be enabled in the settings screen. I've never tried to use the Mini DisplayPort or the SD-card reader. I didn't get the lid camera or fingerprint reader so I have no idea if they're supported in Ubuntu.
 


The Tweaks


First, I have a machine with so-called "Optimus" graphics. That is, there's an NVIDIA graphics card in the machine in addition to the Intel integrated graphics. This is not supported out of the box. What will happen under Ubuntu is that you use the integrated graphics, but the NVIDIA card is also active and drawing a fair bit of power. Not good for your battery life.

If you have yet to buy a laptop, I would actually suggest you skip the NVIDIA card altogether. The Intel system is surprisingly good, and the NVIDIA card is reportedly only about twice as fast. If you plan to play a lot of new and demanding games it can make sense to get one; I got one because I'll want to try out GPU processing at some point. Other than that, don't bother.

If you want to use both the Intel and NVIDIA graphics together, you'll currently need to install something called "Bumblebee". It controls the NVIDIA card power and lets you use both graphics systems in a pretty neat way. But Bumblebee looks a bit tricky to install, and I don't actually need the NVIDIA card at the moment, so I've disabled the external card in the BIOS at boot-up.



I have two drives: an SSD (that is, a solid-state drive — USB memory on steroids) as a main disk, and a hard drive as a secondary one. The SSD will work fine out of the box without touching anything. But there is a few things you can do to improve performance and extend the lifetime of the drive.

SSD drives are really fast when reading from them. But writing is slow, and it also wears out the drive over time (Ars Technica has the whole story in exhaustive detail and multiple installments). You want to avoid unnecessary writes as much as you can. You also want the drive to reuse all its memory as evenly as possible, so it doesn't wear out any one area too fast.

We want to set a parameter called "discard". The OS will inform the drive immediately when a data block is no longer in use which helps the drive spread out writes and prolong the life of the drive. File systems can record the last time a file was read, but that generates a write — which is bad, remember — every time you read. So we also set "relatime", which tells the disk to only record the first time you read the file after it has been written. I think this is the default in Ubuntu already, but setting it can't hurt.

You set these parameters in /etc/fstab — there may be some graphical tool to do this but frankly I don't really know what it'd be. In a terminal, do:

$ gksudo gedit /etc/fstab

You'll see a line like this (I assume the first disk — sda — is your SSD):

# / was on /dev/sda1 during installation
UUID=something /  ext4  errors=remount-ro 0 1

Add "discard" and "relatime":

UUID=something /   ext4 relatime,discard,errors=remount-ro 0 1

Another tip is to change the scheduler to "noop" for the SSD. A scheduler orders the reads and writes to a disk to maximize performance. But schedulers are typically made for spinning disks, so it's generally better to let the SSD decide this for itself. There's no simple parameter to set this. Edit /etc/rc.local in the same way as above, and at the bottom of that file, add this command:

echo noop > /sys/block/sda/queue/scheduler

I've got plenty of memory in the machine, and one easy way to make use of it is to mount /tmp as a ramdisk. Accessing it is much faster, and it also saves wear on the SSD as well. Add the following line to /etc/fstab (I limit it to 1GB):

tmpfs  /tmp  tmpfs  defaults,noatime,mode=1777,size=1G 0 0

Also, I set Firefox to keep its cache in /tmp; again, that speeds up Firefox
and saves the SSD. Go to about:config, right-click->New, and add
"browser.cache.disk.parent_directory" with value "/tmp".


What about that second hard drive? I formatted it and mounted it on /data during installation. I put all my pictures and archival research data there. I also run a very simple back-up script every evening that copies all changes on the SSD to the second drive. If the SSD fails I'll lose no more than a day of work.

This means the drive isn't actually used very often. Having it spinning all day long is annoying, and it uses up the battery for no good reason. I set the drive to spin down and sleep if it's unused for more than a minute. In /etc/hdparm, add the following:

command_line { hdparm -B 1 -S 12 
    /dev/disk/by-uuid/something }

Where "something" is the same as you can find for the drive in /etc/fstab.

I also set the swap partition on the second hard drive. The idea is that I hardly ever need swap with the amount of memory I've got, and I don't want to sacrifice a few GB of precious SSD space to something I rarely use. On the other hand, if you do need swap on a regular basis, an SSD is a better place for it.


The Bugs


Not everything is a bed of roses, though (and a good thing too; those thorns are scary sharp). The Intel Ivy Bridge chipset is brand new, and there's a fair number of bugs that can affect people with such computers. And before anybody starts to snicker about Linux: New Windows and OSX machines use the same Intel-supplied drivers at heart and have their own share of related bugs.

I've had two bugs affect me. One where the graphics driver (and thus the machine) will completely hang about once a day or so. My solution was to install kernel 3.4.0 from this PPA which completely stopped this from happening. I've seen that recent updates presumably fixes this bug but I have no particular reason to switch back from 3.4.0 so I can't confirm this.

And there's one bug where putting the machine to sleep by shutting the lid — and only shutting the lid — would give you a frozen screen on wakeup. You had to kill X and lose all your currently open work. My guess is that closing the lid triggers the driver to turn off the screen twice — once for closing the lid and once for sleeping — and that messes up something internally.

There is no fix released for 12.04 yet, though it is fixed for 12.10. Meanwhile I've turned off sleep when closing the lid and simply use the "sleep" button on the keyboard instead. And frankly, that is my preferred behaviour anyway; when I go to and from seminars and meetings I don't want the computer to shut down just because I have the lid closed.

It's notable that both these bugs are already fixed for the next version in October or were never present there in the first place. The takeaway is to not by the very latest and shiniest new stuff the moment it is released. You pay the most and get all the bugs. Wait a while, just a few months, and you'll get the same thing but cheaper and free of most teething problems.

I know this of course, and my plan was to wait until October and Ubuntu 12.10 before I got this computer. But my previous computer died before its time, leaving me with little choice. Oh well; I've been able to fix or work around it so no harm done. And anybody installing 12.10 on this hardware will find the rock-steady experience they have every right to expect, in part because people like me have been shaking out the bugs.

15 comments:

Lotharloo said...

Really great article! I applied most of your tweaks and they are really useful.

I'm curious about something though. I'm getting about 20W power consumption on idle with wireless on under Ubuntu 12.10. I was wondering what do you get.

In Windows 7, it's about 8 W so I get more than twice the battery life in Windows which sucks because I'm 99% of the time on Linux.

cheers!

Jan Moren said...

Hi, I get 10-12W normally. If you have the NVIDIA card, then I bet that's the reason you are getting so high numbers; the card is on all the time even though you aren't using it.

Easiest way around it is to simply turn it off in the BIOS. That's what I've done for now. Or, if you want to sue the card, install Bumblebee.

Lotharloo said...

Thanks a lot! I disabled the card in BIOS and it worked perfectly. I've not tried the bumblebee yet but at the moment I don't really need the graphic card. But thanks a lot for the nice tips!

perlpetual said...

Hi Janne,

I was looking for a good sturdy laptop which could be used for studying for VMWare VCP (basically needed a good mobile VMWare Lab) and your article on the T430 helped me.

I am now a proud owner of a T430 !!

Enjoying it so far. Still on Win7 though. Will soon migrate to Ubuntu.

Any tips you have for dual booting Win7 and Ubuntu?

Basically planning to keep Win7 to upgrade the BIOS/thinkvantage stuff etc.

Please let me know.

Jan Moren said...

Hi,

I've never done dual booting so I can't offer any solid advice. There's lots of guides and stuff out there, though, and just straightforward dual boot seems easy to do.

edzer pebesma said...

Thanks, that was helpful.

My T430 w 16 Gig ram and no nvidia goes down to 7.5W when on battery, fan off, giving it over 7 hours on the 6 cell, much longer on the 9.

I did a BIOS upgrade, seems to improve fan speed, you don't need windows for this, just burn an ISO to CD, boots itself.

Reformatted the complete disk, running win7 in VirtualBox now (with ubuntu 12.04, didn't work under 12.10)

Jan Moren said...

@edzer, thanks! Never considered a BIOS update. Is it worth it for the fan speed — it's already quiet enough that I'm never bothered.

Also, I keep pushing off installing Windows 7 in some kind of VM. The installation looks messy and complicated, with suspicious images floating around and advice that often seems contradictory.

edzer pebesma said...

The fan ran often over 3000 rpm when idle, which disturbed me enough. Update was a piece of cake.

Installing VirtualBox was pretty trivial, on 12.04, manuals are good. It doesn't take any unnecessary resources.

Jan Moren said...

Hm, my fan basically stays silent at idle, and is still almost unnoticeable when it does run. Only time I really hear it is when I stress the machine.

It's not VirtualBox that seems messy, but installing Windows into it. Never done a Windows installation so I don't have much experience to fall back on.

Joanthan said...

Any updates to T430 and 12.10 since last August.

Jan Moren said...

Hi,

No real update to report other than that the bugs I had are gone and it all works fine now.

That's my usual experience with Ubuntu by the way: new hardware is often a bit flaky and messy, but give it six months and the support is usually rock solid.

That's not unique to Linux of course; both Windows and OSX often suffer from similar bugs with newly released hardware.

Jon said...

This was a handy article.

I have a similar config to yours. I did try installing bumblebee but found power consumption still hovered around 18W-20W a lot of the time. My old laptop also had an optimus card but no bios option so bumblebee had to be used to disable it. It usually decreased power consumption much more than I found on the T430. In the end I just shut the discrete card off in the bios and I'm glad that option is there.

I wasn't going to get the Nvidia card since I'd had a lot of trouble with them on my last laptop but Lenovo was paying me to take it so I decided to get it anyways.

Jan Moren said...

Hi Jon,

yes, actually I haven't used the NVIDIA card since I got the laptop. The graphics are fast enough for me already. Were I to order the machine again I would have skipped it.

It may help prolong the life of the laptop another year or so, though; if the current Intel GPU is just too slow for some game in two or three years time the NVIDIA card may be enough to let me use the machine for a while longer.

stevenswall said...

Everyone says to disable the GPU... I need it for some Steam games to hopefully run better. What are the correct BIOS settings? (I've tried a few, and Ubuntu can't even see the GPU to install the driver. windows 7 can.)

Jan Moren said...

Steven, sorry for the late response.

In short, I have no idea. I've never used the card and so far I've never needed it. I guess your best bet is googling for it or asking on a site such as askubuntu.