Tuesday 19 March 2019

One command solution to set up password less ssh

Use following command on system where you need password less ssh

ssh-copy-id -i <IP>

IP = IP address of host to be you want password less shh

Example:
ssh-copy-id -i 192.168.1.1

Wednesday 6 September 2017

How to find structure member offset in gdb


(gdb) print (int)&((struct A*)0)->a

Above command can be used to find structure member offset 

For example your structure is 

struct node {
  int a;
  char b;
  short c;
};

If you want to find relative offset of char b then you need to run

(gdb) print (int)&((struct A*)0)->b
$2 = 4

Tuesday 25 July 2017

Linux kernel module debugging using gdb

Choose appropriate function from stack which has failed. Suppose
function failed is "function_foo()" then you will have entry like

kernel: [<ffffffff814ec2ba>] ? function_foo+198

in stack trace. Pass corresponding debug .ko to gdb 
[root@pritam-pc]# gdb mymodule.ko.debug

(gdb) l* function_foo+198

This will give you .c file which caused failure with line number.
Suppose you got details like .c file is foo.c and line number is 122
then you can do more debugging with following command

(gdb) info line  foo.c:122

Tuesday 6 December 2016

How to disable rsyslog Rate-Limiting on Red Hat Enterprise Linux


imjournal: begin to drop messages due to rate-limiting

Is above message causing problems to you, no worries here is solution for RHEL7


Follow simple 3 steps to disable rsyslog Rate-Limiting

1. Update following variables in file /etc/systemd/journald.conf with values  shown below


    RateLimitInterval=0s
    RateLimitBurst=0


2. Update file /etc/rsyslog.conf as follows

        # File to store the position in the journal
     $IMJournalStateFile imjournal.state
    $imjournalRatelimitInterval 0


       Mostly you will have first variable set in your file already.


3. Restart rsyslogd
  
       service rsyslog restart

Friday 10 January 2014

Short description of Linux Boot Process

I am describing in short about Linux boot process.

Linux boot process steps.

1.  After running POST, BIOS executes code in first sector i.e. 512 bytes of hard disk. Note that BIOS drivers are used to access hard disk. This sector is known as boot sector. Out of these 448 bytes are used by actual boot loader code and remaining 64 bytes are reserved for partition table. Note that each partition table entry corresponds to  16 bytes of memory. So that's why we can have only 4 primary partitions on hard disk.

2.  Boot loader code can be saved in ROM and some embedded systems do this but in typical Linux box it is on hard disk.

3.  Job of this 448 bytes of boot sector code is to handle basic functionality of boot loader and pass control to actual boot loader code. This activity is normally termed as second stage of boot loader. Please note every partition has boot sector at its beginning.

4. Now this code is responsible to actually display boot loading options to user and load kernel. I multiple OS are installed on machine then this code might defer us to different active partition depending on choice made to load OS in boot loader GUI. Then boot loader of other OS is loaded. This process is knows as chain loading.

5. Note that vmlinuz and initrd needs to loaded in order to proceed. Addresses of these files are hard coded and they are always under /boot directory. All contents of /boot are saved contiguous to boot loader on hard disk.

6. Now which one is used first...?  vmlinuz is first uncompressed and init command is executed. It then mounts initrd image as initial root file system which contains basic set of modules needed to mount actual root file system.

7. Then again control is taken by init process and linuxrc is executed in the end. 

Friday 27 December 2013

What does # in the output of "uname -a" or "uname -v" denote ?


Following is output of "uname -a" command


[pbankar@linux-node-1 linux-3.9.2]$ uname -a
Linux linux-node-1 3.9.2 #6 SMP Tue Jul 30 02:24:56 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux


       I got detailed information regarding all field of output of uname but one. I was not able to find what exactly #6 means in above output. After some analysis I found this value is taken from .version file at top of kernel source tree.
       First time when you compile kernel source and use it, # is 1 next time when you edit some file from same source or add patch to kernel and compile it again keeping kernel string same, # becomes 2. While compiling you can see following message when make is about to complete its work

Kernel: arch/x86/boot/bzImage is ready  (#7)

The same # number is propagated to uname output. I doubt whether kernel keeps all bzImages. For above example where # is 7 I looked into directory arch/x86/boot/ but there is only one bzImage. I also don't think these different # versions can be kept at a time on system. For one exact kernel only one # can be installed on system. It will only upgrade existing #

Wednesday 30 January 2013

Extracting single file from rpm/deb packages

   Sometimes rpm/deb package installation fails due to other dependent rpm/deb packages. It becomes very hectic to resolve all dependencies. But if you need some files from package and don't want pure installation of whole rpm then don't waste your time, you can use tools like rpm2cpio to extract single file from rpm package. I came across such need while using crash tool, which requires vmlinux file as one of the arguments. On Redhat this file is shipped with kernel-debuginfo-common-x.y.z.rpm package but to install it you may need to install other rpms because of dependencies between two. But you can extract required file by following way :

 Extracting file from rpm package:

For example if you want to extract contents of unifdef-1.171-5.fc6.x86_64.rpm then use following command


[pritam@pritam-pc]$ rpm2cpio unifdef-1.171-5.fc6.x86_64.rpm | cpio -idmv
./usr/bin/unifdef
./usr/bin/unifdefall.sh
./usr/share/man/man1/unifdef.1.gz
47 blocks

This will create required files in your *current directory*. If you want to extract single file lets say /usr/bin/unifdef in above case then use following command,

[pritam@pritam-pc]$ rpm2cpio unifdef-1.171-5.fc6.x86_64.rpm | cpio -idmv ./usr/bin/unifdef
./usr/bin/unifdef
47 blocks
 
This will only extract /usr/bin/unifdef in your *current directory* 


 Extracting file from deb package:

   DEB files are ar archives, which always contains the three files — debian-binary, control.tar.gz, and data.tar.gz. We can use ar command and tar command to extract and view the files from the deb package, as shown below.
For example we are extracting initramfs-tools.deb package

[pritam@pritam-pc]$ ar -vx initramfs-tools.deb
x - debian-binary
x - control.tar.gz
x - data.tar.gz

This will produce above three files in your *current directory*.
Then you can extract data.tar.gz to get required files

[pritam@pritam-pc]$ tar -xvzf data.tar.gz