What is a the Linux kernel?
The kernel is a program, Often with a name vmlinuz-<version>(vmlinuz-3.10.0-514.26.2.el7.x86_64), and that program needs to loaded into memory and run and that operation is a boot loader. With Linux we often have a boot-loader called grub, so grub reads the kernel file from disk into memory and transfer control to it.
The kernel program like other program has command-line parameters and grub is responsible for passing those parameters to the kernel. The Linux kernel is a API it provides an programming interface. The functions we call from user space into the kernel we call system calls, but linux kernel also provides virtual file system entries say proc,sys,debugfs., and through those virtual file systems we can interact directly with kernel. Like getting information from kernel and changing things in kernel . Also our file system as Device-File’s (system calls) .
The kernel is a Gate Keeper: that Enforces priviliges(capabilities), Executes superior instructions, Implements security policies(SElinux),Controls access to h/w and other resources.
Kernel is a Modular: Kernel image is relatively small(In MB),Kernel image is sufficient to boot to user space, Optional functionality is added after booting,It allows for alternatives; for example, =>loading only drivers required for present h/w.
[root@cms ~]# ls -l /boot/
total 140568
-rw-r–r–. 1 root root 126426 Nov 20 2015 config-3.10.0-327.el7.x86_64
-rw-r–r–. 1 root root 137701 Jul 4 20:45 config-3.10.0-514.26.2.el7.x86_64
drwxr-xr-x. 2 root root 26 Jan 26 01:44 grub
drwx——. 6 root root 4096 Jul 15 06:07 grub2
-rw-r–r–. 1 root root 43565957 Jan 26 01:48 initramfs-0-rescue-63f5c6cb01084bad905d0c80fe992973.img
-rw——-. 1 root root 20081417 Jul 15 06:08 initramfs-3.10.0-327.el7.x86_64.img
-rw-r–r–. 1 root root 17663887 Jan 26 01:50 initramfs-3.10.0-327.el7.x86_64kdump.img
-rw——-. 1 root root 20815122 Jul 15 06:08 initramfs-3.10.0-514.26.2.el7.x86_64.img
-rw——- 1 root root 18595423 Jul 15 06:15 initramfs-3.10.0-514.26.2.el7.x86_64kdump.img
-rw-r–r–. 1 root root 613842 Jul 15 06:07 initrd-plymouth.img
-rw-r–r–. 1 root root 252612 Nov 20 2015 symvers-3.10.0-327.el7.x86_64.gz
-rw-r–r–. 1 root root 277955 Jul 4 20:47 symvers-3.10.0-514.26.2.el7.x86_64.gz
-rw——-. 1 root root 2963044 Nov 20 2015 System.map-3.10.0-327.el7.x86_64
-rw——-. 1 root root 3114352 Jul 4 20:45 System.map-3.10.0-514.26.2.el7.x86_64
-rwxr-xr-x. 1 root root 5156528 Jan 26 01:48 vmlinuz-0-rescue-63f5c6cb01084bad905d0c80fe992973
-rwxr-xr-x. 1 root root 5156528 Nov 20 2015 vmlinuz-3.10.0-327.el7.x86_64
-rwxr-xr-x. 1 root root 5397008 Jul 4 20:45 vmlinuz-3.10.0-514.26.2.el7.x86_64
1.What kernel version is your Linux system running?
[root@cms ~]# uname -a
Linux cms.example.com 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
2.What is the size of the kernel file that corresponds to the kernel your system is running?
[root@cms ~]# ls -lh /boot/vmlinuz-3.10.0-327.el7.x86_64
-rwxr-xr-x. 1 root root 5.0M Nov 20 2015 /boot/vmlinuz-3.10.0-327.el7.x86_64
[root@cms ~]# ls -lh /boot/vmlinuz-3.10.0-514.26.2.el7.x86_64
-rwxr-xr-x. 1 root root 5.2M Jul 4 20:45 /boot/vmlinuz-3.10.0-514.26.2.el7.x86_64
[root@cms ~]# ls -lh /boot/vmlinuz-0-rescue-63f5c6cb01084bad905d0c80fe992973
-rwxr-xr-x. 1 root root 5.0M Jan 26 01:48 /boot/vmlinuz-0-rescue-63f5c6cb01084bad905d0c80fe992973
Commands for H/W info?
lshw & lspci
lsusb & lsblk
lscpu & lsdev
Command for H/W control and config
hdparm
write (eg: echo)tp proc,dev,or sys files.
inb & outb
setpci
System call Mechanics
Standard library uses architecture-dependent means to invoke the system call mechanism.
suitably sized parameters are usually put in registers.
The Kernel is invoked, determined which system call, and calls it.
man 2 read
dmesg shows RAM buffer message from kernel.
dmesg |wc -l
1471
dmesg |head
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.0-83-generic (buildd@lgw01-10) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #106~14.04.1-Ubuntu SMP Mon Jun 26 18:10:19 UTC 2017 (Ubuntu 4.4.0-83.106~14.04.1-generic 4.4.70)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.4.0-83-generic root=UUID=50baebd2-73f6-4d7c-b951-e3a3853c9cbd ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
/proc
The proc filesystem is mounted on /proc at boot. proc gers its name from “process”. proc conatins lots of process info and lots more. kernel tunable variable are an important part of proc.
/sys
The sys filesystem is mounted on /sys at boot. sysyfs is for “kernel project” info. In particular it is h/w info.
3.How much RAM is available to your running kernel? Note: It may or may not be the amount of physical RAM on your system.
mohammedrafi@NOC-RAFI:~$ free -m
total used free shared buffers cached
Mem: 3885 2105 1779 300 24 566
-/+ buffers/cache: 1514 2371
Swap: 4028 620 3408
mohammedrafi@NOC-RAFI:~$ head /proc/meminfo
MemTotal: 3978556 kB
MemFree: 1820000 kB
MemAvailable: 1937948 kB
Buffers: 25468 kB
Cached: 583228 kB
SwapCached: 33116 kB
Active: 1482844 kB
Inactive: 485312 kB
Active(anon): 1298280 kB
Inactive(anon): 368968 kB
4.The command strace will display the system calls that a process makes as it runs. Using the man command, determine what option for strace will show a summary, with a count, of the number of times a process called each system call. Using that option, what system call is called the most by the command date ?
mohammedrafi@NOC-RAFI:~$ strace -c date
Sat Jul 22 23:44:33 IST 2017
% time seconds usecs/call calls errors syscall
—— ———– ———– ——— ——— —————-
0.00 0.000000 0 3 read
0.00 0.000000 0 1 write
0.00 0.000000 0 4 open
0.00 0.000000 0 6 close
0.00 0.000000 0 6 fstat
0.00 0.000000 0 1 lseek
0.00 0.000000 0 10 mmap
0.00 0.000000 0 4 mprotect
0.00 0.000000 0 3 munmap
0.00 0.000000 0 3 brk
0.00 0.000000 0 3 3 access
0.00 0.000000 0 1 execve
0.00 0.000000 0 1 arch_prctl
—— ———– ———– ——— ——— —————-
100.00 0.000000 46 3 total
5.Can you determine, using strace , what system call is used to change the directory?
mohammedrafi@NOC-RAFI:~$ strace ls /home/
6.Run a sleep 100 with & (to put it in the background). What files does its process have open?
mohammedrafi@NOC-RAFI:~$ sleep 100&
[1] 2602
mohammedrafi@NOC-RAFI:~$ jobs
[1]+ Running sleep 100 &
mohammedrafi@NOC-RAFI:~$ cd /proc/2602/
mohammedrafi@NOC-RAFI:/proc/2602$ ls
attr clear_refs cpuset fd limits mem net oom_score projid_map sessionid stat task
autogroup cmdline cwd fdinfo loginuid mountinfo ns oom_score_adj root setgroups statm timers
auxv comm environ gid_map map_files mounts numa_maps pagemap sched smaps status uid_map
cgroup coredump_filter exe io maps mountstats oom_adj personality schedstat stack syscall wchan
mohammedrafi@NOC-RAFI:/proc/2602$ ls -l fd/
total 0
lrwx—— 1 mohammedrafi mohammedrafi 64 Jul 22 23:55 0 -> /dev/pts/2
lrwx—— 1 mohammedrafi mohammedrafi 64 Jul 22 23:55 1 -> /dev/pts/2
lrwx—— 1 mohammedrafi mohammedrafi 64 Jul 22 23:55 2 -> /dev/pts/2
mohammedrafi@NOC-RAFI:/proc/2602$ tty
/dev/pts/2
7.Does your system have a PCI Ethernet device?
mohammedrafi@NOC-RAFI:~$ lspci |grep -i ethernet
25:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 06)
8.Is the kernel variable ip_forward (under /proc/sys/ …) set to 1 or 0 on your system?
mohammedrafi@NOC-RAFI:~$ sudo find /proc/ -name ip_forward
/proc/sys/net/ipv4/ip_forward
mohammedrafi@NOC-RAFI:~$
mohammedrafi@NOC-RAFI:~$ cat /proc/sys/net/ipv4/ip_forward
1
mohammedrafi@NOC-RAFI:~$ sudo sysctl -a |grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
sysctl: reading key “net.ipv6.conf.all.stable_secret”
sysctl: reading key “net.ipv6.conf.default.stable_secret”
sysctl: reading key “net.ipv6.conf.docker0.stable_secret”
sysctl: reading key “net.ipv6.conf.eth0.stable_secret”
sysctl: reading key “net.ipv6.conf.lo.stable_secret”
sysctl: reading key “net.ipv6.conf.virbr0.stable_secret”
sysctl: reading key “net.ipv6.conf.vmnet1.stable_secret”
sysctl: reading key “net.ipv6.conf.vmnet8.stable_secret”
sysctl: reading key “net.ipv6.conf.wlan0.stable_secret”
mohammedrafi@NOC-RAFI:~$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
9.According to /sys/block , do you have a block device (disk) sda ? If so, do you have device files for partitions of sda ? How many? Using strace , does the command fdisk -l (run it as root), open any files under /sys/dev/block ?
mohammedrafi@NOC-RAFI:~$ cd /sys/block/
mohammedrafi@NOC-RAFI:/sys/block$ ls
loop0 loop1 loop2 loop3 loop4 loop5 loop6 loop7 sda sr0
10.Using dmesg and grep , do you see the kernel reporting the kernel command line? If not, can you determine if the boot messages from the kernel were lost? Does your system have a log file that recorded the boot messages? You can grep for BOOT_IMAGE under /var/log to look.
dmesg
11.What other device files are character devices and share the same major number with /dev/null ?
mohammedrafi@NOC-RAFI:~$ ls -l /dev/ |grep ^c |grep “1,”
crw-rw-rw- 1 root root 1, 7 Jul 21 17:27 full
crw-r–r– 1 root root 1, 11 Jul 21 17:27 kmsg
crw-r—– 1 root kmem 1, 1 Jul 21 17:27 mem
crw-rw-rw- 1 root root 1, 3 Jul 21 17:27 null
crw-r—– 1 root kmem 1, 4 Jul 21 17:27 port
crw-rw-rw- 1 root root 1, 8 Jul 21 17:27 random
crw——- 1 root root 251, 0 Jul 21 17:27 rtc0
crw-rw—- 1 root disk 21, 0 Jul 21 17:27 sg0
crw-rw—-+ 1 root cdrom 21, 1 Jul 21 17:27 sg1
crw-rw-rw- 1 root root 1, 9 Jul 21 17:27 urandom
crw-rw—-+ 1 root video 81, 0 Jul 21 17:27 video0
crw-rw-rw- 1 root root 1, 5 Jul 21 17:27 zero
Run grub2-mkconfig to generate a new config file.
Grub passes paramertes
The kernel process command-line arguments
Initial Root FileSystem
Linux systems frequently start up by a mounting a filesystem from RAM. The filesystem that contains “/” is called root file system. This initial RAM disk or RAM filesystem(initrd) is used to provide drivers and support for mounting the system’s real root file system. The initrd has an init that takes tuns first.
The First process(from disk)
when the init from the initrd terminates, the Linux kernel init again; this time from the real file system, which is commonly on disk. Historically that program was called “init” . Now, init may be a link to systemd. This process is responsible for starting for starting up services such as daemon like a web server.
mohammedrafi@NOC-RAFI:~$ cd /lib/modules
mohammedrafi@NOC-RAFI:/lib/modules$ ls
4.2.0-27-generic 4.4.0-59-generic 4.4.0-63-generic 4.4.0-70-generic 4.4.0-75-generic 4.4.0-83-generic
4.2.0-42-generic 4.4.0-62-generic 4.4.0-64-generic 4.4.0-72-generic 4.4.0-78-generic
mohammedrafi@NOC-RAFI:/lib/modules$ cd 4.4.0-83-generic/
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic$ ls
build kernel modules.alias modules.builtin modules.dep modules.devname modules.softdep modules.symbols.bin vdso
initrd misc modules.alias.bin modules.builtin.bin modules.dep.bin modules.order modules.symbols updates
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic$ cd kernel/
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel$ ls
arch crypto drivers fs kernel lib mm net sound ubuntu virt
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel$ cd ..
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic$ head modules.dep
kernel/arch/x86/kernel/cpu/mcheck/mce-inject.ko:
kernel/arch/x86/kernel/msr.ko:
kernel/arch/x86/kernel/cpuid.ko:
kernel/arch/x86/crypto/glue_helper.ko:
kernel/arch/x86/crypto/aes-x86_64.ko:
kernel/arch/x86/crypto/des3_ede-x86_64.ko: kernel/crypto/des_generic.ko
kernel/arch/x86/crypto/camellia-x86_64.ko: kernel/crypto/xts.ko kernel/crypto/lrw.ko kernel/crypto/gf128mul.ko kernel/arch/x86/crypto/glue_helper.ko
kernel/arch/x86/crypto/blowfish-x86_64.ko: kernel/crypto/blowfish_common.ko
kernel/arch/x86/crypto/twofish-x86_64.ko: kernel/crypto/twofish_common.ko
kernel/arch/x86/crypto/twofish-x86_64-3way.ko: kernel/arch/x86/crypto/twofish-x86_64.ko kernel/crypto/twofish_common.ko kernel/crypto/xts.ko kernel/crypto/lrw.ko kernel/crypto/gf128mul.ko kernel/arch/x86/crypto/glue_helper.ko
mohammedrafi@NOC-RAFI:~$ lsmod |head
Module Size Used by
hid_generic 16384 0
usbhid 49152 0
hid 118784 2 hid_generic,usbhid
ipt_REJECT 16384 2
nf_reject_ipv4 16384 1 ipt_REJECT
xt_CHECKSUM 16384 1
iptable_mangle 16384 1
xt_tcpudp 16384 6
xt_addrtype 16384 2
mohammedrafi@NOC-RAFI:~$ cd /lib/modules/4.4.0-83-generic/kernel/
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel$ find . -name camellia*
./arch/x86/crypto/camellia-aesni-avx2.ko
./arch/x86/crypto/camellia-x86_64.ko
./arch/x86/crypto/camellia-aesni-avx-x86_64.ko
./crypto/camellia_generic.ko
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel$ cd arch/x86/crypto/
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto$ insmod camellia-x86_64.ko
insmod: ERROR: could not insert module camellia-x86_64.ko: Operation not permitted
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto$ sudo !!
sudo insmod camellia-x86_64.ko
insmod: ERROR: could not insert module camellia-x86_64.ko: Unknown symbol in module
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto$ dmesg |tail
[69485.394393] input: PixArt USB Optical Mouse as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:0461:4E2A.0004/input/input52
[69485.422727] userif-3: sent link down event.
[69485.422738] userif-3: sent link up event.
[69485.450243] hid-generic 0003:0461:4E2A.0004: input,hidraw0: USB HID v1.11 Mouse [PixArt USB Optical Mouse] on usb-0000:00:1d.0-1.1/input0
[69486.505699] userif-3: sent link down event.
[69486.505761] userif-3: sent link up event.
[73281.057882] wlan0: AP 80:37:73:a8:d5:78 changed bandwidth, new config is 2437 MHz, width 2 (2447/0 MHz)
[80996.450650] wlan0: AP 80:37:73:a8:d5:78 changed bandwidth, new config is 2437 MHz, width 1 (2437/0 MHz)
[83418.473374] wlan0: AP 80:37:73:a8:d5:78 changed bandwidth, new config is 2437 MHz, width 2 (2447/0 MHz)
[85129.918108] camellia_x86_64: Unknown symbol xts_crypt (err 0)
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto$ sudo modprobe camellia-x86_64.ko
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto$ lsmod |head
mohammedrafi@NOC-RAFI:/lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto$ modinfo camellia-x86_64.ko
filename: /lib/modules/4.4.0-83-generic/kernel/arch/x86/crypto/camellia-x86_64.ko
alias: crypto-camellia-asm
alias: camellia-asm
alias: crypto-camellia
alias: camellia
description: Camellia Cipher Algorithm, asm optimized
license: GPL
srcversion: 60B293291F8592BCEB105DD
depends: xts,lrw,glue_helper
intree: Y
vermagic: 4.4.0-83-generic SMP mod_unload modversions
parm: force:Force module load, ignore CPU blacklist (int)
Boot Procedure
https://shaikmdrafi.wordpress.com/introduction-to-linux-and-os-installations/
