Friday, March 10, 2006

Terminal color code for vt100

This is very useful if you want to display your text messages in color from your c program(printf) on linux console


Format : esc[[{attribute};{foreground};{background}m
key stock for esc[ = CTRL+v ESC = hex char value of 0×1B(used in printf with %c format)
attribute 0 – reset, 1 – bright, 2 – dim, 3 – uderline
foreground (30 + color)
background (40 + color)
color 0 – black, 1 – red, 2 – green, 3 – yellow, 4 – blue

Example
^[[1;31;49m

Attr: Bold fg:red bg:white

Tuesday, March 07, 2006

Ext3 File System

Ext3 FS = (Ext2 FS) + Journal

Advantage over Ext2 File System = Fast crash recovery


Converting an Ext2 File System into an Ext3 File system in Linux OS

Use tune2fs command with -J option to add journal support to your partition edit the file /etc/fstab, change the file system type specified for the corresponding partition from ext2 to ext3

Swap partition

what is swap partition? – portion of hard disk space is used as RAM. useful for system which has less RAM and still want to run large programs.

How to create swap memory in linux?

  • create a empty file of required swap size
    dd if=/dev/zero of=/swap-file bs=1k count=65536
    swap memory = count*bs = 65536*1k = 64 MB
  • convert this file into a swap file format
    mkswap /swap-file 65536
  • enable swap file system
    swapon /swap-file

RAM disk

What is RAM disk?
RAM disk is a portion of RAM which is being used as a disk drive. Any data stored in RAM disk is lost when system is switched off. very useful for embedded system where there is not disk drive. Linux kernel 2.4 has built-in support for ramdisks

How to create a RAM disk in linux?
  • RAM disk size : default RAM disk size supported by linux is 4 MB so, if you need more ram space then include ramdisk_size=XXXX in kernel command line for kernel to reserve memory for ramdisk. here XXXX is ram size expressed in 1k block. for 16 MB, ramdisk_size=16000
  • Format your RAM disk : command :- mke2fs – m 0 /dev/ram0 16384. Linux supports 16 RAM disks by default (ram0 to ram15).
  • Mount your RAM disk : command :- mkdir /mnt/rd; mount /dev/ram0 /mnt/rd
  • Verify your RAM disk : command :- df -h

How to create RAM disk for embedded linux?

  • create a empty file of your file system size. here it is 16MB command :- dd if=/dev/zero of=ramdisk bs=1k count=16384
  • format the empty file as ext2 file system command :- mke2fs -F -m 0 -i 1024 ramdisk
  • create a mount point and mount the empty file system command :- mkdir ramdiskmountpoint;mount -t ext2 -o loop ramdisk ramdiskmountpoint
  • copy the tinytarget(uclibc and busybox) to mounted file system command :- cp -a tinytarget/* ramdiskmountpoint/
  • unmount the mount point and delete it command :- umount ramdiskmountpoint;rm -rf ramdiskmountpoint
  • compress the new file system present in raddiskfile command :- gzip -v9 ramdisk
  • Copy ramdisk.gz to arch/XXXX/ramdisk/ramdisk.gz where XXXX is target name. ex. ppc,mips,arm,etc.,
  • Enable the following options in kernel config : ramdisk and initial ramdisk