Monthly Archives: October 2013

yum – get list the files of package

repoquery -lq yum-utils

and it will output something like:

/etc/bash_completion.d
/etc/bash_completion.d/yum-utils.bash
/usr/bin/debuginfo-install
/usr/bin/find-repos-of-install
/usr/bin/needs-restarting
/usr/bin/package-cleanup
/usr/bin/repo-graph
/usr/bin/repo-rss
/usr/bin/repoclosure
/usr/bin/repodiff
/usr/bin/repomanage
/usr/bin/repoquery
/usr/bin/reposync
/usr/bin/repotrack
/usr/bin/show-changed-rco
/usr/bin/show-installed
/usr/bin/verifytree
/usr/bin/yum-builddep
/usr/bin/yum-config-manager
/usr/bin/yum-debug-dump
/usr/bin/yum-debug-restore
/usr/bin/yum-groups-manager
/usr/bin/yumdownloader
/usr/lib/python2.7/site-packages/yumutils
/usr/lib/python2.7/site-packages/yumutils/__init__.py
/usr/lib/python2.7/site-packages/yumutils/__init__.pyc
/usr/lib/python2.7/site-packages/yumutils/__init__.pyo
/usr/lib/python2.7/site-packages/yumutils/i18n.py
/usr/lib/python2.7/site-packages/yumutils/i18n.pyc
/usr/lib/python2.7/site-packages/yumutils/i18n.pyo
/usr/sbin/yum-complete-transaction
/usr/sbin/yumdb

traceroute and tracepath

When you execute a traceroute command (http://www.linuxhow.tk), your machine sends out 3 UDP packets with a TTL (Time-to-Live) of 1.  When those packets reach the next hop router, it will decrease the TTL to 0 and thus reject the packet.  It will send an ICMP Time-to-Live Exceeded (Type 11), TTL equal 0 during transit (Code 0) back to your machine – with a source address of itself, therefore you now know the address of the first router in the path.

Next your machine will send 3 UDP packets with a TTL of 2, thus the first router that you already know passes the packets on to the next router after reducing the TTL by 1 to 1.  The next router decreases the TTL to 0, thus rejecting the packet and sending the same ICMP Time-to-Live Exceeded with its address as the source back to your machine.  Thus you now know the first 2 routers in the path.

This keeps going until you reach the destination.  Since you are sending UDP packets with the destination address of the host you are concerned with, once it gets to the destination the UDP packet is wanting to connect to the port that you have sent as the destination port, since it is an uncommon port, it will most like be rejected with an ICMP Destination Unreachable (Type 3), Port Unreachable (Code 3).  This ICMP message is sent back to your machine, which will understand this as being the last hop, therefore traceroute will exit, giving you the hops between you and the destination.

The UDP packet is sent on a high port, destined to another high port.  On a Linux box, these ports were not the same, although usually in the 33000.  The source port stayed the same throughout the session, however the destination port was increase by one for each packet sent out.

One note, traceroute actually sends 1 UDP packet of TTL, waits for the return ICMP message, sends the second UDP packet, waits, sends the third, waits, etc, etc, etc.

If during the session, you receive * * *, this could mean that that router in the path does not return ICMP messages, it returns messages with a TTL too small to reach your machine or a router with buggy software.  After a * * * within the path, traceroute will still increment the TTL by 1, thus still continuing on in the path determination.

linux – control server swapiness

Get current value:
cat /proc/sys/vm/swappiness

Use sysctl change value for temporaly:
sysctl vm.swappiness=10 or save value there /etc/sysctl.conf

swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache

Disable swapping:

echo 0 > /proc/sys/vm/swappiness

linux – drop data caches

Sometimes it useful drop memory caches:

sync; echo 3 > /proc/sys/vm/drop_caches

if you need sudo and more options then:

echo 1 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache
echo 2 | sudo tee /proc/sys/vm/drop_caches  # drop dentries and inodes
echo 3 | sudo tee /proc/sys/vm/drop_caches  # drop pagecache, dentries and inodes

Kernel Samepage Merging – linux

KSM is a memory-saving de-duplication feature, that merges anonymous (private) pages (not pagecache ones). Although it started this way, KSM is currently not suitable only for Virtual Machine use, but rather, it can be useful to any application which generates many instances of the same data.

KSM enables the kernel to examine two or more already running programs and compare their memory. If any memory regions or pages are identical, KSM reduces multiple identical memory pages to a single page. This page is then marked copy on write. If the contents of the page is modified by a guest, a new page is created for that guest.

You can verify KSM is in action, by checking for the existence of some of its /sys files, under /sys/kernel/mm/ksm/

pages_shared how many shared pages are being used
pages_sharing how many more sites are sharing them i.e. how much saved
pages_unshared how many pages unique but repeatedly checked for merging
pages_volatile how many pages changing too fast to be placed in a tree
full_scans how many times all mergeable areas have been scanned

Check if your kernel supports this:

grep KSM /boot/config-`uname -r`
CONFIG_KSM=y

More info there:

https://www.kernel.org/doc/Documentation/vm/ksm.txt

shadow page tables

Virtualized guests running under Linux like to think that they are doing their own memory management. The truth of the matter, though, is that the host system cannot allow guests to directly modify the page tables used by the hardware; allowing that sort of access would compromise the security of the host. So, somehow, the host must be involved in the guest’s memory management. One common technique is through the use of shadow page tables. Guest systems maintain their own page tables, but they are not the tables used by the memory management unit. Instead, whenever the guest makes a change to its tables, the host system intercepts the operation, checks it for validity, then mirrors the change in the real page tables, which “shadow” those maintained by the guest.

One problem with this technique, as implemented in Linux currently, is that there is no easy way for the host to feed page table changes back to the guest. In particular, if the host system decides that it wants to push a given page out to swap, it can’t tell the guest that the page is no longer resident. So virtualization mechanisms like KVM avoid the problem altogether by pinning pages in memory when they are mapped in shadow page tables. That solves the problem, but it makes it impossible to swap processes running KVM-based virtual machines out of main memory.

qemu/kvm memory usage

The qemu/kvm process runs mostly like a normal Linux program. It allocates its memory with normal malloc() or mmap() calls. If a guest is going to have 1GB of physical memory, qemu/kvm will effectively do a malloc(1<<30), allocating 1GB of host virtual space. However, just like a normal program doing a malloc(), there is no actual physical memory allocated at the time of the malloc(). It will not be actually allocated until the first time it is touched.

Once the guest is running, it sees that malloc()’d memory area as being its physical memory. If the guest’s kernel were to access what it sees as physical address 0x0, it will see the first page of that malloc() done by the qemu/kvm process.

It used to be that every time a KVM guest changed its page tables, the host had to be involved. The host would validate that the entries the guest put in its page tables were valid and that they did not access any memory which was not allowed. It did this with two mechanisms:

shadow page tables

VMX/AMD-V extensions

 

 

linux – check network card supported speed

ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: off
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes

mdadm layout

So you’ve grown, shrunk, or reshaped your array and after rebooting, it just won’t continue booting correctly? You likely forgot to update the cached mdadm.conf in the initramfs image. Luckly this is easy.

First, we have to fix your boot issue. Reboot and when you see the grub menu, hit a key. This will take you to an interactive mode. Go ahead and edit the kernel line and change the end of it from ‘rhgb quiet’ to ‘rdshell’. Go ahead and boot that configuration. It will still fail, but rather then stopping forever, it will give you a shell. You now have to manually assemble the array by hand. Example:

mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1

dracut --force --mdadmconf /boot/initramfs-`uname -r`.img `uname -r`

SysRq magic

'b'     - Will immediately reboot the system without syncing or unmounting
          your disks.

'c'	- Will perform a system crash by a NULL pointer dereference.
          A crashdump will be taken if configured.

'd'	- Shows all locks that are held.

'e'     - Send a SIGTERM to all processes, except for init.

'f'	- Will call oom_kill to kill a memory hog process.

'g'	- Used by kgdb (kernel debugger)

'h'     - Will display help (actually any other key than those listed
          here will display help. but 'h' is easy to remember :-)

'i'     - Send a SIGKILL to all processes, except for init.

'j'     - Forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl.

'k'     - Secure Access Key (SAK) Kills all programs on the current virtual
          console. NOTE: See important comments below in SAK section.

'l'     - Shows a stack backtrace for all active CPUs.

'm'     - Will dump current memory info to your console.

'n'	- Used to make RT tasks nice-able

'o'     - Will shut your system off (if configured and supported).

'p'     - Will dump the current registers and flags to your console.

'q'     - Will dump per CPU lists of all armed hrtimers (but NOT regular
          timer_list timers) and detailed information about all
          clockevent devices.

'r'     - Turns off keyboard raw mode and sets it to XLATE.

's'     - Will attempt to sync all mounted filesystems.

't'     - Will dump a list of current tasks and their information to your
          console.

'u'     - Will attempt to remount all mounted filesystems read-only.

'v'	- Forcefully restores framebuffer console
'v'	- Causes ETM buffer dump [ARM-specific]

'w'	- Dumps tasks that are in uninterruptable (blocked) state.

'x'	- Used by xmon interface on ppc/powerpc platforms.
          Show global PMU Registers on sparc64.

'y'	- Show global CPU Registers [SPARC-64 specific]

'z'	- Dump the ftrace buffer

'0'-'9' - Sets the console log level, controlling which kernel messages
          will be printed to your console. ('0', for example would make
          it so that only emergency messages like PANICs or OOPSes would
          make it to your console.)

sysrq control – linux

/proc/sys/kernel/sysrq

0 – disable sysrq completely
1 – enable all functions of sysrq
2 – enable control of console logging level
4 – enable control of keyboard (SAK, unraw)
8 – enable debugging dumps of processes etc.
16 – enable sync command
32 – enable remount read-only
64 – enable signalling of processes (term, kill, oom-kill)
128 – allow reboot/poweroff
256 – allow nicing of all RT tasks