Tuesday, April 5, 2011

Ubuntu Cthulhu

Ubuntu (oo-BOON-too) (Philosophy) "I am what I am because of who we all are." ~ Lemah Gbowee. A distro of Linux based on the Ubuntu philosophy.


Cthulhu (THOO-loo, or hchTHOO-loo, or k,THOO-loo or possibly Worcestershire) A monster imagined by H.P. Lovecraft. Evil from beyond the stars. 


If you should happen to press Ctrl+Alt+F8…F12 (Such as, oh, say, when you're customizing desktop shortcuts) your friendly, safe, beautiful, human, Ubuntu desktop vanishes and without warning you are plunged into the abyss—just you, pitch darkness, and a blinking cursor. Maddeningly, the music you were playing in the realm of light can still be heard, but you fancy it sounds faint and far away. Louder is the sound of breathing, vast and slow. A fetid chill makes you shiver. You have fallen into the Lair of Cthulhu.

Don't get me wrong. I love Ubuntu. I rave to my friends that Linux isn't just for geeks, any more, and have been heard to implore of heaven why anyone uses Windows. I knock on doors and ask strangers if they have accepted Linux as their personal operating system.

I am a database programmer. That may qualify as a species of geek, I suppose, but to me real geeks create (in order of Olympianess)  editors, IDEs, database servers, programming languages, operating systems, natural language parsers and—this is the summit—games. If you don't know what some of those terms mean, trust me, it's all very geeky. Above all, real geeks are stick figures, and I am certainly not that.

I built this computer for Vista, with the usual list of ultra geeky hardware to make it run fast. I even added flame decals to the gun metal black case. Vista sniffed at it, and consented to run. Six months later, I upgraded to XP.

I had always looked wistfully toward Linux, so when the Hearty Heron release of Ubuntu came out, I ran it from the CD for an hour, then took the plunge. As I recall, the installation took about forty minutes, at the end of which I had a dual boot system for Linux and XP, dozens of first-rate applications, and all of the updates fully installed. By contrast, "upgrading" to XP, because I had to reinstall all of my expensive commercial software one application at a time, took many hours.

When Ubuntu came up for the first time and saw the hardware resources available, it burst into tears and started kissing my feet. I had to make it stop. It was embarrassing.

The flame decals have since burned off.

I am still a Linux newcomer. Ubuntu did not become my primary OS until Lucid Lynx. I simply didn't have the time to play with it. Each morning, I would turn on the computer, sigh at Grub (the Linux boot manager), and boot into XP. Linux wasn't paying my bills. But then, after a time, neither was Windows.

This blog is for newcomers like me—especially refugees from Windows—for anyone thinking about giving Linux a try, and for old hands who may enjoy watching me thrash about. This isn't your go-to place for short, snappy how-tos. I tend to explore all of the ideas surrounding a topic. It is a record of what I learn about Linux and how I learn it, told in narratives that I hope will be amusing enough to help the reader learn painlessly the things I sometimes learn by being the kind of fool who presses a hot key combination to see if it is taken. 

The System>Preferences>Keyboard Shortcuts applet is how you assign desktop shortcut keys in Ubuntu. It is what I was doing when I discovered the Lair of Cthulhu.

To be honest, that isn't quite what I was doing. I called myself a fool, just now, and with good reason, but it doesn't take a fool to fall into this trap. Let me just say right now that, even so, I prefer the way Ubuntu lets you assign desktop keys to the way Windows does it, because in the end, the way Ubuntu does it actually works. One of the things it does beautifully is pop up a friendly dialog if you try to assign a shortcut combination that already exists. It tells you what it is assigned to and lets you reassign it to the new command or cancel.

The trouble is that not every shortcut key is assigned here, just the ones Gnome (the Ubuntu desktop environment) knows about. There are older, darker parts of Linux where things lie in wait for keystrokes, and grab them, and activate vast gears and clanking chains that can gape a trap door beneath your feet and swallow you into darkness before your desktop ever sees them.  No warning, no friendly message, because the Keyboard Shortcuts applet never gets that keystroke.

Before the Days of Linux, there was UNIX. It was a time so long ago that graphical user interfaces did not exist. You did everything from a terminal (also known as a "console") that could only display alpha-numeric characters, typically 24 lines by 80 columns—as much as will fit in a single small window on a modern computer screen. I can fit six such windows, including scrollbars, titlebars, decorative borders, and menus on my HD monitor with room to spare.

Yet, even in those ancient days, UNIX was a multi-tasking, multi-user operating system. It always has been.

Geeks' Corner
How do you manage multitasking when you don't have windows and many programs need the whole screen to interact with you? 
In a terminal, you can move a "job" to the background—hide it's output—with Ctrl+z. Then you can start another job. Or twelve. To return to a job, use the command fg  (foreground) and the job number that jobs displays. If there are lots of jobs, you can grep (search) for the name of the process with  jobs | grep emacs for instance, to find the emacs editor's job number.
(Why Ctrl+Z? Well the screen has an x and a y axis. When you move a program behind others, you are moving it on an imaginary z axis, perpendicular to the screen. This can be very handy when you're forty pages into the emacs help system and you realize that you haven't yet seen the command for exiting. That's when kill also comes in handy)
Ctrl+Z also suspends the job. If you want the job to resume and finish in the background, use bg and the job number. This is useful if you start a job, then realize it's going to take forever (more than two minutes). If you are thinking ahead, though, you can launch a job and let it run to completion in the background by appending an "&" to the end of the command line. For instance tree -a / > bigtree.txt &  dumps your entire file system tree to bigtree.txt & lets you go on with life; gedit bigtree.txt will launch gedit and suspend the terminal, but gedit bigtree.txt & firefox http://unbuntuthulu.blogspot.com & launches gedit, launches Firefox (to browse an excellent blog) & resumes the terminal.
Of course, you could just open more terminals, but that wouldn't be nearly as cool.
Normal people resume below.

Back to the problem at hand. In a busy computer room, it could make sense for several people to share the same console(s). I think this is why virtual consoles were invented, since each has it's own log-in.

The shortcuts Ctrl+Alt+F1—F6 are assigned to different full screen text consoles. Pressing one of those will immediately put you at a log-in prompt. Ctrl+Alt+F7 is where your desktop lives (think F7 is heaven) and that is how you can return to your desktop from any of the other consoles, including the undefined consoles reserved for extra graphical desktops: Ctrl+Alt+F8 through F12, aka the Lair(s) of Cthulhu.

An immediate practical use for virtual terminals is to restart the desktop without having to reboot your computer. Even if your desktop completely stops working (something I have never seen), you should be able recover by opening one of the text consoles, say Ctrl+Alt+F1. Log in with your user name and password, then enter the command:

service gdm restart

If your desktop is only a bit tipsy, which I have seen, save your work and close all open applications, first. Don't use a terminal window to restart. Open one of the consoles. Restarting from a terminal window may work, but it moves your desktop to the virtual terminal on F8, and—in my case—some panel applets don't like that.

This ability blows my mind. In Windows, you can sometimes restart Explorer, but I have never observed it to do any lasting good, though it may give you a chance to save your work. (Why is a file manager conflated with the desktop, anyway?) Logging out and back in works a little better, but isn't reliable enough to be worth the bother, and of course you can do it only if your desktop isn't frozen.  Recovering stability in Windows seems to require a "full reboot from cold iron." In my experience, restarting the Gnome Desktop Manager really works—thus far, every time.

It is only because the Ctrl+Alt+Fx keys are trapped before they get to the desktop that you could restart Gnome even if your desktop became totally unresponsive. (In theory. Again, my desktop hasn't locked up, so I can't be sure) This is why the Keyboard Shortcuts applet can't put up a dialog to warn you that you are about to change consoles and perhaps ask your permission before introducing you to Cthulhu.

All of which is no excuse. Lulling the novice into a false sense of security and then plunging him into darkness without warning qualifies as evil from beyond the stars.

This dialog comes up in the Keyboard Shortcuts applet when you press a key combination that is already assigned. It is excellent, thoughtful programming. But to the novice it says, "I've got your back." No, it doesn't. Not quite. What is missing, I think, is just a line or two of text, not here, but on the main applet window: "Note Ctrl+Alt+F1—F12 are Linux system keys for changing terminals. Ctrl+Alt+F7 is your Gnome Desktop." ("Well, what if we decide to change those?" OK. Read the effing configuration files)

On The Other Tentacle

So, why did I call myself a fool? Because I wasn't using the Keyboard Shortcuts applet when—having something in mind for Ctrl+Alt+F8—I decided to just quickly find out if it was taken. "Oooh. I wonder what this button does?" Click

If you have a drop of geek blood in your veins, you may have perked up when I mentioned that Ctrl+Alt+F8 through F12, instead of just plunking you down in front of a blank screen, can be used for extra graphical desktops. If you're brand new to Linux, this is going to make your head explode: with Linux you can use different desktop environments, each with its own core philosophy. The big three are Gnome (the default desktop for Ubuntu), KDE (Kubuntu), and xfce (Xubuntu). Then there is Lubuntu, an unofficial flavor of Ubuntu that uses the lightweight, fast LXDE desktop. Linux is a smörgåsbord.

If you want (only if you want!) you can have different desktops on the same installation, and switch between them by logging out and logging back in, or by associating a desktop with one of the unassigned terminals and switching that way, instantaneously, though I don't know how to do that yet. It will be the subject of a future investigation.

If that's too much choice, just ignore it and stick to Gnome. Even though you're at a smörgåsbord, you can still have the Swedish Meatballs—and try the Pickled Octopus another day.

The service gdm restart command is worthy of a sticky-note. A handier way to restart an unstable, but still functioning, desktop is to close all open applications, then hit Ctrl+Alt+Backspace. You may need to enable this: Go to System>Preferences>Keyboard Preferences (not short cuts), select the Layouts tab, click the Options button, click "Key sequence to kill the X server" and check the box. Please note that Ctrl+Alt+Backspace works instantly. You don't get a chance to save your work. If you think you might hit it by accident, then use the above to make sure it is disabled and just stick to using service gdm restart in a text console. (Come to think of it, I'll take my own advice. It's not that much handier. Why do I want an unexploded mine on my keyboard? Never mind)
On The Other Other Tentacle

I understand that virtual terminals can be useful, but twelve of them? Given that each one can multitask? The six graphical desktop terminals could each have multiple terminal windows, each with multiple tabs, each tab running multiple programs. I get that there are things you can do with a text console that you can't do with a graphics console, such as restart the desktop with service goddamn restart—in case you have feelings about it—but six? Why not six thousand? If one isn't enough, how can we be sure of six? 

The average user spends very little time restarting the desktop. The Gnome Desktop Manager is very stable. I've only had to restart it a handful of times, and then it wasn't frozen, just shaky. I load it down with all the eye candy possible, too. For screen shots. And stress testing. And the interviews.

The point is, I would like to have Ctrl+Alt+F2—F12 available for, oh, I don't know, doing things on my desktop. In fact, as far as ordinary users are concerned (and a database programmer is pretty close to that) by default thirteen different hot keys are devoted either to redundant functions to doing something we don't need.

I know. This is Linux. I can have my druthers. I just have to rtfm. But the Olympian stick figures who really need six different text consoles and six different graphics consoles instantly available can have their druthers a lot sooner than the rest of us can have our druthers. For them, it would be the work of minutes to map every key on the keyboard to a different terminal. I suppose one hot key would have to be reserved for toggling modes so they could actually type something without invoking a terminal. Or perhaps not. The ways of the stick gods are mysterious.

The Nth Tentacle

If I wrote only about Ubuntu's Cthulhu moments, I wouldn't have much to say. Ubuntu is a wonderful operating system. Most of the time it is easy to use—a pure joy, in fact. Most of the misunderstandings I've had with it come from expecting Linux to be as obtuse and disempowering as Windows. It's been a long time since I've had the feeling my computer really was my computer, XP's possessive pronouns not withstanding. It takes some getting used to.