Monday, January 12, 2009

Add a non-graphical login option in Ubuntu

By default, Ubuntu would bring you directly to a graphical login window (gdm). Sometimes I just want to do some quick work and don't want to waste the extra 20 seconds to bring up Xfce/Gnome/Kde, here is how.

Before doing anything, we need to prepare ourselves with the boot process in Ubuntu. For this regard, here is a very helpful article by Aaron Toponce. In summary, Ubuntu will first boot into the S runlevel to excute some critical initializing scripts, then it will switch to runlevel 2. As most other linux distributions, Ubuntu does have 4 multi-user runlevels (2-5), but it only uses 2. Our goal is to revise runlevel 3 to boot to a non-graphical login window, and add an option in grub to start the process.

Step 1. Prepare runlevel 3.
For this non-graphical runlevel, we don't want any thing related to X windows brought up upon boot. Thus, we remove the gdm service script in /etc/rc3.d:
  sudo mv /etc/rc3.d/S30gdm /etc/rc3.d/s30gdm
Next, Ubuntu has x11-common brought up in the S runlevel, we don't want that in our non-graphical login, so move it to runlevel 2:
  sudo mv /etc/rcS.d/S99x11-common /etc/rc2.d/S01x11-common

Step 2. Add a menu item in grub.
The normal way to boot to a desired runlevel is to add a kernel option with a single digits or the letter "S". This is simple in Ubuntu. Open /boot/grub/menu.lst and add this following line:
  #altoptions=(non-graphical) quiet 3
and update grub menu:
  sudo update-grub

Step 3. Tell Ubuntu to go into that runlevel
You don't need this step is you are using a different distribution other than Ubuntu, since the kernel option is automatically recorgnized. In Ubuntu, however, the system use the script /etc/init.d/rc-default to determine next runlevel after the S runlevel. The one shipped with Ubuntu will only boot to runlevel 2 and single user mode. We need to modify this file so that it will accept the kernel runlevel parameter. Just add these lines in /etc/init.d/rc-default before the part testing for "single" in the command line:
  # Before testing for single user runlevel in the kernel parameter list, add these lines:
RL=`sed -n -e "s/.*[ \t]\([S0-6]\)[ \t].*/\1/p" -e "s/.*[ \t]\([S0-6]\)$/\1/p" /proc/cmdline`
if [ 'x'$RL != 'x' ]; then
telinit $RL;
elif ... (following the original script here to test "single" in the cmdline)
And that's it. Now when you power up your computer and there will be a grub menu item to boot your system to non-graphical mode.

Wednesday, January 7, 2009

eee 901, end of story

I ordered a Asus Eee 901 about a month ago after some research on the tiny netbooks. It was a windows edition because the linux version was not on sale. The netbook arrived a week later, and the first glance was impressive -- it's really small, especially because I'm used to my 14 inch T61. The keyboard is quite undersized, but not as bad as many online reviews claim.

Putting Xubuntu on it is an easy task, and I was all happy the next day before first the screen and then the whole thing died completely. That's a little more than 24 hours after I put my hands on it. I thought that it was pure bad luck -- I haven't seen any complaints about the build quality of the Eee PCs. So I contacted TigerDirect.com, where I ordered the computer from, and they were quite willingful to send me another one for exchange. They also provided a return shipping label. It's another two weeks before I receive the replacement due to backordering, but I did get it before the New Year.

This time, it didn't take me 24 hours to find out what's defective: the battery cannot be charged beyond 51%. A quick online search leads to a few similar cases and a few solutions, but none works for the unit I have. So I decide to drain out the battery to see what would happen. Yes, miracle happens, when the battery indicator drops to 0%, the computer is still alive, and stay alive for another 3 hours! This saying, the battery is actually good, but it gives wrongful information to the system. Now I start to recharge the battery, the battery capacity indicator increase from 0% instantly rather than wait until it's half charged. That's a good sign, and indeed, this time the indicator does show 100% charge, but -- why there is always a but -- charging does not stop there. The charging light on the front of the computer keeps blinking in red for a whole night, and there is actually a small charging current of about 20 mA (the normal current is between 1000mA and 2000 mA).

This is not good! Two defective products in a row cannot be explained by my bad luck. So I send it back and decide to wait until the weight of Thinkpad X2** drops to bellow 2.5 lbs.

Saturday, January 3, 2009

Speed up ubuntu, Part I -- Boot up

I've done some tweaks on my T61 to make xubuntu startup and run faster. These tricks are mostly collected from different forums/blogs.

Part I. Boot Up

One easy way to measure boot time is to install bootchart:
  sudo apt-get install bootchart
Once installed, a png image will be generated at /var/log/bootchart every time the system reboots, showing the starting up processes and how long they each take. You probably don't want it after you have done tweaks with the start-up process.

I.1 Clean installed packages (http://www.linuxine.com/2008/06/speed-up-ubuntu-boot-speed.html )

Delete residual config packages: in Synaptic package manager, check status and remove all residual config packages.
Delete incomplete packages:
  sudo apt-get autoclean
Delete isolated libraries:
  sudo apt-get install deborphan
sudo deborphan | xargs sudo apt-get -y purge
sudo apt-get autoremove --purge
This is more like a help on the overall performance than booting only. But it will clean out some broken packages that might be loaded during booting.

I.2 Disable unnecessary services (http://ubuntuforums.org/showthread.php?t=89491)

IMPORTANT! Since we're going to mess up with some critical system files, I would back them up:
  mkdir ~/sysbak
cp -rPp /etc/rc?.d ~/sysbak
The -P option in cp tells it to copy symbolic links rather than files they point to, the -p option tells it to preserve all file properties.

A quick introduction on the symbolic links in the rc*.d directory. Each rc*.d directory corresponds to a runlevel (S, 0-6). S/1 are the single user runlevel, 0 is shutdown, 6 is reboot, 2-5 are multiuser runlevels. In ubuntu, runlevels 2-5 are the same by default. In each rc*.d directory, there are two type of symbolics: those begin with "K??" and those with "S??". Upon entering each runlevels, the system will kill all services beginning with "K??", then start those beginning with "S??", in order of the two digits "??". In the default boot process, after the kernel is loaded, the system enters runlevel S, then 2 and stay in 2. To enable/disable a service at a certain runlevel, simply add/remove a S?? symbolic link to the service script in /etc/init.d. To learn more about Ubuntu boot process and runlevels, see this two-part article by Aaron Toponce.

Here is a list of services available by default on my T61 laptop:

must enable, critical,
should enable,
may disable.

letter and numbers in parenthesis shows ubuntu default runlevels.

NetworkManager (S): Automate switching between different network connections.
acpi-support, acpid (2,3,4,5): power management
alsa-utils (2,3,4,5): sound
anacron (2,3,4,5): excute delayed cron jobs
apparmor (S): application security, I don't need it on my laptop
apport (2,3,4,5): Automatic crash report. Safe to turn off.
atd (2,3,4,5): excute commands assigned by at.
aumix (2,3,4,5): Turn off if you are using alsa-utils.
avahi-daemon (2,3,4,5): MS/Apple Zeroconf implementation.
binfmt-support (2,3,4,5): Support non-native binary format. If you run Windows program through wine, you'll need it.
bluetooth (2,3,4,5): Bluetooth support, turn off if you don't connect to a BT device regularly.
bootlogd (S), stop-bootlogd (2,3,4,5): Record boot messages, but currently it's broken in Ubuntu.
cron (2,3,4,5):
cups (2,3,4,5): turn off if you don't connect to a printer regularly.
dbus (2,3,4,5): Message bus system.
dkms_autoinstaller (2,3,4,5): Kernal module auto generator and installer.
dns-clean (S): Mainly for cleaning up the dns info when using dial-up connection
gdm (2,3,4,5): Gnome desktop manager
hal (2,3,4,5):
halt (0):
hotkey-setup (2,3,4,5): Setup some hotkeys for HP, Acer, ASUS, Sony, Dell, and IBM laptops.
killprocs (1):
klogd (2,3,4,5): Kernel logging
laptop-mode (2,3,4,5): laptop battary managing. not needed for desktops
linux-restricted-modules-common (0,6,S): needed if restricted modules are used, e.g., nVidia driver.
loopback (S): providing loopback device.
module-init-tool (S): load extra modules in /etc/modules.
networking (0,6,S):
pcmciautils (S): pcmcia card support. I don't have any pcmcia devices.
policykit (2,3,4,5):
defining and handling the policy that allows unprivileged processes to speak to privileged processes
powernowd, powernowd-early (2,3,4,5): manage CPU frequency
pppd-dns (2,3,4,5): dial-up service
procps (S): provide infomation about /proc
rc.local (2,3,4,5)
readahead (S), readahead-desktop (S), stop-readahead (2,3,4,5): Speed up booting by read all needed files into the memory. Use this with kernel profiling reduce the startup time on my T61 from 27 seconds to 20 seconds.
reboot (6)
rmnologin (2,3,4,5): remove nologin
rsync (2,3,4,5): Rsync service
screen-clean (S):
sendsigs (0,6): send signals during reboot or shutdown
single (1): single user mode
sysklogd (2,3,4,5): kernel logging
system-tools (2,3,4,5)
udev, udev-finish (S): udev service
ufw (S): uncomplicated firewall, you may want a firewall to protect you computer, but I don't.
umountfs (0,6)
umountroot (0,6)
urandom (0,6,S): random number generator
usplash (S): splash screen during booting
vbesave (2,3,4,5): Video card BIOS configration
wpa-ifupdown (0,6): secured wireless connection
x11-common (S): start xserver, I changed it to runlevel 2 since I sometimes want to boot to non-graphical terminal windows.
xserver-xorg-input-wacom (2,3,4,5): Wacom tablet input device support, I don't have one.

Now we are going to remove/add symbolic links in the /etc/rc*.d directories. If you haven' t backed up the original links yet, DO IT NOW.

Generally, you don't want to mess up with anything in runlevels 0, 1, and 6. But I would remove the K scripts in 0 and 6 which are not started in any other runlevels. Runlevels 0 and 6 are identical except the last script excuted: halt in 0, but reboot in 6.

Here are what these directories look like in my T61 after all the modifications:
$ ls /etc/rcS.d
README
S01mountkernfs.sh
S01readahead
S02hostname.sh
S06keyboard-setup
S07linux-restricted-modules-common
S08hwclockfirst.sh
S08loopback
S10udev
S11hwclock.sh
S11mountdevsubfs.sh
S13pcmciautils
S15module-init-tools
S17procps
S20checkroot.sh
S22mtab.sh
S30checkfs.sh
S35mountall.sh
S36mountall-bootclean.sh
S37mountoverflowtmp
S37udev-finish
S39readahead-desktop
S40networking
S45mountnfs.sh
S46mountnfs-bootclean.sh
S49console-setup
S55bootmisc.sh
S55urandom
S70screen-cleanup
S90console-screen.kbd.sh
$ ls /etc/rc0.d
K01gdm
K20apport
K25hwclock.sh
K50alsa-utils
K63mountoverflowtmp
K74dkms_autoinstaller
K86avahi-daemon
K99laptop-mode
README
S01linux-restricted-modules-common
S15wpa-ifupdown
S20sendsigs
S30urandom
S31umountnfs.sh
S35networking
S40umountfs
S60umountroot
S90halt
$ ls /etc/rc2.d
README
S01policykit
S01x11-common
S05vbesave
S10acpid
S10powernowd.early
S10sysklogd
S11klogd
S12dbus
S14avahi-daemon
S20apport
S20dkms_autoinstaller
S20hotkey-setup
S20powernowd
S20rsync
S24hal
S28NetworkManager
S30gdm
S30system-tools-backends
S50alsa-utils
S89anacron
S89cron
S99acpi-support
S99laptop-mode
S99rc.local
S99rmnologin
S99stop-bootchart
S99stop-readahead
hat's it for now. I will cover how to take advantage of runlevels 3-5 in a separate topic.

I.3 Profile the boot up process.

This will work only if you enable readahead service in previous section. The kernel parameter "profile" tells it to record all disk access during the booting process, then readahead can load all the files at once to save from random access of harddrive. This might not help much for SSD since SSDs have the advantage of fast random access.

The kernal parameter can be added in your /boot/grub/menu.lst, but since we only need it once, it's better to add it in the grub boot menu. At the boot menu, press "e" will allow you to change booting parameters. Highlight the kernel line, press "e" again, and append "profile" at the end of the line. Hit "b" to reboot, and wait for the computer to start. It will be slow, probably 5 times slower than an normal boot, but remember that we only need to do this once.

I.3 Concurrent booting (http://www.my10sen.com/2007/10/05/ubuntu-a-speedup-guide/)

Concurrent booting allows Ubuntu to take full advantage of dual-core processors, as well as processors that hyperthread or multithread. These settings are located in your /etc/init.d/rc file.

Change
  CONCURRENCY=none
to
  CONCURRENCY=shell
To be frankly, this change does not help me much although I have Intel Core Duo processers.

I.4 Remove extra virtual terminals (http://paulsdigitalworld.blogspot.com/2008/01/complete-ubuntu-speed-up-tweak-guide.html)
  cd /etc/event.d
sudo mv tty3 tty3.bak
sudo mv tty4 tty4.bak
sudo mv tty5 tty5.bak
sudo mv tty6 tty6.bak

I.5 Reduce forced disk check

By defaults, ext2/ext3 partitions are forced to do disk check about every 30 mounts, or every 6 months. I typically turn off my laptop every day, so the 30 mounts cap reaches rather often. Since laptop's harddrives are subject to more potential damage than desktop's or server's, I prefer to have it checked every 3 months or 100 mounts. This can be done with tune2fs:
  sudo tune2fs -c 101 -i 3m /dev/sda1
The -c option is the mount count cap, and -i option is for time interval. Do this for all ext2/ext3 partitions. Be sure not to use the same numbers for all partitions. Otherwise your boot time might prolong to an hour if all partition checks are synchronized.
 
Creative Commons License All contents on this page are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.