Search This Blog

Tuesday, November 12, 2013

pic


Friday, October 25, 2013

Snake's magic

Simple example:

!#/usr/bin/env python

x = 'abcdef'

if x.find('z'):
    print 'True'
else:
    print 'False'

What result will you get after run this python code ? False ?, are you sure  ?

Wednesday, July 17, 2013

Linux CentOS 6 KVM hot add device

First of all, you should avoid using virsh attach-disk with its limited amount of options. Instead, I suggest to specify the exact disk format you prefer in a separate, temporary XML file, like this: 

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='writeback'/>
  <source file='/home/gert/kvm/testdomain-vdb.img'/>
  <target dev='vdb' bus='virtio'/>
</disk>


Before adding it, make sure the hotplug kernel modules are loaded in the guest: 

modprobe acpiphp
modprobe pci_hotplug


Some distributions, including recent CentOS/RHEL/Fedora have this built-in in the kernel. In this case, check for CONFIG_HOTPLUG_PCI_ACPI. If it's y, then you're all set.

Finally, add it to the running VM using 

virsh # attach-device [domain] /path/to/disk.xml
(optionally, add the --persistent option to let Libvirt update the domain XML definition 'persistent'.)

In the guest, the kernel should now be triggered, as can be checked with dmesg:
[  321.946440] virtio-pci 0000:00:06.0: using default PCI settings
[...]
[  321.952782]  vdb: vdb1 vdb2

This also works perfectly using the GUI-enabled virt-manager application.

source

How to clear memory (caches) on Linux

Since 2.6.16 you need only echo to clear cached memory on Linux box.

This will clear all cached memory.


echo 3 > /proc/sys/vm/drop_caches
You can clear only part of it by using 1 or 2. All options:
  • 1 to clear cached pages.
  • 2 to clear dentries and inodes. 
  • 3 to clear all cached memory.

Thursday, February 14, 2013

Copy LVM volume over network to another LVM pool

We need to copy huge LVM volume from HOST_A to LVM on HOST_B. It can be virtual machine disk for example.
On HOST_B create LVM_HOST_B volume and after that dd over ssh with gzip. And do not use /dev/mapper

#> dd bs=1M if=LVM_HOST_A | gzip --fast -c | ssh HOST_B "gzip -d -c | dd bs=1M of=LVM_HOST_B"

Awesome!

pv utility can show progress bar for dd. pv - monitor the progress of data through a pipe.
pv -ptrb

Sunday, January 20, 2013

About Centos and default kernel boot options

 We use Centos and KVM virtualization on my work place. After some time new kernel was released and the question arose "How do I set the default kernel parameters in CentOS for all existing and future kernels?"

 We found a solution for CentOS! yum uses grubby itself! (strace, thank you!) grubby has the option "--copy-default" and I think yum runs grubby with it. So only thing you should do is to add in grub.conf all kernel options you need to current default kernel and reboot. After reboot you can install new kernel!

serverfault

Wednesday, January 16, 2013

My Debian and USB memory stick

 Few days ago i bought Silicon Power USB memory stick 16Gb size.
Memory was formated to ntfs file system (mkfs.ntfs) for MS Windows compatability.
 I was very surprised when i try copy some big files (3.3 GB ) to it and my PC totaly freezed on 70-80%.

After some search in google i found solution: ehci_hcd module

#> modprobe ehci_hcd

#> rsync -av --progress /home/***/Downloads/xxx-720p.mkv /mnt/usb/
sending incremental file list
xxx-720p.mkv
  3519709784 100%   29.22MB/s    0:01:54 (xfer#1, to-check=0/1)

sent 3520139543 bytes  received 31 bytes  30477398.91 bytes/sec
total size is 3519709784  speedup is 1.00


awesome!

Monday, January 14, 2013

pic



Monday, January 7, 2013

Powersaving for Lenovo x220i

Tunes for power saving on my Lenovo x220i

You can find something usefull here: thinkwiki

Tunes from lesswatts.org

nmi_watchdog=0
pcie_aspm=force

echo 1 > /sys/devices/system/cpu/sched_mc_power_savings
echo 1 > /sys/devices/system/cpu/sched_smt_power_savings

echo 5 > /proc/sys/vm/laptop_mode
# default 0

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# default 500

hdparm -B 1 -S 12 /dev/sda
# default -B 128

echo 10 > /sys/module/snd_hda_intel/parameters/power_save
# default 0

if your requirements for syslog are less strict than described above, you can
edit the /etc/syslog.conf file and add a "-" in front of this line:
   *.info;mail.none;authpriv.none;cron.none        /var/log/messages
like this:
   *.info;mail.none;authpriv.none;cron.none        -/var/log/messages

/sys/class/scsi_host/

echo auto > /sys/bus/pci/devices/0000:00:00.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:02.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:16.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:19.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:1a.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:1b.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:1c.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:1c.1/power/control
echo auto > /sys/bus/pci/devices/0000:00:1c.3/power/control
echo auto > /sys/bus/pci/devices/0000:00:1c.4/power/control
echo auto > /sys/bus/pci/devices/0000:00:1d.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:1f.0/power/control
echo auto > /sys/bus/pci/devices/0000:00:1f.2/power/control
echo auto > /sys/bus/pci/devices/0000:00:1f.3/power/control
echo auto > /sys/bus/pci/devices/0000:00:1f.5/power/control
echo auto > /sys/bus/pci/devices/0000:03:00.0/power/control
echo auto > /sys/bus/pci/devices/0000:0d:00.0/power/control
# default on

echo 'min_power' > /sys/class/scsi_host/host0/link_power_management_policy
# default max_performance

#echo SATA_ALPM_ENABLE=true >> /etc/pm/config.d/sata_alpm


And from amarao-san livejournal
most important:

  pcie_aspm=force
  # in grub config
  # GRUB_CMDLINE_LINUX_DEFAULT add 'pcie_aspm=force' (delimiter space)
  # update-grub
  #
  # in sysfs
  # echo powersave > /sys/module/pcie_aspm/parameters/policy
  # default performance powersave

  i915_enable_rc6=true
  # to grub config same as pcie_aspm
  # check 'i915.lvds_downclock=1 i915.semaphores=1'

  SATA link power management
  # echo SATA_ALPM_ENABLE=true >> /etc/pm/config.d/sata_alpm


  xset +dpms
  xset dpms 0 0 300

  # dpms options to .xinitrc for screen powersave


source
= Tricks and Tips to Reduce Power Consumption =

Enable ALPM:
 echo SATA_ALPM_ENABLE=true | sudo tee /etc/pm/config.d/sata_alpm

 can save ~1-2W, may cause data corruption on some hardware

Change background to a lighter colour on laptop LCD
 can save ~1%

Enable i915 rc6:
 kernel parameter: i915.i915_enable_rc6=1
 can save 25-40% on Sandybridge
 known to lockup on some machines

Enable i915 Framebuffer Compression:
 kernel parameter: i915.i915_enable_fbc=1
 LessWatts believes it can save 0.6 Watts

DRM vblank off delay:
 kernel parameter: drm.vblankoffdelay=1
 Reduces wakeup events, possibly saves power

Disable any wireless you don't need (e.g. from desktop or blacklist bluetooth)
 E.g. bluetooth, saves ~1-2W

Disable webcam
 add "blacklist uvcvideo" to /etc/modprobe.d/blacklist.conf
 can save ~1-2W
 
Use PowerTop to put the following devices into a "Good" power saving state:
 * Webcam
 * Audio
 * DRAM
 * Ethernet
 * Wifi
 * Bluetooth
 * SATA link
 * MMC/SD

PCIe ASPM
 Use Ubuntu Precise kernel - has PCIe ASPM fix in.
 Or force to powersave using kernel parameter: pcie_aspm=powersave

Laptop Backlight
 Don't use at full brightness.
 Drop to 2/3 brightness level - will save ~1W

Disable flashing cursor on gnome-terminal:
 gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_blink_mode off
 can save a few wakeups/second