Skip to main content

Sponsors

Fedora 10 Problem: X is hogging CPU

Posted in

I installed Fedora 10 onto my system where the "nv" driver does not work with my display card GF 6600LM. The installation ends up being a text-based installation. Nvidia driver is later installed manually. Surprisingly, now the X windows take up the tty1 instead of usual tty7 (ctrl-alt F7).

The problem occurs when I start the system into runlevel 3 in console, then "init 5" to start X. The X process is then hogging the CPU.

The /var/log/message is showing something like below:

localhost /sbin/mingetty[2369]: tty1: invalid character 0x1f in login name

Now I find that mingetty keeps respawning tty1.

Solution:

Comment out everything in /etc/event.d/tty1 and forget about the existence of tty1.
Or find a way to get the X windows started back at tty7 (ctrl-alt F7).

Compiling VirtualBox 2.0.2 OSE in Fedora 9

Posted in

Unable to compile VirtualBox with the source package? Get errors like the following?

$ ./configure --with-gcc=gcc422 --with-g++=g++422
Checking for environment: Determined build machine: linux.amd64, target machine: linux.amd64, OK.
Checking for kBuild: found, OK.
Checking for gcc: Checking for as86: 
  ** as86 (variable AS86) not found!

Check if the following work helps. ;)

# Install necessary packages, including the following but not exhausive list. This requires root.
% yum install dev86 iasl pulseaudio-devel pulseaudio-libs-devel glibc-devel.i386 libX11-devel.i386 libXt-devel.i386 libXext-devel.i386 libXmu-devel.i386 compat-gcc-34 compat-gcc-34-c++ kernel-devel kernel-headers libxml2-devel libxslt-devel SDL-devel python-devel

# Obtain the source from http://www.virtualbox.org/wiki/Downloads

# Prepare and compile the source.
$ tar jxvf VirtualBox-2.0.2-OSE.tar.bz2
$ cd VirtualBox-2.0.2
$ ./configure --with-gcc=gcc34 --with-g++=g++34    # I was able to build with gcc424 and g++424 too.
$ source env.sh
$ kmk    # This compiles the VirtualBox. You may do 'kmk -j 4' if you have a quad-core processor.
$ cd ./out/linux.ARCH/release/bin/src    # ARCH depends on the architecture of your system.
$ make    # This build the kernel module vboxdrv.
% make install    # Requires root, to copy vboxdrv.ko to /lib/modules/`uname -r`/misc/vboxdrv.ko

# Load the VirtualBox kernel module.
% modprobe vboxdrv    # Requires root.

# Create a group of users for accessing the VirtualBox.
% groupadd vboxusers    # Requires root.
% chown root.vboxusers /dev/vboxdrv
% usermod -a -G vboxusers USERNAME    # USERNAME is your account username who should have accesses to VirtualBox.

# Logout and login for the group information to get updated.
# Check if your user is in group vboxusers.
$ groups    # This should show at least vboxusers

# Try running your newly built VirtualBox.
$ cd VirtualBox-2.0.2/out/linux.ARCH/release/bin
$ LD_LIBRARY_PATH=. ./VirtualBox

If you get the following error (happens in version 2.0.2),

VirtualBox: SUPR3HardenedMain: effective uid is not root (euid=500 egid=501 uid=500 gid=501)

try

% cd VirtualBox-2.0.2/out/linux.ARCH/release/bin
% chmod +s VirtualBox VBoxSDL VBoxHeadless

Save the script below to /etc/init.d/vbox and make sure it's executable. The script helps to load and unload the kernel module during system boot up and shutdown.

#!/bin/bash
### BEGIN INIT INFO
# Provides: vbox
# Required-Start: $syslog $local_fs
# Required-Stop: $syslog $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The Virtual Box kernel module
# Description: The Virtual Box kernel module
### END INIT INFO

start () {
        echo -n $"Starting Virtual Box: "
        modprobe vboxdrv
        sleep 1
        [ -c /dev/vboxdrv ] && chown root.vboxusers /dev/vboxdrv && echo " OK"
        [ ! -c /dev/vboxdrv ] && echo "Failed"
        return 0
}

stop () {
        echo -n $"Stopping Virtual Box: "
        [ -c /dev/vboxdrv ] && rmmod vboxdrv && echo " OK"
        [ ! -c /dev/vboxdrv ] && echo
        return 0
}

restart() {
        stop
        start
}

case $1 in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                restart
        ;;
        status)
                [ -c /dev/vboxdrv ] && echo "Virtual Box is loaded"
                [ ! -c /dev/vboxdrv ] && echo "Virtual Box is not loaded"
        ;;
        *)

        echo $"Usage: vbox {start|stop|restart|status}"
        exit 3
esac

exit 0

Then,

% chkconfig --add vbox    # Add vbox as a service.
% service vbox status    # Check if the Virtual Box module is loaded.
% service vbox start    # Load the Virtual Box kernel module.
% service vbox stop    # Unload the Virtual Box kernel module.

Though the script is rather ugly, it should work ok for our purpose.

Date Time UTC Issue with Fedora 9

Posted in

A system booted up with a wrong date & time is extremely annoying. It happens to me once I installed the Fedora 9.

What happens is that Fedora 9 seems to treat the initialize the system time from hardware clock as UTC time no matter you choose to store it as UTC time or LOCAL time. It works fine if I store the hardware clock as UTC time, but that unfortunately screw up other OS in the system such as Windows.

--- New Solution ---
I simply upgraded to kernel 2.6.26 with CONFIG_HPET_EMULATE_RTC enabled. That solved my time problem.

--- Obsolete ---
I did a little work around for this, setting the system time with hardware clock in LOCAL time in /etc/rc.d/rc.sysinit (about line 745).

# xman: The system seems to read hardware clock as UTC time no matter I set to store hardware clock as local or UTC.
# xman: This force the system time set to local timezone.
hwclock --localtime --hctosys
# xman: Try to correct the timestamp of /proc and /sys.
touch /proc
touch /sys

Generating Bit Mask in C

Posted in

Given a number n, I want to generate n number of 1s on the less significant bits. For example, when n is 3, bit mask = 0000 0000 0000 01112. Observe that the bit mask is equivalent to 2n-1. The following codes try to generate the bit mask.

// Note that *long* is 64bit in this case, running on a 64bit Linux OS.
int i;
for (i = 1; i <= 64; i++) {
        printf("method 1: mask %d: %lx\n", i, (1UL << i)-1); // 2^n-1
        printf("method 2: mask %d: %lx\n", i, ~(~0UL << i));
        printf("method 3: mask %d: %lx\n", i, ~0UL >> (-i)); // obscure.
        printf("method 4: mask %d: %lx\n", i, ~0UL >> (64-i));
        printf("method 5: mask %d: %lx\n", i, ~((~0UL-1UL) << (i-1)));
        printf("\n");
}

However, method 1 and method 2 do not work when n is 64. Both of these methods suffer from shift overflow. When it shifts to the left by 64, the shift operator simply refuse to work, and return the original value.

Method 3 is surprisingly working correctly in my environment. Further study indicates that -i is converted to unsigned (large number), and applied mod 64 before the shift. It becomes equivalent to method 4. However, method 3 is not guaranteed to work with all standard compilers. Note that you can't shift by a negative constant e.g. –2.

Method 5 is just a longer way, start with 1111…10 bit pattern and shift left by n-1, then complement.

Solving Fedora 7 (FC7) Nvidia Display Problem

Posted in

The "nv" driver doesn't work on my GeForce 6600LM. Installing Nvidia's driver however gives the following errors when starting X:

(II) LoadModule: "glx"
(WW) Warning, couldn't open module glx
(II) UnloadModule: "glx"
(EE) Failed to load module "glx" (module does not exist, 0)
(II) LoadModule: "nvidia"
(WW) Warning, couldn't open module nvidia
(II) UnloadModule: "nvidia"
(EE) Failed to load module "nvidia" (module does not exist, 0)

The reason being Nvidia's driver by default installs modules to /usr/X11R6/lib64/modules, however, FC7 now installs Xorg related modules to /usr/lib64/xorg/modules

Solution: Specify the module path during installation.

./NVIDIA-Linux-x86_64-1.0-9755-pkg2.run --x-module-path=/usr/lib64/xorg/modules

Let the installation updates xorg.conf automatically.

Done. Enjoy!

Transcoding

Posted in

# Transcode .flv to .avi

time mencoder 01_a.flv -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300 -o a.avi

# Transcode .raw to .avi

time transcode -i a.raw -o a.avi -y ffmpeg -F mpeg4

Edit rake Compilation Flags

Posted in

Edit /usr/lib64/ruby/1.8/x86_64-linux/rbconfig.rb to modify the default compilation flags.

Edit Compilation Flags When using CPAN

Posted in

Edit /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Config_heavy.pl

Look for:

  • -Doptimize
  • lddlflags=
  • optimize=

The default flag -mtune=generic doesnt work with my GCC compiler, hence I change all of these to -mtune=athlon64.

Publish GIT Repository using GITWEB

Posted in

# Setup gitweb

$ tar jxvf git-1.5.1.2.tar.bz2  # Extract git source
$ cd git-1.5.1.2
$ make GITWEB_PROJECTROOT="/absolute/path/to/git/repository/container" \
        GITWEB_CSS="/gitweb/gitweb.css" \
        GITWEB_LOGO="/gitweb/git-logo.png" \
        GITWEB_FAVICON="/gitweb/git-favicon.png" \
        bindir=/usr/local/bin \
        gitweb/gitweb.cgi
Edit $GIT in gitweb.cgi to point to git.
[Optional] Edit $site_name in gitweb.cgi.
[Optional] Create a project list file and edit $projects_list in gitweb.cgi.
$ mkdir /var/www/cgi-bin/gitweb
$ cp -fv gitweb/gitweb.cgi /var/www/cgi-bin/gitweb
$ mkdir /var/www/html/gitweb
$ cp -fv gitweb/gitweb.{cgi,css} gitweb/git-{favicon,logo}.png /var/www/html/gitweb

# Setup Apache Web Server
Add if they do not exist in the httpd.conf file:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
    Options Indexes FollowSymlinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Access Project Site at: http://host/cgi-bin/gitweb/gitweb.cgi

BASH Problems: Files with Spaces

Previous script xman_dos2unix in xman utility (latest) under GPL has problems on files or directories with space.

Simple work around with double quotes:

for file in "$@" ; do
...
done

Note that all references to $file requires double quotes too.

Another tedious work around with IFS and double quotes:

I use IFS=$'\n', and double quote references to files such as "${file}" to solve the space problems.

OLDIFS=$IFS
IFS=$'\n'
for file in $@ ; do
        # FIXME: I should have put these into a subroutine to reduce code duplications in explore().
        # However, I'm not familiar with subroutines in BASH yet.
        # echo "$file"
        IFS=$OLDIFS
        if [ -d "$file" ] ; then
                echo "Entering $file"
                pushd "$file" > /dev/null
                explore
                echo "Leaving $file"
                popd
        elif [ "`${FILE} \"${file}\" | ${GREP} text`" != "" ] ; then
                $DOS2UNIX "$file"
        fi
        IFS=$'\n'
done
IFS=$OLDIFS
Syndicate content