Saturday, November 14, 2009

Creating specific sized file

To create a specific sized file, dd command can be used. Example below will create a file named output with 10M size:


$ dd if=/dev/zero of=output bs=1M count=10
where bs is block size, and count is number of blocks to be created

The output:

$ ls -lh output
-rw-r--r-- 1 user user 10M 2009-11-14 06:21 output

Friday, November 13, 2009

Splitting big files

To split big files, split command can be used. Below is command used to split 400MB file named bigfile into 100MB chunk files named smallfile0*


$ split -b 100M -d --verbose bigfile smallfile
creating file 'smallfile00'
creating file 'smallfile01'
creating file 'smallfile02'
creating file 'smallfile03'
where -b is for byte size, -d is for numeric suffixes and smallfile is the prefix to be used

The output is:
$ ls
bigfile smallfile00 smallfile01 smallfile02 smallfile03

To recover back the splitted files into a file named newbigfile:
$ cat smallfile0* > newbigfile


Tuesday, September 29, 2009

Restore GRUB

GRUB is a boot loader commonly used with linux operating system. It can be used to managed dual boot environment where linux and windows can coexist easily in a same machine without problem provided you install the windows OS first so that when you install linux, GRUB will overwrite Windows boot loader and automatically detect and manage both operating system the next time you boot your computer. Problems will happen if you alter your partitions outside the knowledge of GRUB, for example, you create new partition in your hard drive using windows. This will cause GRUB to automatically go into GRUB shell when boot. To restore back your GRUB is very simple, just follow easy steps below:

1. find in which partition does GRUB store its configuration file, which is your /boot partition. (hd0,2) means third partition of the first hard drive
grub> find /boot/grub/stage1
(hd0,2)

2. set the root for GRUB to be (hd0,2)
grub> root (hd0,2)

3. write GRUB to the Master boot record(MBR) of your hard drive. Change (hd0) to (hd0,2) to write GRUB to your /boot partition instead
grub> setup (hd0)

4. Reboot machine
grub> reboot

All those steps can also be used using livecd, if let say the grub shell did not come out but you cannot boot your machine or you cannot boot your linux due to messed up GRUB. just boot from livecd, open a terminal, and type "grub" as a superuser to go to GRUB shell

Thursday, August 6, 2009

Mounting Windows shared folder on linux

Mounting windows shared folder on linux is very easy provided you know the ip of the windows machine, the name of the folder that is being shared, the username and password of the windows machine. As far as I know, there are 2 ways you can mount your windows shared folder on your linux machine.

The first way:

For gnome user, type Ctrl+F2, and type smb://windows_machine_ip/shared_folder_name. For example, see below picture


You can access the folder from Places


The second way:

Using command line;

sudo mount -t cifs //windows_machine_ip/shared_folder_name /directory_to_mount -o username=username,password=userpassword

example for mounting a shared folder named MP3 on 192.168.1.110 using windows username usin and password 123456 to /home/user/mp3:

$ sudo mount -t cifs //192.168.1.110/MP3 /home/user/mp3 -o username=usin,password=123456

Your shared folder now can be accessed from /home/user/mp3


That's all friends :)

Friday, July 24, 2009

Labeling linux partition

In linux, to label a partition, there are 3 tools that can be used. The tools are e2label, tune2fs and mke2fs.

To use e2label to label the second partition of the first hardisk with label DATA:
# e2label /dev/sda2 DATA

To use tune2fs to do the similar job as above:
# tune2fs -L DATA /dev/sda2

The third tool, mke2fs is actually a tool to build ext2/ext3 filesystem. So, if you want to build the partition's filesystem as ext2/ext3 and at the same time label it, this command can be used. Be careful though, because it will delete all existing data on that particular partition
# mke2fs -L DATA /dev/sda2

To view the label that you have set, there are 3 ways which are using e2label, blkid and viewing /dev/disk/by-label.

To check using e2label:
# e2label /dev/sda2
DATA

blkid tool is even more useful, because it can list out all the partitions that you have in the machine together with their labels,uuid and filesystem type:
# blkid
/dev/sda1: LABEL="/" UUID="1CC08F13C08EF276" TYPE="ext3"
/dev/sda2: LABEL="DATA" UUID="2063f830-fe5d-438e-b727-571b313cb89e" TYPE="ext3"
/dev/sda3: TYPE="swap" LABEL="SWAP" UUID="3e266b53-42e0-4f09-8fe3-d1cf79cb5d37"

To view the /dev/disk/by-label
# ls -l /dev/disk/by-label
total 0
lrwxrwxrwx 1 root root 10 2009-07-24 05:38 / -> ../../sda1
lrwxrwxrwx 1 root root 10 2009-07-24 05:38 DATA -> ../../sda2
lrwxrwxrwx 1 root root 10 2009-07-24 05:38 SWAP -> ../../sda3

Note that the label will stay with the partition although the disk is moved to another computer.

To use it in /etc/fstab:
LABEL=/ / ext3 defaults 1 1
LABEL=DATA /DATA ext3 defaults 1 2
LABEL=SWAP swap swap defaults 0 0

Monday, June 22, 2009

Hyper terminal for linux

For people that manage hardware devices such as storage, routers and many more using Microsoft Windows, the term hyper terminal is a familiar thing. They use hyper terminal to connect to all the devices mentioned above using serial cable. But what if you have to manage all those devices using linux?

The answer is, linux has 2 alternatives to hyper terminal; one is command line based and the other is GUI based. Let me start with the command line tool first. It is called minicom. You can install this tool using package manager of your linux machine. In fedora/redhat/centos:

# yum install minicom

Running it for the first time requires you to do some settings by running below command as root:

# minicom -s

Picture below shows the screen after command minicom -s


This is where you set the baudrate, serial device you want to use etc. After finish with the setting, save it so that you do not have to do it every time. You can save it to default .dfl file, with the name of .minirc.dfl in your home folder, or you can specify the name and location yourselves. To change the saved setting, just use the above command back.

The second tool is called cutecom, a graphical serial terminal. To install it on fedora,centos or redhat:

# yum install cutecom

It is easier to use since it has GUI. Picture below shows cutecom main screen, where you can set your device, parity, baudrate etc.

Monday, June 15, 2009

Validate your downloaded files using md5

When you download files, especially iso for your favourite linux distro, how do you validate the files is properly downloaded or not? This is where md5 checksum comes into picture. From manpage of md5sum; md5sum is used to compute and check MD5 message digest. What is MD5 exactly?

"MD5 is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. However, it has been shown that MD5 is not collision resistant; as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property. An MD5 hash is typically expressed as a 32 digit hexadecimal number "

The above definition is extracted from www.wikipedia.org

To make it simple, the usage to this magnificent tool is just to validate the correctness of any file that we download from the internet. This is very important especially when we downloaded big files such as linux distro iso so that we won't burn a corrupted iso. The easiest way to check the correctness of the iso is by using md5sum

How to use:

to check the md5sum of a file
$ md5sum filename

Example:

Lets say we have a file named test.txt. Run the md5sum command to this file:
$ md5sum test.txt
d968a9cf53f4cb21b06a888e2a6f4cb6

Compare the string that we got with the md5 string provided by the provider of the file. If similar, test.txt is in good order.


If you have more than one file to be checked, use flag -c to check from file. Example, we have 2 files, test.txt and test2.txt, and we want to check both using md5 validation. First, create a file that follow the format where first column is for md5 string, then 2 spaces(press spacebar 2 times) and the next column is the name of the file like below:

d968a9cf53f4cb21b06a888e2a6f4cb6 test.txt
52dba85eb1460f265ddf3de51e91652a test2.txt

Save the file as md5sum.txt

Place the md5sum.txt with test.txt and test2.txt in a same folder

Run md5sum command to check:
$ md5sum -c md5sum.txt

If success, the output will be like this:

test.txt OK
test2.txt OK

You are done with the testing and test.txt and test2.txt is validated as correct using MD5 checksum :)

Monday, May 25, 2009

Setting ip in debian/ubuntu server

To setup ip for debian or ubuntu server is not easy for someone who is not familiar with command line. For normal ubuntu desktop user, there is always NetworkManager applet to easily set up the network using GUI, which is very easy. There are 2 ways to setup ip for debian or ubuntu server. One will set the ip temporarily and the otehr one will permanently set the ip. I will show both :)

To set ip temporarily using ifconfig and route commands

1. Run the command below to set ip and netmask
$ sudo ifconfig eth0 10.20.1.10 netmask 255.255.255.0 up
where eth0 is the name of the interface, 255.255.255.0 is the netmask and up to activate the interface

2. run route command to set default gateway
$ sudo route add default gw 10.20.1.1
where 10.20.1.1 is your gateway ip

3. You can check the configuration that you have setup using commands route -n to see the gateway and ifconfig to see the ip address

Done.


To permanently set up the ip and gateway, you have to edit /etc/network/interfaces. It is advisable if you backup the existing interfaces file, if it is available.

1. Backup /etc/network/interfaces
$ sudo cp /etc/network/interfaces /etc/network/interfaces.bak

2. Open the /etc/network/interfaces using your favorite text editor
$ sudo vi /etc/network/interfaces

3. Add the below setting to add ip, netmask and gateway

# The loopback interface
auto lo
iface lo inet loopback

# The first network card - this entry was created during the Debian installation
# (network, broadcast and gateway are optional)
auto eth0
iface eth0 inet static
#set your static IP below

address 10.20.1.10
#set your default gateway IP here
gateway 10.20.1.1
# set your netmask, network and broadcast ip below
netmask 255.255.255.0
network 10.20.1.0
broadcast 10.20.1.255

4. Save your configuration and restart network
$ sudo /etc/init.d/network restart

5. Your debian/ubuntu server machine is now operating with the new ip. Check ip and gateway using ifconfig and route -n

Sunday, May 24, 2009

Setting ip in redhat,fedora and centos

For redhat, fedora and centos, to set ip temporarily, you can use ifconfig and route commands(you have to be root to do these steps)

1. Run the command below to set ip and netmask
# ifconfig eth0 10.20.1.10 netmask 255.255.255.0 up
where eth0 is the name of the interface, 255.255.255.0 is the netmask and up to activate the interface

2. run route command to set default gateway
# route add default gw 10.20.1.1
where 10.20.1.1 is your gateway ip

3. You can check the configuration that you have setup using commands route -n to see the gateway and ifconfig to see the ip address


To setup the ip and gateway permanently, follow below steps (You have to be root to do these steps)

1. Go to folder /etc/sysconfig/network-scripts
# cd /etc/sysconfig/network-scripts

2. Backup your existing configuration
# cp ifcfg-eth0 ifcfg-eth0.bak

3. Open ifcfg-eth0 with your favorite editor
# vi ifcfg-eth0

4. Add below line to the ifcfg-eth0 file to setup your ip

BOOTPROTO=static
DEVICE=eth0
IPADDR=10.20.1.20
NETMASK=255.255.255.0
NETWORK=10.20.1.0
ONBOOT=yes
TYPE=Ethernet

5. Save the file

6. Add below line to /etc/sysconfig/network to set your gateway
GATEWAY=10.20.1.1

7. Save and restart network
# /etc/init.d/network restart

8. Done. Check your newly created ip using ifconfig and gateway using route -n commands

Monday, April 27, 2009

MSCOSCONF2009

MSC Malaysia Open Source Software Conference(MSCOSCONF2009) is an open source conference that will be held in Malaysia on 31 May - 3 June, 2009, organized by MAMPU and MDEC of Malaysia. There will be great speakers presenting their stuff on the event, great activities and much more. For further details, visit http://www.mscmalaysia.my/osconf and http://www.mscoscon.my.

Tuesday, April 14, 2009

Installing virtualbox 2.2.0 on ubuntu 8.10

To install virtualbox is fairly easy. Just follow the instructions below:

1. Open /etc/apt/sources.list and add this line deb http://download.virtualbox.org/virtualbox/debian intrepid non-free

2. Import sun public-key and register it using apt-key (wget is for downloading, apt-key is for registering the key to your machine)
$
wget -q http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc -O - | sudo apt-key add -
OK

3. Update your system's package index file
$ sudo apt-get update

4. Install virtualbox 2.2
$ sudo apt-get install virtualbox-2.2

Done, that's all :)


Friday, April 10, 2009

Adding local directory to apt sources.list

I faced this problem when trying to install the latest version of lyx, frontend for the famous LaTeX/TeX document processor. Lyx is available at the ubuntu main repo, but the version is kind of outdated. After checking at http://www.getdeb.net, a latest version is available. After downloading the lyx and lyx-common package from here, I tried to install both of them using "dpkg -i *.deb" but they have unsatisfied dependencies. One of the way to solve this is to download all the dependencies and put them inside one directory, and run "dpkg -i *.deb" but I think I wanna try another solution which is using apt to install them. This is where "Adding local directory to apt sources.list" comes into the picture. The steps will be explained below:

1. Create the directory to put all the deb files you downloaded, in this case I'll create /home/foo/debs
$ mkdir /home/foo/debs

2. Put all the downloaded deb files into the directory
$ mv /home/foo/Desktop/*.deb /home/foo/debs

3. Check the current priorities and section for the package, find entry named Section and Priority:
$ dpkg --info lyx_1.6.2-1~getdeb1_i386.deb

Here are some of the info:
Package: lyx

Section: editors

Priority: optional

Homepage: http://www.lyx.org/


4. Create override file. Override file is used to override the default priority and section setting of the package (refer to no. 3 for guide on how to check section and priority). Override file contains 3 columns: package, priority, section. Package is the name of the package, priority is low, medium, high or optional and section is the section to which it belongs.
Example of override file content:

## Override
#Package priority section

lyx low editors


5. Create Packages.gz inside /home/foo/debs
$ cd /home/foo/debs
$ sudo dpkg-scanpackages . override | gzip -c9 > Packages.gz

6. If you are too lazy to do the override file, you do not have to. Just change the "dpkg --scanpackages" command above to this:
$ cd /home/foo/debs
$ sudo dpkg-scanpackages . /dev/null | gzip -c9 > Packages.gz
If you follow this path, ignore step 4 and 5

7. Add this line to /etc/apt/sources.list
deb file:///home/foo/debs /

8. Resynchronize the package index files from their sources
$ sudo apt-get update

9. Install your application (in this case, lyx)
$ sudo apt-get install lyx


Apt will fetch the deb files from your local file directory also. Congratulations, you just created a local file repository in your own computer :)

Tuesday, March 31, 2009

Suse forgotten root password

In suse, if you forgot your root password, you can go to the single mode as usual. Steps are explained below:

1. Reboot the machine
2. When Startup Options(blue background in SLES) appear, choose Failsafe mode
3. In the Boot Options, append init=/bin/sh at the end of the line
4. Press Enter to boot
5. You will be presented with a shell. Change your password using command passwd root
6. Reboot the machine. root is now can be accessed using your new password

Wednesday, March 25, 2009

Changing default shell in ubuntu

I faced this problem when I created a new account using command line where the default shell of my new account is /bin/sh. After googling around, I found 2 useful solutions which are listed below:

1. Change user entry in /etc/passwd
a) edit /etc/passwd using any editor

  • $ vi /etc/passwd
b) find the line that belongs to the user (foo) that we about to modify
  • foo:x:1001:1001::/home/foo:/bin/sh
c) change from /bin/sh to /bin/bash
  • foo:x:1001:1001::/home/foo:/bin/bash
d) save
e) Logout and login back

2. Use chsh command
a) type chsh
  • $ chsh
b) You will be asked for password. Enter your password
c) This screen will appear
  • Enter the new value, or press ENTER for the default
    Login Shell [/bin/sh]:
d) Put /bin/bash at the menu and press Enter

Done :)

Thursday, March 19, 2009

Turn off automatic first capital letter in openoffice

By default, openoffice will automatically turn the first letter to capital in a sentence. This feature is very useful but sometimes you do not want your first letter in your sentence to be capital. There is a setting that you have to turn off to make this happen. This steps have been tested on openoffice 3.

  1. go to Tools -> AutoCorrect
  2. go to Options tab
  3. Uncheck Capitalize first letter of every sentence under [T] which means disable capitalize first letter of every sentence when typing
  4. Click on OK
Done :)

Tuesday, March 3, 2009

Installing microsoft truetype font on ubuntu

The reason we need this microsoft truetype fonts is that we want the documents created in microsoft office to be nicely opened in openoffice. To install microsoft trutype fonts:

1. Run the command below to install msttcorefonts. You can also use synaptics package manager to install if you are not familiar with terminal

$ sudo apt-get install msttcorefonts

2. To immediately use the new font, run the command below to rebuild back font information cache files

$ sudo fc-cache -fv

3. Your new fonts are ready to be used. Fonts that are already installed are:

  • Andale Mono
  • Arial Black
  • Arial (Bold, Italic, Bold Italic)
  • Comic Sans MS (Bold)
  • Courier New (Bold, Italic, Bold Italic)
  • Georgia (Bold, Italic, Bold Italic)
  • Impact
  • Times New Roman (Bold, Italic, Bold Italic)
  • Trebuchet (Bold, Italic, Bold Italic)
  • Verdana (Bold, Italic, Bold Italic)
  • Webdings
To add another font besides listed above, just copy the fonts files, and put it inside ~/.fonts/. You can find the fonts files from sourceforge

Monday, February 23, 2009

Rebuild corrupted dbmail account

Symptoms of corrupted dbmail account are slow to open account and if manage to open account, it will take forever just to open the inbox. Here are the steps to rebuild back the account using joe's email account

1. You have to backup the the user's inbox. Use command "dbmail-export" to export mailbox to mbox file. For better management, export the mailbox to home folder.
# cd /home
# dbmail-export -u joe

2. A few mbox files will be generated depending on how many folders you have in your email. The mboxs will be placed in a folder named with your username, in this case, joe
#ls /home

3. Clear up the username mailbox using "dbmail-users". -e is for clearing mailbox
# dbmail-users -e joe

4. Delete the user. -d is for deleting user
# dbmail-users -d joe

5. Create back user. -a is for add user, -w for password, -p for password type and -s for aliases
# dbmail-users -a joe -w joe123456 -p md5 -s joe@example.com

6. Download dbmail tarball from here. Extract and you can see a script named mailbox2dbmail in contrib folder. Use that script to migrate back the mbox files to dbmail. For easy usage, copy the mailbox2dbmail script to /usr/local/bin. -u is for username, -t for type of input, -m for input filename and -b is for the name you want the mailbox to appear in your email
# cd /home/joe
# mailbox2dbmail -u joe -t mbox -m INBOX.mbox -b INBOX

7. Go to your joe's webmail and you can see the INBOX is already there. Repeat step 6 for all your mailboxes

Friday, February 20, 2009

CentOS/Fedora forgotten password

What to do if you forgot the password for your CentOS/Fedora/Redhat machine?? Here are some simple steps to change back the password by entering into single user mode of your machine provided you do not forgotten your grub password if you have set it ;)

  1. Reboot your machine
  2. Press 'Esc' key once grub starts loading
  3. Select your kernel press 'e' on one of the kernel to edit the kernel parameter
  4. Press 'e' on the line that starts with 'kernel /vmlinuz...'
  5. Append ''single" or "1" at the end of the line
  6. Press 'Enter'
  7. Press 'b' to boot from the appended kernel
  8. You are now in the single user mode of your linux machine once you get to the shell. You can now change the password of your account using command passwd
  9. Reboot back your machine normally
  10. You can now log in to your machine using your new password
:)

Tuesday, February 17, 2009

DNS lookup

To find an ip address for a domain, we need to do dns lookup. A few tools available for us to use in linux, but in this article I will give brief explanation about 3 most famous tools of dns lookup, which are host, nslookup and dig. Usually if the commands are used without the optional nameserver, then the nameserver entries in /etc/resolv.conf will be used


To find ip address of a domain using host (nameserver is optional):

$ host
example:
$ host www.google.com 208.67.222.222

To find the domain that belongs to an ip address using host (nameserver is optional):

$ host
example:
$ host 202.188.0.133 ns1.tm.net.my


To find ip address of a domain using nslookup (nameserver is optional):

$ nslookup
example:
$ nslookup www.google.com 208.67.222.222

To find the domain that belongs to an ip address using nslookup (nameserver is optional):

$ nslookup
example:
$ nslookup 202.188.0.133 208.67.222.222

nslookup also have interactive mode that you can access by simply typing
$ nslookup


To find ip address of a domain using dig (nameserver is optional):

$ dig @
example:
$ dig @ns1.tm.net.my www.google.com

Thursday, February 5, 2009

Unmounting busy device

You have an external drive attached to your linux machine. Then after finishing all your job, you try to unmount it, a message come out saying the device is busy.

# umount /media/disk
umount: /media/disk: device is busy
umount: /media/disk: device is busy

So what could possibly the cause?

1. You are inside the disk. Check your working directory using pwd

# pwd
/media/disk

2. Some files are accessing the disk. Check list of open files using lsof

# lsof | grep /media/disk

3. Some processes areaccessing the disk. Use fuser to check

# fuser -m /media/disk

What to do?

1. For case 1, just go to another directory

# cd
# umount /media/disk

2. For case 2, check the files that are accessing the disk and kill it

# lsof | grep "/media/disk"
vim 2693 pingu cwd DIR 8,4 4096 73729 /media/disk
# kill -9 2693
# umount /media/disk

3. For case 3, find the process that accessing the disk and kill it

# fuser -m /media/disk
/media/disk: 2693

# ps -e | grep 2693
2693 pts/0 00:00:00 vim
# kill -9 2693
# umount /media/disk

4. For case no 3 also, you can use fuser -k to kill the process that bugging the disk directly (Thanx to mr. linuxmalaysia for the comment)

# fuser -k /media/disk
#umount /media/disk


Hope this will be useful

Wednesday, January 14, 2009

GUI media converter

ffmpeg is a very powerful media converter but unfortunately it is text based. For people like me who use terminal as much as GUI, using ffmpeg in its original nature, which is text based is ok. You can refer to my post about converting flv to avi using ffmpeg. But for people who want to harness the power of ffmpeg yet not familiar of using terminal, mobile media cenverter from miksoft is a good option. This application is a GUI for mmpeg, so you can expect some of the goodness of ffmpeg if not all of them. You can download this application here, where it is available for windows and linux. For debian based linux user, the application is available in .deb form where you can install easily. For other linux user, a little bit of extra work has to be done to start using this application.

A few of mobile media converter features are drag n drop, using ffmpeg engine, it is free of charge, it has integrated youtube downloader and it is available for linux and windows. Supported formats are:
- Desktop Audio: mp3, wma, ogg, wav
- Mobile Audio: amr, awb
- Desktop Video: wmv, mpeg, wmv, avi, flv
- Mobile Video: 3gp, mp4

Installation instruction is available here under Help.

Below are screenshots of the application in ubuntu 8.10



and windows vista

Monday, January 5, 2009

Searching or finding files owned by user

A few days back, I have to find in my machine files that belong to a user or to a group. The general form are like below:

# find location -user username -group groupname

To find files in / directory owned by user foo:

# find / -user foo

To find files in / directory owned by user in group bar:

# find / -group bar

To find files in directory / owned by user foo and group bar:

# find / -user foo -group bar

You can also use uid or gid
To find files belong to uid 500:

# find / -uid 500

To find files that belong to gid 500

# find / -gid 500