Debian on a Lenovo Thinkpad T420
From GrinningMonkey
The purpose of this document is (a) to be a record of everything I did while configuring this laptop, to use as a reference later if I rebuild it; (b) to help folks who're trying to do some or all of the same things I did when I installed mine.
It is somewhat scatterbrained and incomplete at the moment. Building this laptop up to replace my old one as the machine I do all my computing on is an ongoing process, and I'm almost always more interested in doing it and then using it than I am in writing notes about it.
Contents |
Dealing with Windows
This T420 came with Windows 7 "home premium" edition installed. I was unable to find a non-Windows option. I have since heard that you can look for models that come with DOS instead, but haven't tried it. YMMV.
So first thing to do is to shrink the Windows partition. Not as straight-forward as it sounds. Turns out that Windows has a couple of "unmovable" files in odd places on the disk. If you don't deal with them, you won't be able to free up as much space. In my case, the Windows partition, which was 465GB, had only 30GB used, but the shrink option only offered to shrink 212GB. Thanks for the effort, shrink-manager-thing, but 465 minus 30 does not equal 212. Here's what I did:
(1) Go to Start -> Control Panel. Use the "search" tool to lookup "partition". You'll find Disk Management. If you try to shrink your disk now, you will find that it won't free up as much space as you'd like. Keep this window open for later.
(2) The two "unmovable" files are a paging file and a backup file. Find your way to the place where you can change virtual memory settings, and disable the paging file for your disk. Then find your way to Windows Backups configurator, turn off backups, and delete any backup files.
(2) Defrag your hard disk. Sounds like a cheap tech. support way of getting a caller out of your hair, but this will de-fragment and consolidate your data on the disk so that there is maximum space for shrinking.
(3) Now use the Disk Management tool to shrink your disk, and you should be able to shrink all the unused space. You might want to leave a pittance for Windows in case you ever have some software you cannot run elsewhere. In my case, the configurator for some of my remote controlled flying money-sinks machines.
Installing Debian
I installed Debian testing/wheezy for amd64. I like to keep the initial installation simple (not counting my partitioning scheme to achieve filesystem encryption) and install the packages I want later at the console.
Process:
- Pop the debian testing amd64 netinst CD in and boot 'er up
- Answer all the questions with the default values
- At some point it complains that the microcode for the iwlwifi isn't there. That's okay, unless (perhaps even if) you're fetching the netinst packages over WiFi.
- Assign root password, user account
Now we get to the partitioning. This laptop comes with 3 partitions already:
- Lenovo recovery (~15GB)
- Windows actual (now shrunk to ~49GB)
- Windows SYSTEM_DRV (1.5GB)
I tried once to install Debian in one big partition, but grub2 doesn't like it if /boot is on the encrypted partition as part of the root (contrary to what I'd read somewhere, which serves me right for believing what I read on some website).
(1) So I made a 100MB partition for /boot. Turns out it only uses 18MB -- I looked at my current laptop's grub-legacy /boot and saw ~50MB, and said to myself "grub2 probably wants more, better give it 100". Change the space reserved for superuser from 5% to 0%. It's not necessary on /boot, but the installer apparently doesn't know that.
(2) The rest gets assigned as "physical for encrypted" or words to that effect. Then tell the partition tool to create the encrypted partition. If you don't want to wait a very long time, you can skip the part where it writes random data across the entire partition. However, if a proper cryptanalyst (as opposed to a knuckle-dragging thief) gets their hands on your laptop, they will have an easier time decrypting it.
(3) Next, give a nice long pass-phrase for your filesystem. Not password, passphrase. Best if it's something you can type quickly and it takes several seconds to type it. The goal is that nobody watching you type it will have much of a chance. Later on when you're rebooting the thing several times to reconfigure it, test suspend functions, etc. you can temporarily assign an easier-to-type passphrase to keyslot 1 for the duration of your testing, and kill it after.
(4) Now you can assign the available space as "physical for LVM" or whatever the actual words are. Then tell partition tool to create the LVM. I created one volume group called "main" and two logical volumes in it: "swap" (4.4GB) and "root" (the rest).
(5) Finally, assign "swap" as swap space, and "root" as ext4 mounted on / and change space for superuser from 5% to 1%. 1% of 400GB is still 4GB with which the system can continue running if the rest gets filled up. Reserved space by percent is silly nowadays.
Once this is all written to disk and done, the rest is dead simple:
- Answer with defaults until you get to the part as to what components to install
- I installed "laptop" and "base system" (or whatever the bottom option is called)
- Let grub install to the MBR. It will find two bootable Windows partitions, that's fine. (turns out both will boot normal windows... huh)
- When I tried to put everything including /boot into the encrypted LVM, grub install failed at this point
- Your disk spits out, you reboot, voila
For cleanup, I like to remove one or the other of the grub Windows 7 options (they both seem to work normally) and the "recovery mode" boot option for the kernel. If need be I know how to change the boot command line, I don't need a special entry to clutter my list.
Other options for booting
Also consider making Windows your default boot option. Yes, this means that each time you boot you have to hit downarrow - enter to get the Linux you want. So what, you're about to type a several-second-long passphrase anyways. This way, if you're letting someone borrow your laptop, it's easy for them to just turn it on and wait. It's also easy if a border official wants you to power up your laptop. They'll see that happy Windows screen that tells them you're just another sheep.
Another way to do it is to make a bootable USB stick and put Grub on there instead. Then the laptop will always boot Windows just like all the other computers people are used to, unless you put your stick in and make it boot what you want. Then you wouldn't need that /boot partition at all, and you could get away with 4 primary partitions, not that that matters much. This also makes you look more sheep-like when anyone inspects your laptop, but then again anyone serious about it will just boot it using a CD or something with its own OS for analyzing your computer.
GRUB and GFXTERM
I spent a long time trying to (a) get Grub to come up in graphics mode instead of console, and (b) have the kernel do the same.
This is supposedly accomplished by editing /etc/default/grub and putting:
GRUB_GFXMODE=1600x900x8 GRUB_GFXPAYLOAD_LINUX=keep
I couldn't get it to work for me. After a lot of futzing around, I found out why: there are no *.pf2 fonts installed in /boot/grub! Without them, the update-grub scripts happily configure Grub for console mode, and with no explanation leave you wondering why nothing you try works.
Anyways, you can find the in /usr/share/grub and copy them over, and then it will work.
Also note that 1600x900 is only available after you tell the BIOS to use "Discrete Graphics" (which means nVidia but not nVidia Optimus).
Faster framebuffer
The first time you booted into Linux before doing any of this, you probably left the BIOS set to use nVidia Optimus mode for the display. You maybe noticed that something in the bootup sequence switched from ugly console to nice framebuffer. If you happened to do anything that involves filling the screen (e.g. dmesg) you'll notice it was blazingly fast. And if you happened to have a second display plugged in, the console was cloned there.
After the above, you'll see that things like dmesg are very slow to draw on the screen. Even something like less some_file are slow, and (if you switched to nVidia/discrete) you lose your cloned console.
I found that using 1600x900x8 let the screen draw faster than x16 or x32, so that's what I'm using.
Console Setup switches to an uglier font
You might notice that before the bootup finishes, something says Setting up console font and keymap and then you get an uglier font.
You can disable this by editing /etc/default/console-setup and commenting these out:
#FONTFACE="Fixed" #FONTSIZE="16"
Desktop Environment
I use Sawfish as my Window Manager, and I have no Dekstop Environment (i.e. no Gnome, no KDE, no FVWM, no XFCE). On my old laptop I had Gnome running. As it turns out, the only piece of that glut of stuff I really used was the time and date in the panel. For that I paid the price of slow X start-up, lots of cruft using up cycles and memory.
I use gkrellm to keep an eye on my system. It too eats cycles and sits in memory. It gives me a clock, all sorts of useful information about how busy my system is, state of my battery, a volume control, etc. All the things that a Gnome panel could do using up lots more cycles and memory. So now I don't have a panel, just gkrellm and sawfish-pager. And I don't really use sawfish-pager except occasionally to see which screen I'm on.
I think there are probably some other advantages that Gnome or other desktop environments give, too. I don't know what they are. Until I miss them enough to bother installing Gnome, I won't.
I mention this so that you understand some of what comes next, e.g. configuring the laptop VOLUME UP and VOLUME DOWN buttons (which would, admittedly, be easier if I were to just let Gnome's thingies manage it). Several things would probably work a lot better right out of the box were I using Gnome or some Desktop Environment like most other people do.
Mutt and OfflineIMAP
For email, I use OfflineIMAP, which fetches my mail from various IMAP servers (home, work, etc.) and puts the messages in various local folders. I use Mutt to read and reply.
OfflineIMAP works out of the box. However, it may have a problem when an IMAP server is down. It *should* keep retrying, but sometimes it seems to get stuck waiting forever. I haven't watched this enough / worked this problem out yet.
Mutt
I installed Mutt from source because I use a patch that lists all my folders in a sidebar and lets me quickly and easily switch between them.
Had this problem compiling Mutt: I would get: mutt_ssl.c Error: Unknown type name `STACK'. This seems to be because in OpenSSL 1.0.0, STACK is deprecated. Developers are supposed to use STACK_OF instead. However, /usr/include/openssl/stack.h is still there. It just calls it _STACK instead. Changing the one line (655?) in mut_ssl.c to replace "STACK" with "_STACK" worked.
TMUX, window titles and buffer paste
I use terminals heavily, and tmux is my friend. On my old laptop, tmux and xterm played nicely together, and I could set the window title properly. This is helpful because when I go to switch windows with ALT+TAB, I type whatever part of the window name matches and switch to that window (search for sawfish Iswitch if interested).
Right now tmux is not setting my window title properly. I haven't figured out why yet and I'm asking on tmux-users@lists.sourceforge.net mailing list. Will update when I find out anything.
UPDATE: fixed! Turns out I had in my ~/.Xdefaults:
! Allows Sawfish keyboard paste to work !XTerm*allowSendEvents: true
... and it was interfering. In the newer version of xterm on my new laptop, allowSendEvents is recognized as a major security hole and so it forcibly disables several other resources, including allowTitleOps which means changing the title stops working. Old xterm didn't do this, so my allowSendEvents setting didn't interfere with set-titles.
(I discovered this by invoking uxterm, which changes the resource name and so bypasses my .Xdefault entries. When uxterm titles worked and xterm titles didn't, it didn't take long to solve the puzzle)
Why allowSendEvents? My old laptop has no middle-mouse-button on its touchpad and its two buttons are inconveniently placed -- you have to move your hand(s) away from the keyboard to reach them. So I used a Sawfish extension that lets you assign a key-binding to a function that pastes the buffer like middle-mouse-click does. I had ALT+ENTER assigned to this.
Why I never trained myself to use SHIFT+INSERT for this is another story -- it's more convenient, as middle-mouse-click pastes where the X cursor is and SHIFT-INS pastes where the text cursor is. Most of the time I type in a terminal which isn't mouse-aware, so middle-mouse-click paste goes where the text cursor is. However, in gvim which IS mouse-aware and in browsers and GUIs, you either have to move the mouse to the place where you want to paste (eugh!) or use SHIFT+INS.
Pentadactyl is a Firefox extension that makes your browser much more vi-like, which I absolutely love. One of its features is you can use an external editor like gvim for input fields like textareas. Since I do a lot of text input via textbox (responding to trouble tickets in BestPractical's RT), this has become more important to me.

