Tuesday, December 3, 2013

verify kernel compile macro in running linux


How to check whether a kernel compile macro is enabled on a running linux machine?

root@babu-VirtualBox:~/tools/stk_corruption/stk_overflow_lkm# grep OVERFLOW /boot/config-3.13.5
CONFIG_HAVE_DEBUG_STACKOVERFLOW=y
# CONFIG_DEBUG_STACKOVERFLOW is not set
root@babu-VirtualBox:~/tools/stk_corruption/stk_overflow_lkm#


Monday, December 2, 2013

How to edit boot options during linux booting?


The following steps worked for me in a Virtualbox Ubuntu VM:
  • During the boot up menu, select the kernel version you want to boot with: 
                        


                        

  • Press 'e' to enable editing of this line:
                        
  • Go to "linux" bootline & add the boot options. I am adding slub_debug option in my screen:
                        


                        

  • Do these boot options get retained across reboot?
          No. 

Sunday, December 1, 2013

How to - Linux Kernel Compilation in Ubuntu VM/VirtualBox


I recently compiled linux kernel in a Virtualbox VM. Here are the steps I used to compile a custom linux kernel. These steps worked for me in Ubuntu 13.10 distribution.



Check the linux version of your VM:



babu@babu-VirtualBox:~$ uname -a
Linux babu-VirtualBox 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux
babu@babu-VirtualBox:~$ 

Switch to root mode:


babu@babu-VirtualBox:~$ sudo -s
[sudo] password for babu: 
root@babu-VirtualBox:~#

Download the linux sources for the matching version to /usr/src:
root@babu-VirtualBox:~# cd /usr/src
root@babu-VirtualBox:/usr/src# 
root@babu-VirtualBox:/usr/src# ls
linux-headers-3.11.0-12          vboxguest-4.3.6
linux-headers-3.11.0-12-generic
root@babu-VirtualBox:/usr/src# wget http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.11-tar.bz2
.
.
root@babu-VirtualBox:/usr/src#

In my case, I didn't have tarball for 3.11.0 at http://www.kernel.org/pub/linux/kernel/v3x/. So, I got linux-3.11.tar.bz2 instead:
root@babu-VirtualBox:/usr/src# ls 
linux-headers-3.11.0-12          vboxguest-4.3.6
linux-3.11.tar.bz2  linux-headers-3.11.0-12-generic
root@babu-VirtualBox:/usr/src# 

Extract the source to /usr/src:
root@babu-VirtualBox:/usr/src# tar -xvf linux-3.11.tar.bz2 -C .
.
.
root@babu-VirtualBox:/usr/src# ls
linux-3.11          linux-headers-3.11.0-12          vboxguest-4.3.6
linux-3.11.tar.bz2  linux-headers-3.11.0-12-generic
root@babu-VirtualBox:/usr/src# 

Install compilation tools necessary:

apt-get update
apt-get install gcc
apt-get install make
apt-get install ncurses-*

Select the kernel configuration options you need:

root@babu-VirtualBox:/usr/src# cd linux-3.11/
root@babu-VirtualBox:/usr/src/linux-3.11# make menuconfig

Compile & Install the Kernel:

root@babu-VirtualBox:/usr/src/linux-3.11# make     <-- This step took approximately 2 hours on my dual core VM.
.
.
root@babu-VirtualBox:/usr/src/linux-3.11#  make modules <-- This step took approximately 2 minutes.
.
.
root@babu-VirtualBox:/usr/src/linux-3.11# make modules_install  <-- This step took approximately 10 minutes.
.
.
root@babu-VirtualBox:/usr/src/linux-3.11# make install
.
.
root@babu-VirtualBox:/usr/src/linux-3.11#

Initrd creation & GRUB modification:

I didn't have to create initrd image or a grub entry. An initrd image was already generated in /boot directory & my new image was already in /boot/grub/grub.cfg. I guess grub2 made this step automatic?


Reboot:


/sbin/reboot

Select the new custom created kernel during bootup:

Before the VM boots up, hold the shift key to get the bootloader options list. Then, select "Advanced Options for Ubuntu":


                    















Then in the next menu, select your custom kernel:

                    















Verify that your VM indeed is running the new custom kernel:

babu@babu-VirtualBox:~$ uname -a
Linux babu-VirtualBox 3.11.0 #3 SMP Fri Feb 14 10:54:07 PST 2014 i686 i686 i686 GNU/Linux
babu@babu-VirtualBox:~$ 

Thats it. Hope this helps.



Monday, November 18, 2013

I-nex & lshw - GUI based tool for linux system information

In my earlier post, I covered cli commands that can be used for inspecting system information in linux. I also covered GUI based tools - sysinfo and hardinfo.

I tried two more GUI based tools - I-nex & lshw-gtk. In particular, I liked I-nex. I will try covering these tools later.

Sunday, November 17, 2013

sysinfo - GUI based tool for linux system information


In my earlier post, I covered cli commands that can be used for inspecting system information in linux. I also covered GUI based tools - hardinfoIn this post, I will cover sysinfo - a GUI based tool for inspecting system info.

This tool wasn't available by default in Ubuntu 13.10. I installed it manually - apt-get install sysinfo. After this, I typed sysinfo at command prompt to open GUI screen. Below are some screens that help inspect the system info:








Saturday, November 16, 2013

hardinfo - GUI based tool for linux system information


In my earlier post, I covered cli commands that can be used for inspecting system information in linux. I also covered GUI based tools - sysinfoIn this post, I will cover hardinfo - a GUI based tool for inspecting system info.

This tool wasn't available by default in Ubuntu 13.10. I installed it manually - apt-get install hardinfo. After this, I typed hardinfo at command prompt to open GUI screen. Below are some screens that help inspect the system info:







Friday, November 15, 2013

Linux System Info Commands


In this post, I will cover the cli commands that can be used to get system information. I will also cover some GUI tools in my upcoming posts. Embedded systems do not have GUI capabilities & hence the following commands would be handy despite the availability of various GUI based tools.

CPU Info

How many processors does the system have?

Method1:
      root@babu-VirtualBox:~# grep processor /proc/cpuinfo
      processor     : 0
      processor     : 1


               root@babu-VirtualBox:~# 

Method2:
      root@babu-VirtualBox:~# lscpu | grep "CPU(s):"
      CPU(s):                2
      root@babu-VirtualBox:~# 

What processor make/vendor, speed?

Method1:
      root@babu-VirtualBox:~# grep "model name" /proc/cpuinfo | unique   <-- architecture specific, but works for intel processors
      model name   : Intel(R) Core(TM) i7-3540M CPU @ 3.00GHz
      root@babu-VirtualBox:~# 

Method2:
      root@babu-VirtualBox:~# lscpu | grep Vendor
      Vendor ID:             GenuineIntel
      root@babu-VirtualBox:~# 

      root@babu-VirtualBox:~# lscpu | grep MHz
      CPU MHz:               2976.472
      root@babu-VirtualBox:~# 

What is processor type/architecture?
Method1:
      root@babu-VirtualBox:~# uname -p
      i686
      root@babu-VirtualBox:~# 
      
      root@babu-VirtualBox:~# uname -m   
      i686

      root@babu-VirtualBox:~#
Method2:
      root@babu-VirtualBox:~# arch <-- is this installed kernel or processor type?
      i686
      root@babu-VirtualBox:~# 
Method3:
      root@babu-VirtualBox:~# lscpu | grep Architecture
      Architecture:          i686
      root@babu-VirtualBox:~# 

Is the processor 32-bit or 64-bit or both? (this is different from whether the running OS  is 32-bit or 64-bit)


root@babu-VirtualBox:~# lscpu | grep "CPU op"
CPU op-mode(s):        32-bit
root@babu-VirtualBox:~# 

What is the endian-ness of the processor?

root@babu-VirtualBox:~# echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}'
1
root@babu-VirtualBox:~# 
    <-- 0 if Big endian, 1 if little endian

root@babu-VirtualBox:~# lscpu | grep "Byte"
Byte Order:            Little Endian
root@babu-VirtualBox:~# 

RAM Info

What is the RAM size?
Method1:
      root@babu-VirtualBox:~# cat /proc/meminfo | grep MemTotal
      MemTotal:        1026276 kB
      root@babu-VirtualBox:~# 
Method2:
      root@babu-VirtualBox:~# free -m
                 total              used       free     shared    buffers     cached
Mem:          1002        732        269          0         43        431
-/+ buffers/cache:        257        744
Swap:          510         110        400
root@babu-VirtualBox:~# 

Disk Info

What is the size of the disk?
root@babu-VirtualBox:~# df | grep '^/dev/*' | awk '{s+=$2} END {print s/1048576}'
54.0081          <--- in GB
         root@babu-VirtualBox:~#


root@babu-VirtualBox:~# inxi -D
Drives:    HDD Total Size: 59.6GB (23.8% used) 1: id: /dev/sda model: VBOX_HARDDISK size: 59.6GB 
root@babu-VirtualBox:~#
   
Is the disk SSD or HDD? 
         root@babu-VirtualBox:~# cat /sys/block/sda/queue/rotational
        1         <---  1 for hard disks and 0 for an SSD
         root@babu-VirtualBox:~# 

OS Info


What is the OS distribution?

root@babu-VirtualBox:~# head -n1 /etc/issue
Ubuntu 13.10 \n \l
root@babu-VirtualBox:~# 

root@babu-VirtualBox:~# cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=13.10
DISTRIB_CODENAME=saucy
DISTRIB_DESCRIPTION="Ubuntu 13.10"
NAME="Ubuntu"
VERSION="13.10, Saucy Salamander"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 13.10"
VERSION_ID="13.10"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
root@babu-VirtualBox:~# 

root@babu-VirtualBox:~# lsb_release -a
No LSB modules are available.
Distributor ID:           Ubuntu
Description:   Ubuntu 13.10
Release:         13.10
Codename:    saucy
root@babu-VirtualBox:~# 

What is the linux kernel version?
root@babu-VirtualBox:~# uname -r
3.11.0-12-generic
          root@babu-VirtualBox:~#


root@babu-VirtualBox:~# cat /proc/version 
Linux version 3.13.5 (root@babu-VirtualBox) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) ) #2 SMP Tue Mar 25 00:40:49 PDT 2014
root@babu-VirtualBox:~# 

Is the OS 32-bit or 64-bit?
root@babu-VirtualBox:~# uname -a
Linux babu-VirtualBox 3.13.5 #1 SMP Wed Mar 5 12:34:20 PST 2014 i686 i686 i686 GNU/Linux
root@babu-VirtualBox:~# 
          <-- In case of 64 bit, we get x86_64. In case of 32-bit, we get i386/i486/i586/i686

root@babu-VirtualBox:~# file /sbin/init   (or any binary in /bin directory)
/sbin/init: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xc0d86a25a7abb14cad4a65a1f7d03605bcbd41f6, stripped
root@babu-VirtualBox:~# 
        <--- 32-bit above indicates 32 bit. 64 bit above indicates 64 bit.

root@babu-VirtualBox:~# getconf LONG_BIT
32         <----- 32, if OS is 32 bit - 64, if OS is 64 bit
root@babu-VirtualBox:~# 
            

More detailed info about the system:
root@babu-VirtualBox:~# lscpu
Architecture
: i686
CPU op-mode(s)
: 32-bit
Byte Order
: Little Endian
CPU(s)
: 2
On-line CPU(s) list
: 0,1
Thread(s) per core
: 1
Core(s) per socket
: 2
Socket(s)
: 1
Vendor ID
: GenuineIntel
CPU family
: 6
Model
: 58
Stepping
: 9
CPU MHz
: 2976.472
BogoMIPS
: 5952.94
L1d cache
: 32K
L1d cache
: 32K
L2d cache
: 6144K

root@babu-VirtualBox:~# 

root@babu-VirtualBox:~# cat /proc/cpuinfo
processor
: 0
vendor_id
: GenuineIntel
cpu family
: 6
model
: 58
model name
: Intel(R) Core(TM) i7-3540M CPU @ 3.00GHz
stepping
: 9
cpu MHz
: 2976.472
cache size
: 6144 KB
physical id
: 0
siblings
: 2
core id
: 0
cpu cores
: 2
apicid
: 0
initial apicid
: 0
fdiv_bug
: no
f00f_bug
: no
coma_bug
: no
fpu
: yes
fpu_exception
: yes
cpuid level
: 5
wp
: yes
flags
: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht nx rdtscp constant_tsc pni ssse3
bogomips
: 5952.94
clflush size
: 64
cache_alignment
: 64
address sizes
: 36 bits physical, 48   bits virtual
power management:



processor
: 1
vendor_id
: GenuineIntel
cpu family
: 6
model
: 58
model name
: Intel(R) Core(TM) i7-3540M CPU @ 3.00GHz
stepping
: 9
cpu MHz
: 2976.472
cache size
: 6144 KB
physical id
: 0
siblings
: 2
core id
: 1
cpu cores
: 2
apicid
: 1
initial apicid
: 1
fdiv_bug
: no
f00f_bug
: no
coma_bug
: no
fpu
: yes
fpu_exception
: yes
cpuid level
: 5
wp
: yes
flags
: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht nx rdtscp constant_tsc pni ssse3
bogomips
: 5952.94
clflush size
: 64
cache_alignment
: 64
address sizes
: 36 bits physical, 48   bits virtual
power management:

root@babu-VirtualBox:~# 

To install inxi tool in ubuntu, I had to do these:

root@babu-VirtualBox:~# inxi -b
System:    Host: babu-VirtualBox Kernel: 3.11.0-12-generic i686 (32 bit) Desktop: N/A Distro: Ubuntu 13.10
Machine:   System: innotek product: VirtualBox version: 1.2 serial: 0 
           Mobo: Oracle model: VirtualBox version: 1.2 serial: 0 Bios: innotek version: VirtualBox date: 12/01/2006
CPU:       Dual core Intel Core i7-3540M CPU (-MCP-) clocked at 2976.472 MHz 
Graphics:  Card: InnoTek Systemberatung VirtualBox Graphics Adapter 
           X.org: 1.14.3 drivers: ati,vboxvideo (unloaded: fbdev,vesa) tty size: 70x24 Advanced Data: N/A for root 
Network:   Card: Intel 82540EM Gigabit Ethernet Controller driver: e1000 
Drives:    HDD Total Size: 59.6GB (23.8% used)
Info:      Processes: 171 Uptime: 8:45 Memory: 300.7/1002.2MB Client: Shell (bash) inxi: 1.9.12 
root@babu-VirtualBox:~#


root@babu-VirtualBox:~# inxi -F
System:    Host: babu-VirtualBox Kernel: 3.11.0-12-generic i686 (32 bit) Desktop: N/A Distro: Ubuntu 13.10
Machine:   System: innotek product: VirtualBox version: 1.2 serial: 0 
           Mobo: Oracle model: VirtualBox version: 1.2 serial: 0 Bios: innotek version: VirtualBox date: 12/01/2006
CPU:       Dual core Intel Core i7-3540M CPU (-MCP-) cache: 6144 KB flags: (nx pae sse sse2 sse3 ssse3) 
           Clock Speeds: 1: 2976.472 MHz 2: 2976.472 MHz
Graphics:  Card: InnoTek Systemberatung VirtualBox Graphics Adapter 
           X.org: 1.14.3 drivers: ati,vboxvideo (unloaded: fbdev,vesa) tty size: 70x24 Advanced Data: N/A for root 
Audio:     Card: Intel 82801AA AC'97 Audio Controller driver: snd_intel8x0 Sound: ALSA ver: k3.11.0-12-generic
Network:   Card: Intel 82540EM Gigabit Ethernet Controller driver: e1000 
           IF: eth0 state: up speed: 1000 Mbps duplex: full mac: 08:00:27:2a:c0:33
Drives:    HDD Total Size: 59.6GB (23.8% used) 1: id: /dev/sda model: VBOX_HARDDISK size: 59.6GB 
Partition: ID: / size: 55G used: 14G (26%) fs: ext4 ID: swap-1 size: 0.54GB used: 0.11GB (21%) fs: swap 
RAID:      No RAID devices detected - /proc/mdstat and md_mod kernel raid module present
Sensors:   None detected - is lm-sensors installed and configured?
Info:      Processes: 171 Uptime: 8:46 Memory: 301.2/1002.2MB Client: Shell (bash) inxi: 1.9.12 
root@babu-VirtualBox:~#

TBD/Advanced/Detailed
lshw, lspci, lsblk, lsusb, lsscsi, lshal, lsraid, lsdev, hwinfo, dmidecode, hdparm, biosdecode



UA-48797665-1