Thursday, March 19, 2015

Remove all files in a directory except one or two

In Linux, have you ever wondered what is the command to execute in terminal to delete all files in a directory except one or two ? Its,

 find ! -name 'file.txt' -type f -exec rm -f {} +  
 
This command will remove all files except file.txt.

To remove directory, change type -f to type -d and add -r option to rm as below.

 find ! -name 'file.txt' -type d-exec rm -rf {} +  

Please becareful before executing command. If you accidentally type in an important folder, you may loose all contents.

Always try to understand to learn about each term before executing it :).

How to open chm files in Ubuntu 14.04. Which package to install.

I have been searching for package(s) to install to open chm files. Below command worked like magic.

 sudo apt-get install xchm  

While install press Y. After installation,click on any  *.chm file it will open automatically.

Sunday, March 1, 2015

Building Kernel Source

This article just briefs about downloading and installing Linux Kernel Source.
Of-course, there are many articles available in net. I would like to make this as simple as possible.

Steps to follow

1. Install Git
 sudo apt-get install git  

2. Download Linux Source (in here I am downloading 2.6 version) in to a directory
 $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 
 $ git pull 

3.Configure your Kernel by executing
 $make defconfig  
 $make oldconfig  

Some times, we can use "$make  menuconfig" a graphic utility to configure Kernel. You may face fatal error problem while executing this command.

4.Now build your kernel
 $make  

This may take a while. So relax, we have done a lot till now :)

To improve Kernel build time you can use
 $make  -jn

Here, n is the number of jobs to spawn. Usual practice is to spawn one or two jobs per processor. For example, on a 16-core machine, you might do
$ make -j32 > /dev/null

Using utilities such as the excellent distcc or kernel build time. ccache
can also dramatically improve  Kernel build time.

5. Now once the build is done, we need to find for bzImage
 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ find . -name bzImage |xargs ls -l  
 lrwxrwxrwx 1 mrtechpathi mrtechpathi   22 Mar 1 23:16 ./arch/x86_64/boot/bzImage -> ../../x86/boot/bzImage  
 -rw-rw-r-- 1 mrtechpathi mrtechpathi 5970016 Mar 1 23:16 ./arch/x86/boot/bzImage  

6.Copy this image to /boot directory as vmlinuz-2.6
 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ sudo cp ./arch/x86/boot/bzImage /boot/vmlinuz-2.6  

7.Install modules
$ sudo make modules_install

8.Now update grub using
$ sudo update-grub

Sometimes,  your grub may disappear or may not appear. To solve this check this post "Grub menu is not displayed after installing Linux".

Grub menu is not displayed after installing Linux (ubunt 14.04)

We often face an issue where Grub menu disappear after installing a new operating system.

By default, your GRUB is set to hide the OS selection menu on boot.

Basically, what you'll need to do is make the following change:

1. Open up a terminal (ctrl+alt+t) and then enter in the following command:   

$ sudo vim /etc/default/grub

2. Edit the file and comment below two lines (adding # before the lines)

GRUB_HIDDEN_TIMEOUT=0 
GRUB_HIDDEN_TIMEOUT_QUIET=true

becomes

#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=true

Save the file

3. Update the grub

$sudo update-grub

When you reboot you should see the OS Selection Menu.

Fatal error: curses.h: No such file or directory while configuring Kernel Source

While working on Kernel source, during configuring Kernel options, we  may need to use "make menuconfig" command.

We may end up with following error.

 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ make menuconfig  
  HOSTCC scripts/kconfig/mconf.o  
 In file included from scripts/kconfig/mconf.c:23:0:  
 scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: No such file or directory  
  #include CURSES_LOC  
           ^  
 compilation terminated.  
 make[1]: *** [scripts/kconfig/mconf.o] Error 1  
 make: *** [menuconfig] Error 2  

To overcome this, execute below steps

1. $ sudo apt-get update
2. $ sudo apt-get install libncurses5-dev
3. $ make menuconfig -> Works fine now !!!!

Following are my system configurations.
 No LSB modules are available.  
 Distributor ID:     Ubuntu  
 Description:     Ubuntu 14.04 LTS  
 Release:     14.04  
 Codename:     trusty  

Let me know if it worked for you :)

Accessing a Windows shared folder in Oracle VM Virtual Box

This post gives steps to access  a shared folder when you use Oracle VM Virtual box to run a Linux Virtual system on your Windows PC.

1. Make sure you have guest addons installed.notepad

2.Create a folder on the Host computer (ubuntu) that you would like to share, for example "C:/KernelTrap"

3.Boot the Guest operating system in VirtualBox.

4.Select Devices -> Shared Folders...

5.Choose the 'Add' button.

6.Select Folder path name as   "C:/KernelTrap"
   and Folder name will be automatically detected as "KernelTrap"

7. Remember this folder name "KernelTrap"

8. Optionally select the 'Make permanent' option

9. In virtual machine terminal, type:

 cd /mnt  
 sudo mkdir shared_folder  
 sudo mount -t vboxsf KerekTrap share_folder_patch 

And that's it. Don't worry about the absolute paths. You don't need them. For all practical purposes, VB will take care of the real path behind the share name, in this case KernelTrap.

Let me know if this procedure worked for you. I have tried this on Ubuntu 14.04 and it worked without any issue.