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