Tuesday, August 21, 2007

How to Keep Hardware Clock in Local Time


If you dual boot or multiple boot different systems (Linux/Windows), you should keep your system clock in local time meaning you want to disable UTC; otherwise, the clock will be inconsistent between different systems.

Fedora/Red Hat systems:

newemachine# vi /etc/sysconfig/clock
Change 'True' to 'False' in the line where it says 'UTC=True'

Ubuntu/Debian Systems:
newemachine# vi /etc/default/rcS
Change 'yes' to 'no' in the line where it says 'UTC=yes'

Reference

Friday, August 10, 2007

Have fun experimenting with RAID


If your kernel compiled with RAID support and your system supports RAID, the /proc/mdstat exists

[shanren@newemachines ~]$ cat /proc/mdstat
Personalities :
unused devices:


I have reserved two equal-sized unformatted partitions
[shanren@newemachines ~]$ egrep '(sda4|sdb3|blocks)' /proc/partitions
major minor #blocks name
8 4 9052627 sda4
8 19 9052627 sdb3


Let's grab mdadm--RAID administration tool
[root@newemachines shanren]# yum -y install mdadm
Loading "installonlyn" plugin
Setting up Install Process
Parsing package install arguments
fedora 100% |=========================| 2.1 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package mdadm.i386 0:2.6.2-4.fc7 set to be updated

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Updating:
mdadm i386 2.6.2-4.fc7 updates 817 k

Transaction Summary
=============================================================================
Install 0 Package(s)
Update 1 Package(s)
Remove 0 Package(s)

Total download size: 817 k
Downloading Packages:
(1/1): mdadm-2.6.2-4.fc7. 100% |=========================| 817 kB 00:11
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : mdadm ######################### [1/2]
Cleanup : mdadm ######################### [2/2]

Updated: mdadm.i386 0:2.6.2-4.fc7
Complete!


I want to construct RAID 1 with two partitions on separate hard drives and format it with ext3 file system
[root@newemachines shanren]# /sbin/mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/sda4 /dev/sdb3
mdadm: size set to 9052544K
mdadm: array /dev/md0 started.

[root@newemachines shanren]# /sbin/mkfs.ext3 /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1133440 inodes, 2263136 blocks
113156 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2319450112
70 block groups
32768 blocks per group, 32768 fragments per group
16192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Checking the status of building the RAID
[root@newemachines shanren]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb3[1] sda4[0]
9052544 blocks [2/2] [UU]
[==========>..........] resync = 50.0% (4530496/9052544) finish=5.0min speed=15035K/sec

unused devices:

[root@newemachines shanren]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb3[1] sda4[0]
9052544 blocks [2/2] [UU]

unused devices:

Mount the RAID
[root@newemachines shanren]# mkdir /mnt/raid
[root@newemachines shanren]# mount -t ext3 -v /dev/md0 /mnt/raid
/dev/md0 on /mnt/raid type ext3 (rw)


Create the configuration file for mdadm so I can assemble the created array easily later on. I use mdadm with --detail option to obtain the detailed array information and add that information to /etc/mdadm.conf. My final mdadm.conf is shown.
[root@newemachines shanren]# /sbin/mdadm --detail --scan
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=00c674c9:04162ff3:124ba3d9:31646810
[root@newemachines ~]# cat /etc/mdadm.conf
DEVICE /dev/sda4 /dev/sdb3
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=00c674c9:04162ff3:124ba3d9:31646810 devices=/dev/sda4,/dev/sdb3


Should we check how well RAID 1 perform?
[root@newemachines shanren]# ls -lh debian-testing-i386-netinst.iso |cut -d" " -f5
159M
[root@newemachines shanren]# time cp debian-testing-i386-netinst.iso Desktop/

real 0m0.720s
user 0m0.018s
sys 0m0.629s
[root@newemachines shanren]# time cp debian-testing-i386-netinst.iso /mnt/raid/

real 0m0.697s
user 0m0.019s
sys 0m0.613s

[root@newemachines shanren]# ls -lh F-7-i386-DVD.iso |cut -d" " -f5
2.8G
[root@newemachines shanren]# time cp F-7-i386-DVD.iso Desktop/

real 3m18.350s
user 0m0.422s
sys 0m14.498s
[root@newemachines shanren]# time cp F-7-i386-DVD.iso /mnt/raid/

real 7m14.209s
user 0m0.453s
sys 0m13.556s
As the file size increases, the overhead of RAID 1 becomes quite noticeable.

I would like to see if RAID 1 does what it is supposed to do--Mirroring
[root@newemachines shanren]# umount /dev/md0
[root@newemachines shanren]# /sbin/mdadm --stop /dev/md0
mdadm: stopped /dev/md0

[root@newemachines shanren]# mkdir /mnt/raiddevice0 /mnt/raiddevice1
[root@newemachines ~]# mount /dev/sda4 /mnt/raiddevice0
[root@newemachines ~]# mount /dev/sdb3 /mnt/raiddevice1

[root@newemachines ~]# md5 /mnt/raiddevice0/F-7-i386-DVD.iso
355bdb01b0268a4bb7c757f2737dcf7c /mnt/raiddevice0/F-7-i386-DVD.iso
[root@newemachines ~]# md5 /mnt/raiddevice1/F-7-i386-DVD.iso
355bdb01b0268a4bb7c757f2737dcf7c /mnt/raiddevice1/F-7-i386-DVD.iso
Obviously, it does because the md5 of the files written to two RAID devices is the same

Let's clean it up...
[root@newemachines ~]# umount /mnt/raiddevice0 /mnt/raiddevice1
[root@newemachines ~]# rmdir /mnt/raiddevice0 /mnt/raiddevice1
[root@newemachines shanren]# /sbin/mdadm --assemble --verbose /dev/md0
mdadm: looking for devices for /dev/md0
mdadm: /dev/sda4 is identified as a member of /dev/md0, slot 0.
mdadm: /dev/sdb3 is identified as a member of /dev/md0, slot 1.
mdadm: added /dev/sdb3 to /dev/md0 as 1
mdadm: added /dev/sda4 to /dev/md0 as 0
mdadm: /dev/md0 has been started with 2 drives.


Reference: Link 1, Link 2, Link 3

Monday, July 30, 2007

Quick way to find out what types of file systems you can under FreeBSD on your machine


Open a terminal and run:

ls /sbin/mount_*


The following tells the kinds of file systems I can mount under my FreeBSD such as ntfs, ext2fs(linux ext2, ext3 file systems) and etc.
newemachine# ls /sbin/mount_*
/sbin/mount_cd9660      /sbin/mount_mfs         /sbin/mount_procfs
/sbin/mount_devfs /sbin/mount_msdosfs /sbin/mount_reiserfs
/sbin/mount_ext2fs /sbin/mount_nfs /sbin/mount_std
/sbin/mount_fdescfs /sbin/mount_nfs4 /sbin/mount_udf
/sbin/mount_linprocfs /sbin/mount_ntfs /sbin/mount_umapfs
/sbin/mount_linsysfs /sbin/mount_nullfs /sbin/mount_unionfs

Say, now I plug in a USB drive have two slices. The first slice da0s1 is a NTFS file system and the second slice da0s2 is an ext3 file system. I can mount them as follows:
newemachine# mount -t ntfs /dev/da0s1 /media
newemachine# mount -t ext2fs /dev/da0s2 /mnt

Sunday, June 10, 2007

How to Add Startup Programs (Linux & FreeBSD)


This applies to different desktop managers (XDM, GDM, and KDM)

newemachine$ vi ~/.xsession

then put your commands to the following in the file

#!/bin/sh
gnome-terminal &
exec /usr/bin/gnome-session

This runs gnome-terminal after you log into a Gnome session. You can substitute 'gnome-terminal' with other commands that you want to run. 'exec /usr/bin/gnome-session' is required here; otherwise, as soon as starting gnome-terminal process finishes, you will be taken back to the log in window. The directory of window managers such as Gnome varies from distribution to distribution. If you run a different window manager, you want to change '/usr/bin/gnome-session' accordingly.
newemachine$ chmod u+x ~/.xsession
.xsession has to be executable to get this working.

Saturday, June 2, 2007

Learning FreeBSD


How to Install a FreeBSD Application

  • install pre-compiled applications
  • newemachine# pkg_add -r bash
    The above command installs precompiled Bash application.

  • install ports
  • newemachine# cd /usr/ports/www/bash
    newemachine# make install clean
    The above command download necessary source pre, then compile and install it.

How to find a FreeBSD Application
  • Option 1: (If you know the exact application name)
  • newemachine# whereis xclock
    xclock: /usr/local/bin/xclock /usr/share/man/man1/xclock.1.gz /usr/ports/x11/xclock

  • Option 2:
  • newemachine# cd /usr/ports
    newemachine# make search name=xclock
    Port: xclock-1.0.2
    Path: /usr/ports/X11/xclock
    Info: Analog and digital clock for X
    .......

How to Give User Superuser Privilege
  • allow a user to sudo
  • newemachine# pkg_add -r sudo
    newemachine# /usr/local/sbin/visudo

    then add the following line after 'root ALL=(ALL) ALL'
    shawn ALL=(ALL) ALL
    this gives user shawn the superuser privilege

  • allow a user to su
  • newemachine# vi /etc/group
    then add change 'wheel:*:0:root' to 'wheel:*:0:root,shawn', this adds user shawn to the wheel group which have the superuser privilege.

How to Configure X
  • create a X server configuration file
  • newemachine# Xorg -configure

  • test newly created configuration file
  • newemachine# X -config /root/xorg.conf.new
    If you see a gray screen with x mouse cursor, then X is running ok. Now Ctrl + Alt + Backspace to exit X

  • fine-tune X configuration
  • newemachine# mv /root/xorg.conf.new /etc/X11/xorg.conf

    Move tested configuration to the system-wide configuration directory
    newemachine# vi /etc/X11/xorg.conf

    Under Section "Screen", add a line DefaultDepth 24 after the line where it says Monitor "Monitor0"
    then under SubSection "Display", add a line Modes "1024x768" (#change to your own screen resolution) after the line where it says Depth 24
    newemachine# startx
    start the X server!
How to Configure Sound Card
  • load a set of common sound device drivers
  • newemachine# kldload snd_driver

  • test loaded sound card driver
  • newemachine# cat /dev/sndstat
    You will see something similar to the following:
    FreeBSD Audio Driver (newpcm)
    Installed devices:
    pcm0: at io 0xffa7f800, 0xffa7f400 irq 17 bufsz 16384 kld snd_ich (1p/1r/0v channels duplex default)
    This means that my actual sound card driver is snd_ich; therefore, I can load snd_ich instead of snd_driver.
    newemachine# kldload snd_ich

  • load modules at boot
  • newemachine# vi /boot/loader.conf

    add snd_ich_load="YES" to the file

Thursday, May 31, 2007

OSes

Too many operating systems to choose from? Or you only use Windows? Read on:
--> Plain English: FreeBSD vs Linux vs Windows
--> Kernel Talk: A Comparison of Solaries, Linux, and FreeBSD Kernels

Wednesday, May 30, 2007

trying blogger

wow, blogger is pretty cool but I think it can be better :)