Dah… Get rid of the annoying database lock

There have been several times that I had to kill the package management program while it was not through yet. In this case the lock of the database could not be removed correctly and further access to it is prohibited.

The problem is simple, but annoying. Plus, it is common especially when you have a fragile access to internet. So here is the solution when someone tells you ‘database is locked’ in ubuntu/debian linux using apt to manage packages.

Here it is, quoted from https://answers.launchpad.net/ubuntu/+ticket/2231

Use this command from konsole:
 $ sudo fuser -vki /var/lib/dpkg/lock
This will ask you if you want to kill the process using the file.
Now you can run:
 $ sudo dpkg –configure -a
 to make sure all packages are fully installed.

Add comment March 12, 2007

How to improve my English

Recently I paid a three-week visit to California and chatted with dozens of people on all occasions. Although It has been many years since I said my ABC, this was the first time for me to live in an English-dominating environment. And I got some clues on further improvement of my English.

Accent

Nonnative speakers can well sense that they speak differently. The point is to know how and why this happens. For example, Chinese often pronounce ‘that‘ as ‘zat‘, ‘thought‘ as ‘sought‘, because Chinese (including those speak mandarin and dialects) never put their tongue between their teeth. We tend to neglect, or pronounce poorly, phoneme not existing in our mother tongue. On the other hand, Chinese do have much more complex  intonation systems, and they affect the way we speak English. The biggest effect is that we often replace a down tone with a flat tone, which is common in Chinese. Paying special attention to phoneme that are absent in my first language and eliminating tones not popular in English are two key points of eliminating accent.

Vocabulary

During my several flights, there were plenty of chances to chat around with native English speakers. I was upset to realize that my vocabulary could hardly support a dialog beyond everyday life. I cannot master less popular, but important phrases or words barely through learning the language itself. It is the lack of systematic education in English. Therefore, the ability to talk like an well-educated English speaker requires formal education in English. It could be a time-consuming plan, but must help a lot if one goes through textbooks from grade 1 to 12 in the next 3 years. I believe it will significantly boost my proficiency of English, let’s see.

2 comments December 21, 2006

Notes on beep media player plugins

Introduction

There are several articles around discussing how to add support for several popular audio format (e.g., .wma, .ape) to beep media player. Original posts can be viewed at  wma Howto and ape/wma Howto (in Chinese).

A full list of plugins can be traced at the plugin wiki page. Among them, a less known but appealing plugin (to me) is headphone plugin. Finally the uncomfortable feeling of sounds echoing in my head has gone when this plugin takes effect :)

Below is a summary of plugins I have installed.

Adding MAC (.ape) support

  1. Download required MAC non-Windows port and bmp-mac plugin from sourceforge
  2. Install libraries and development tools for compiling: run ’sudo apt-get install XXX’ and replace XXX with the following packages (follow dependencies and ignore installed packages):
    • beep-media-player beep-media-player-dev
    • build-essential gcc make
    • libgtk2.0-dev yasm
  3.  ./configure –enable-assembly
  4. make
  5. sudo make install
  6. ./configure –enable-local=yes
  7. make
  8. sudo make install

DONE

Adding wma support

  1. Download source package
  2. if there is no gcc-3.3/3.4 installed, run ’sudo apt-get install gcc-3.3′ (or 3.4)
  3. run ‘export CC=gcc-3.3′ (or 3.4, 4.0 will NOT work for this plugin) 
  4. run ‘tar -xzf bmp-wma-0.1.1.tar.gz’
  5. run ‘cd bmp-wma-0.1.1′
  6. run ‘./configure’
  7. run ‘make’ then ’sudo make install’

DONE

Simulate Speaker sound stage on headphone

  1. Download bmp-headphone plugin
  2. run ‘tar -xzf bmp-headphone-0.3.tar.gz’
  3. run ‘cd bmp-headphone-0.3′
  4. run ‘make’ then ‘make install’
  5. run ‘libtool –finish /usr/lib/bmp/Effect’

DONE

Add comment October 18, 2006

Nice Feature of Konqueror

Occasionally, I found a nice feature of Konqueror, which further frees me from mouse browsing.

When you open a webpage in konqueror, pressing ctrl (either left or right) will give you a list of shortcut for all links on that page, so you can follow any of them by entering the character/number appearing at the link location. In a framed webpage, it will capture links in the current frame, so switch focus using tab to your desired region first.

Add comment June 14, 2006

How to recover from a dpkg disaster

I am a newbie about linux and encounter trouble in almost every software I try tune. In the last month dpkg crashed twice on my Ubuntu Dapper LTS. After some apt-get upgrade command and normal downloading process, the installation ended up with such an error message:

dpkg: can’t mmap package info file `/var/lib/dpkg/available’: Invalid argument

OK, so now even package management stops working, what to do?

First I searched for possible reasons for such crash, my /var/lib/dpkg/available and /var/lib/dpkg/status look fine under text editors, and dpkg didn’t complain about any package specificly, soon I find out this may be aroused by an insufficient memory size allocated to dpkg, as reported by some Debian users. So I add this line to my /etc/apt/apt/conf:

APT::Cache-Limit 10000000;

I guess that means apt can use as much memory as it wants.

But it is not over yet. I tried several backups for /var/lib/dpkg/status, none of them work for me, and I simply have no backup for /var/lib/dpkg/available. So I realized I have to rebuild both of them by myself, to some extent at least.

So here is my solution, I borrowed several scripts from the web. Before that you may want to read the last part of this article, and perhaps the Debian apt-howto, they explain what are needed to make dpkg work again.

  • backup you current /var/lib/dpkg/available and /var/lib/dpkg/status files, you may still need them later, for reference at least.
  • Create a new /var/lib/dpkg/available, simply quote out fundamental packages from your backup, such as libc6, locales, belocs etc. Start from libc6 package and follow the dependency it requires.
  • Use this perl script to generate your new status database, if your available file is fine, then you wil be almost done, otherwise this file will look much smaller than it should be.
  • run “apt-get upate”.
  • run “apt-get dist-upgrade”. After the packages are downloaded apt will complain for missing debconf or dpkg, whatever, ignore it.
  • Turn to /var/cache/apt/archives, and install packages manually with command “dpkg -i #package name#” #package name# should be replaced with the following packages, one by one: libncurses* perl-base* libstdc++* dselect* dpkg* . If it complains about extra dependence, apt-get that package and use dpkg to install it.
  • Run this script to reinstall libc6, reinstall the base system and recover your status of other packages you have installed. Unlike the perl script above, this script uses information in /usr/share/doc, rather than /usr/lib/dpkg/available, so it will find back all installed packages.
  • Clear up the mess, run “dselect-update” to rebuild your /usr/lib/dpkg/available and you are up-to-date again!

 If you available package is not corrupted (lucky you), only status runs wild, then simply run this script. It didn’t work for me because my bad available package prevents it from generating the right status file in the first place, but maybe you will save most trouble with it.

Add comment June 2, 2006

Random GRUB Splash Image Selection – a Python Script

Before the script there are two warnings, we all know booting is no kidding:

1. Make sure your GRUB splashimage configuration is compatible to the one introduced in my previous blog entry. My script may crash your boot procedure… or much less severely, garble your screen.

2. Check *EVERY* images you plan to use before the random selection ever takes place, this could be done by entering “ctrl C” at the boot screen, and use some GRUB commands to browse the splashimage directories and try them out.

Ok, let’s go on, here is the random splash python script:

———-START OF SCRIPT ————-

#!/usr/bin/python
import os
import commands
import string
from random import choice
GRUB_PATH = '/boot/grub/'
IMG_LNK = 'splash.xpm.gz'
IMG_PATH = '../images/' #Relative path!
curr_dir = os.getcwd()
os.chdir(GRUB_PATH)
img_str = commands.getoutput(''.join(('ls ',IMG_PATH)))
img_lst = []
while len(img_str):
    try:
        idx = img_str.index('\n')
        img_lst.append(img_str[:idx].strip())
        img_str = img_str[idx+1:]
    except ValueError:
        img_lst.append(img_str.strip())
        img_str = ''
       
img_cand = choice(img_lst)
print "The splash image chosen for next boot is %s" % img_cand
if commands.getoutput(''.join(('ln -s -f ', IMG_PATH, img_cand, ' ', IMG_LNK))):
    "Something Wrong while setting the new splashimage!"
else: print "New splashimage set, enjoy!"
os.chdir(curr_dir)

———-END OF SCRIPT ————-

You may want to add it to your startup script so each reboot will bring a little surprise :)

This piece of code has been tested on Kubuntu Dapper, you should try at your own risk. Good Luck.

Add comment May 28, 2006

Configuration of GRUB splash image

Seeing a nice booting splash image add much fun to using linux… at least to me. Better still you can personalize your booting screen with your favorite (simple) image. There are quite a few nice HOWTOs about this topic, but it still takes me a while to make things work, so I think it is worth some notes here.

For ubuntu users, here is an easy-to-follow guide of adding splash image on ubuntu/debian.

And if you would like to know more about splashimage go to visit a detailed version here.

Step 1: Make sure your grub support splash image, up-to-date versions should. Otherwise try to patch it by googling :P

Step 2: Grab an image, it must be a xpm file, and xpm.gz are more storage-conserving, and usually faster. You can download well-tested splashimages from web to test, (better for the first try) or you can make your own.

Note: this image must be 640*480, indexed with at most 14 colors. Many great pictures just look terrible after the conversion, so you may want to try gif pictures because they’re originally indexed and the compression won’t do as much harm as to color-rich ones. It’s a good idea to paint with 14 colors by yourself.

Tool: I prefer Gimp, because it’s powerful and you know what your picture looks like after each modification. right click the image and choose image->mode->indexed, then fill the color number region with 14, choose None for the Dithering option at the bottom. Save the picture with XXXXXX.xpm.gz, Gimp knows the trick of gzip ;)

Step 3: Now we go back to the GRUB part. On Debian based systems, GRUB will search for splash.xpm.gz automatically in the /boot/grub/ folder when you run ‘update-grub’. It’s a good idea to establish a directory for the images, for example

mkdir /boot/grub/images

Then you can copy your favorite image candidates here. Under /boot/grub, Use the command

ln -s ./images/XXXXXX.xpm.gz splash.xpm.gz

This creates a symbolic link to the actual image you’re using. So what’s left is to inform grub to use the image. For Debian update-grub will do this for you, but you may still want to update by yourself (probably on some other distributuion). Then edit the menu.lst (with sudo of course) to add a line like:

splashimage (hdX,Y)/boot/grub/splash.xpm.gz

or

splashimage (hdX,Y)/grub/splash.xpm.gz (if your /boot has its own partition)

or

splashimage=(hdX,Y)${BOOTPREFIX}/grub/splash.xpm.gz

 before the booting records. (hdX, Y) should agree with the booting entry that provides  GRUB, e.g. (hd0, 0). It seems ‘=’ and ‘ ‘ can be used interchangeably.

Note: By using a symbolic link you can avoid most trouble encountered by poor users like me. Because it has been pointed out in a ubuntu forum thread that when reading the menu.lst grub has some limitations on the length the path/filename. So you may end up with strips and dots if your image filename+path is too long. With a simbolic link it doesn’t matter at all where your pictures are stored, as long as they are visible by GRUB.

Good luck and Enjoy!

2 comments May 26, 2006

Tips of Kubuntu

Q:Where can environment variables be loaded at startup or used by many programs? (e.g. PATH)

A:~/.bashrc  /etc/profile  /etc/environment  /etc/kde3/kdm/.kdmrc  ~/.xsessions  /etc/bash.bashrc …

Add comment May 25, 2006

Tools under Linux

NXServer 

NXServer (freeNX as its compatible GNU version) is a fast, easy-to-configure server/client for remote access (via X).  To install is really simple under debian. To make it work securely and properly, note the following:

1. Make you own decision on whether to use self-generated key pair, not much trouble taken but much more stronger security.

2. Make necessary changes to the nxloadconfig file as well as the nxserver script

3. Configure sshd_config properly to support PAM and user login.

Add comment May 25, 2006

LaTeX Tips from Practice

%A template of using the subfigure package

%%%%%%%%%%%%%%%%%%%figure-1%%%%%%%%%%%%%%%%%%%%
\begin{figure}[thbp]
\centerline{
\subfigure[subfigure title]{\label{figure-label 1-1}\includegraphics[width=.45\textwidth]{./figs/fig1-1}}
\hfill %stretch the white space between subfigures
\subfigure[subfigure title]{\label{figure-label 1-2}\includegraphics[width=.45\textwidth]{./figs/fig1-2}}}
\caption{Figure 1}\label{label 1}
\centerline{
\subfigure[subfigure title \label{figure-label 1-1 at title}]{\includegraphics[width=.45\textwidth]{./figs/fig1-1}}
\hfill %stretch the white space between subfigures
\subfigure[subfigure title \label{figure-label 1-2 at title}]{\includegraphics[width=.45\textwidth]{./figs/fig1-2}}}
\caption{Figure 1}\label{figure-label 1}
\end{figure}
%%%%%%%%%%%%%%%End of figure-1%%%%%%%%%%%%%%%%%

%use \autoref or \hyperref for hyperlinks with larger clickable regions

%sample 1
\autoref{figure-label 1} % a clickable region of “Figure 1″

%sample 2
% use \hyperref if you feel dissatisfied with \autoref
%for example \autoref cannot recognize the subfigure environment and correctly auto-complete the labels

\hyperref[figure-label 1-1]{Figure~\ref*{figure-label 1-1}}

%sample 3
%put this after the \usepackage[]{hyperref} command in the document preamble
%if you don’t like the “subsection” name for subsections

\renewcommand{\subsectionautorefname}{Section}

%Declare function names in math environment (instead of using \text{})

%In preamble
\DeclareMathOperator{\myFunction}{myFunction}

%List all References in the .bib file (regardless of their appearance in the text) 

\nocite{*}
% if this command is placed at the beginning of the document, then all items in the .bib file will be numbered according to their appearance in the .bib file, rather than the order they are cited in the text

2 comments March 23, 2006

Next Posts Previous Posts


Categories

  • Personal

  • Feeds