Linux Tips(2)

TurnToJPG -->

1. XenCenter Installation

Just use your windows’s browser point to your XenServer IP Address, Download the XenCenter, and install it.

Update Some tools on XenServer:

$ vim /etc/yum.repos.d/CentOS-Base.repo
$ yum install -y lm_sensors

After installation of lm_sensors you could see more detailed information on XenServer.

2. Disable Specified Repository

Since citrix have no data in its repository, simply disable it.

$ yum update --disablerepo=citrix

3. Yum Shell

yum shell
remove ffmpeg-libpostproc
remove ffmpeg
install ffmpeg-compat

4. Install lm_sensors In XenServer

The default lm_sensors could not be insalled due to dependency errors, so we download the source code from lm_sensors website and manually build and install it:

$ wget
$ tar xzvf lm_sensors-3.4.0.tar.bz2
$ cd lm_sensors
$ yum install -y gcc make flex bison 
$ make && make install
$ export PATH=/usr/local/bin:$PATH
$ sensors-detect
$ sensors

In 79 machine, sensors won’t printout cpu fan, solved by:

$ modprobe it87 force_id=0x8728

Or configure the modprobe.d:

[root:/etc/modprobe.d]# cat it87.conf 
options it87 force_id=0x8603

[root:/etc/modprobe.d]# pwd

5. Detect an AMD Chipset

First using sensors-detect for detecting the sensors, the result is listed as:

Now follows a summary of the probes I have just done.

Driver `w83627ehf':
  * ISA bus, address 0x290
    Chip `Nuvoton W83677HG-I (NCT5572D/NCT6771F/NCT6772F/NCT6775F) Super IO Sensors' (confidence: 9)

Driver `k10temp' (autoloaded):
  * Chip `AMD Family 12h and 14h thermal sensors' (confidence: 9)

Now go to the modules directory for finding out the corresponding driver:

[root@xenserver-WolfHunter 3.10.0+2]# find . | grep -i w83
[root@xenserver-WolfHunter 3.10.0+2]# pwd
[root@xenserver-WolfHunter 3.10.0+2]# modprobe w83627ehf.ko

Now you could detect more infos, add to automatically:

[root@xenserver-WolfHunter modprobe.d]# cat w83627ehf.conf
/sbin/insmod /lib/modules/3.10.0+2/kernel/drivers/hwmon/w83627ehf.ko

6. Headless Ubuntu

Headless Ubuntu, for updating grub.

Add: GRUB_RECORDFAIL_TIMEOUT = 15 in /etc/default/grub, and run "sudo update-grub". You can change the 15 to any arbitrary number of seconds that you like.

7.Joggler Bootloader Configuration

Notice there are 2 systems available on Joggler.

[dash@/run/media/dash/linux-boot]$ cat grub.cfg
loadfont /unicode.pf2
terminal_output gfxterm
set timeout=5
menuentry "Ubuntu 12.04 LTS (Precise) - 3.2.32joggler1" {
  # text mode
  #linux /vmlinuz-3.2.32joggler1 root=LABEL=linux-root 3 ro text pci=routeirq
  # Graphical mode
  linux /vmlinuz-3.2.32joggler1 root=LABEL=linux-root 3 ro pci=routeirq
  initrd /initrd.img-3.2.32joggler1
#menuentry "XUbuntu 12.04 LTS (Precise) - 3.2.32joggler1" {
#  linux /vmlinuz-3.2.32joggler1 root=LABEL=Xubuntu ro quiet splash 
#  initrd /initrd.img-3.2.32joggler1

8. Use Joggler As a DigitalFrame

# Script to run Digital Picture Frame using Feh

# Change number below to the duration, in seconds
# for each photo to be displayed

# hide the cursor after 15 seconds
#/usr/bin/unclutter -idle 15 &

# Start slide show
# /usr/bin/feh --quiet --recursive --randomize --full-screen \ --slideshow-delay $DELAY /home/dash/800480/
/usr/bin/feh --hide-pointer -D $DELAY --quiet --recursive --randomize --full-screen \ --slideshow-delay $DELAY /home/dash/800480 &

# Phone home and sync
# /home/dsl/frame/

exit 0

9. Resolving git conflicts

Once you installed meld or other tools, using following commands.

$ git mergetool

10. Enlarge Volume

Enlarge the qemu disk via:

$ sudo qemu-img resize abc.qcow2 +200GB

Enlarge the disk via following command:

[root@fuel ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/os-root   9.6G  976M  8.1G  11% /
/dev/mapper/os-var     27G  5.4G   20G  22% /var
[root@fuel ~]# lvs
  LV           VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root         os   -wi-ao----  9.78g                                                    
  swap         os   -wi-ao----  2.94g                                                    
  var          os   -wi-ao---- 26.66g       

Use gparted livecd for enlarge the disk, now you could enjoy the whole 300GiB disk size.

Resize the var partition:

Disk /dev/mapper/os-var: 28.6 GB, 28621930496 bytes
255 heads, 63 sectors/track, 3479 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@fuel ~]# lvextend -L+50G /dev/mapper/os-var
  Size of logical volume os/var changed from 26.66 GiB (853 extents) to 76.66 GiB (2453 extents).
  Logical volume var successfully resized
######Reboot to gdisk iso, and resize2fs.   
# resize2fs /dev/mapper/os-var

11. gpg Generation

$ apt-get install -y rng-tools
$ rngd -r /dev/urandom
$ gpg --gen-key
$ gpg --list-secret-keys
$ gpg-agent --homedir /home/dash/.gnupg --use-standard-socket --daemon
$ sudo apt-get install gnupg

Redirect bash script’s output to syslogd:

Then limit the syslogd activity:

via logrotate, syslogd don’t care about the log file size.

So in the end the top portion of my /etc/logrotate.conf file looks like this:

size 250M
rotate 2
include /etc/logrotate.d

13. Brake

14. install specified pip version

$ sudo pip install "PyOpenSSL>=0.13"

15. Tips for using vFense

   57  sudo pip install "PyOpenSSL>=0.13"
   58  apt-cache search libffi
   59  sudo apt-get install -y libffi-dev
dash@fenseServer:~$ sudo mkdir /usr/share/rethinkdb

16. Cgroup error

cloudstack4.5.1 在centos7.1 上的 bug 
此bug 会导致 系统vm state 状态获取不到
Controller 'cpuacct' is not wanted, but 'cpu' is co-mounted: Invalid argument


注释这个文件中的这行 /usr/lib64/python2.7/site-packages/cloudutils/
cfo.addEntry("cgroup_controllers", "[\"cpu\"]")
和这个文件中的这行 /etc/libvirt/qemu.conf


17. PXE Boot Debian:

Trouble Shooting: Use the latest version!!!
iscsi and kvm:

18. Quickly Connect to RDP

# ssh -L 2333: -l root
# rdesktop -u YourUseName -p YourPassword localhost:2333 -g 1400x800

On CentOS 7, do following:

$ sudo vim /etc/nginx/nginx.conf
http {
        disable_symlinks off;

server {
        root         /var/www/html;

        location / {
                        autoindex on;

Restart the nginx service now you could get the local directory avaiable in browser.

20. Get Back the passwd

In Grub, add single at the linux /boot/vmlinuz-……

Press F10, and now you can do whatever you want to do.

21. Enable Nested KVM

# virsh edit VM_NAME
<vcpu placement='static' cpuset='0-3'>4</vcpu>
Also change the cpu model.  
remove the tsc related item.   

22. Restart Windows Under CMD

Specify the timeout(5 seconds) under the cmd line:

# shutdown /r /t 5

23. Cleanup Windows7 Disk

Right click the disk, and select Disk Cleanup, then select Clean up system files, then your winsxs directory will be cleaned, thus saved your partition volumn.

24. vim spell checking

: set spell spelllang=en_us

25. Startup Synergy At System Startup

# vim /etc/lightdm/lightdm.conf
greeter-setup-script=/usr/bin/synergys --config /home/dash/mysynergy.conf

26. Install Cobbler On Ubuntu

# wget -qO - | sudo apt-key add -
# sudo add-apt-repository "deb ./"
# apt-get update

27. Install restricted extra packages

Install it via:

 # sudo apt-get install ubuntu-restricted-extras

28. View Allocated DHCP Address

$ more /var/lib/dhcpd/dhcpd.leases

29. apt-mirror for launchpad

The steps are the same as the ordinary repository.

# vim  /etc/apt/mirror.list
 deb trusty main
# apt-mirror

30. Specify architecture of sources.list

Only include amd64:

$ sudo vim /etc/apt.sources.list
deb [arch=amd64] trusty main

31. Use Cobbler Repository

[root@localhost yum.repos.d]# cat cobbler.repo 

32. Jenkins Worktips


# visudo

33. Query packages

$ yum whatprovides "*/mkpasswd"
$ repoquery -q --file */mkpasswd

34. Encrypt kickstart used passwd

# perl -e "print crypt('engine123','sa')"

35. Disable ssh -X warning


Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-*


# vim ~/.bashrc
export NO_AT_BRIDGE=1

36. Manually add gpg key

# wget
# cat Release.key |sudo apt-key add -

37. Quick Setup the CentOS7 Network

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd

38. GPG Key Error

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file


# wget
# rpm --import RPM-GPG-KEY-EPEL-7 

39. Sync REpository

[root@SpaceWalker ~]# spacewalk-repo-sync -c centos7-x86_64 --url=file:///var/distro-trees/centos7_64/
| Channel: centos7-x86_64

Repo URL: file:///var/distro-trees/centos7_64/
Packages in repo:              8652
No new packages to sync.
Repo file:///var/distro-trees/centos7_64/ has comps file 0e6e90965f55146ba5025ea450f822d1bb0267d0299ef64dd4365825e6bad995-c7-x86_64-comps.xml.gz.
Repo file:///var/distro-trees/centos7_64/ has 0 errata.
Sync completed.
Total time: 0:01:58

40. Resuming until you success

# cat ./
until sudo xxxxxxx
	do something
# ./

41. pacman/yaourt

Ignore the pacman PGP check:

$ sudo vim /etc/pacman.conf
SigLevel = Never

yaourt use disable PGP options:

yaourt --m-arg "--skipchecksums --skippgpcheck" -S xxxxxx

42. Install pandoc

Add 3rd-party repository

# vim /etc/pacman.conf
Server =

With the above ignore PGP settting, run proxychains pacman -Sy.

Then you type-in proxychain pacman -S haskell-pandoc for installing the pandoc.

43. Change Docker Image Save Directory

Only works under CentOS:

# cat /etc/sysconfig/docker
other_args='-g /home/xxxxxxx/dockerimage'

44. Define locale under CentOS

# localedef -v -c -i en_US -f UTF-8 en_US.UTF-8

45. Install nethogs in CentOS 7

# yum install libpcap-devel -y
# rpm -ivh
[root@spacewalkercs7 zones]# cat db.spacewalkercs7
$TTL 604800
@       IN      SOA     spacewalkercs7. root.spacewalker.cs. (
                                3               ;Serial
                                604800          ;Refresh
                                86400           ;Retry
                                2419200         ;Expire
                                604800 )        ;Negative Cache TTL
; name servers - NS records
      IN      NS      spacewalkercs7.

; name servers  - A records
spacewalkercs7.         IN      A
[root@spacewalkercs7 zones]# pwd
[root@spacewalkercs7 zones]# cat /etc/named.conf
// named.conf
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
// See /usr/share/doc/bind*/sample/ for example named configuration files.

options {
        listen-on port 53 {;; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { localhost;;};
        allow-transfer     { localhost;;};

         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
         - If you are building a RECURSIVE (caching) DNS server, you need to enable 
         - If your recursive DNS server has a public IP address, you MUST enable access 
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification 
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface 
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";

        pid-file "/run/named/";
        session-keyfile "/run/named/session.key";

logging {
        channel default_debug {
                file "data/";
                severity dynamic;

zone "." IN {
        type hint;
        file "";

zone "spacewalkercs7" {
        type master;
        file "/etc/named/zones/db.spacewalkercs7";

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

[root@spacewalkercs7 zones]# cat /etc/dhcp/dhcpd.conf
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
option domain-name "";
# specify name server's hostname or IP address
option domain-name-servers;
# default lease time
default-lease-time 600;
# max lease time
max-lease-time 7200;
# this DHCP server to be declared valid
# specify network address and subnet mask
subnet netmask {
    # specify the range of lease IP address
    range dynamic-bootp;
    # specify broadcast address
    option broadcast-address;
    # specify default gateway
    option routers;
    # Specify default dns server
    option domain-name-servers;

47. On DNS Server

48. Install X windows under CentOS

# yum groupinstall 'X Window System' -y

49. Quickly Create/Start KVM Machine

# virsh dumpxml VM_A>A.xml
# vim A.xml
Change its name/uuid/disk file
# virsh start vmname

50. View io statistics

# iostat -m 1
# iotop

51. Traffic Control

52. system-config-kickstart Start Error


# system-config-kickstart
RuntimeError: Could not read video driver database


# apt-get remove hwdata
# wget
# dpkg -i hwdata_0.267-1_all.deb

53. Query Configuration file of yum

Use rpm -qc for querying the configuration files of specified software.

$ rpm -qc xxxxx

54. ShellShock

# export foo='() { :; }; echo Hello World'
# env x='() { :;}; echo vulnerable'  bash -c "echo this is a test"

Detailed info:

55. Install Wine1.7

Do the following changes:

$ sudo vim /etc/apt/sources.list
deb [arch=amd64,i386] trusty main restricted universe multiverse
deb [arch=amd64,i386] trusty-security main restricted universe multiverse
deb [arch=amd64,i386] trusty-updates main restricted universe multiverse
deb [arch=amd64,i386] trusty-proposed main restricted universe multiverse
deb [arch=amd64,i386] trusty-backports main restricted universe multiverse
$ sudo dpkg --add-architecture i386
$ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade
$ sudo aptitude --full-resolver -f install wine1.7
6) 	wine1.7 [Not Installed]
7) 	wine1.7-amd64 [Not Installed]
8) 	wine1.7-i386:i386 [Not Installed]

Accept this solution? [Y/n/q/?] 6
Action "6": Removing wine1.7
Accept this solution? [Y/n/q/?] r 6

Then you will get wine1.7 installed in your system.

55. Quickly Remove the know hosts

ssh-keygen -f "/home/xxxx/.ssh/known_hosts" -R

56. Install mirrordir from rpmforge

Import rpmforge and install mirrordir.

$ rpm -Uvh
$ yum search mirrordir
$ yum install mirrordir

57. Convert recorded videos into gif

From the ogv into the gif.

#  mplayer -ao null ./chromium.ogv -vo jpeg:outdir=output
#  ls output
#  convert output/* output.gif

58. Clear BIOS Password In Linux

# sudo ./cmospwd /k
1 - Kill cmos
2 - Kill cmos (try to keep date and time)
0 - Abort
# 2

Reboot and see CMOS.

59. MATE On CentOS7

First you should switches to the epel and official, then install via groupinstall:

$  yum groupinstall "MATE Desktop" -y

I don’t know why I can install it from my own repository.

To change the runlevel of the CentOS Server, use following command:


# systemctl set-default


# systemctl set-default
Tips for monitor of centos7:

Chinese Input Method:

61. Mount Error Solution



ERROR: could not insert 'module-name': Exec format error


    重命名/lib/modules/extramodules-3.2-ARCH/ (官方内核)或/lib/modules/extramodules-3.2-ck/ (ck内核)下对应的模块文件(.ko.gz),然后重新编译,命令:

    make clean
    make install
    depmod -a


62. Build Fedora Images

Bug for gpg in Fedora21:

rpmkeys --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-21-x86_64


Unable to create appliance : Unable to run ['/usr/bin/firewall-offline-cmd', '--disabled']!

63. KickStart Online Generate

64. Text Based vm Installation

First mount the installation media to /mnt, then run the installtion like following command.

# qemu-system-x86_64 --enable-kvm -m 1024 -smp 2 -hda ./temp_test.qcow2  -cdrom \
/media/opensuse/dash/iso/CentOS-6.6-x86_64-bin-DVD1.iso --nographic -bios \
/usr/share/qemu/bios.bin -append console=ttyS0 -kernel /mnt/isolinux/vmlinuz -initrd \

65. Gzip gz file

gzip -c Packages > Packages.gz

66. osad problem

Trusty should use saucy debs, try it tomorrow.

67. Quick Configure CentOS7(newly installed)

# cd /etc/yum.repos.d/
# mkdir back && mv * back/
# wget && yum makecache
# vim /etc/sysconfig/network-scripts/ifcfg-****
# useradd -m ccccccc
# visudo
# passwd ccccc
# vim /etc/hostname
# vim /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4 pc0xx

Configure the resolution:

# cat /etc/gdm/Init/Default 
# 1440x900 59.89 Hz (CVT 1.30MA) hsync: 55.93 kHz; pclk: 106.50 MHz 
# Modeline "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync  
xrandr --newmode "1440x900_60.00" 106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync                                                   
xrandr --addmode VGA1 "1440x900_60.00"                                            
xrandr --output VGA1 --mode "1440x900_60.00"

Configure the network:

$ cat /etc/sysconfig/network-scripts/route-enp2s0 
172.xx.0.0/16 via dev enp2s0
$ sudo  systemctl restart network

68. Systemd tips

View specified PID status.

#  systemctl status systemd-logind.service         
root:~/ # journalctl _PID=403  

69. systemd networkd and resolvd

Configuration files are listed as following:

$ pwd
$ ls

$ cat MyBridge.netdev

$ cat




$ cat


Enable the systemd service:

$ sudo systemctl enable systemd-networkd.service
$ sudo systemctl enable systemd-resolved.service
$ sudo  ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

70. Quickly install vbox extensional

sudo  VBoxManage extpack install ./Oracle_VM_VirtualBox_Extension_Pack-5.0.0-101573.vbox-extpack 

71. VNC With Specified Language

# export LANG=zh_CN.utf8
# vncserver

Then your vnc will start with zh support.

72. Proxy With Username/Passwd

# export http_proxy=http://easwy:123456@

73. Combine DVD files

74. Nested CPU For CentOS 7

75. Add Tag/Branch For Git

Added tag for the last commit:

# git log
# git tag -a V1.0 0293c397f62e5b2c025a35615c046fb0ecb40a2f
# git push --tags

Create a new branch for name version1:

# git branch version1

View all of the branches, and checkout to the specified branch:

# git branch
# git checkout master

Once you want to delete the branch:

# git branch -d checkout

Commit all of the changes to remote:

# git push --all -u

76. Auto wrap

# vim ~/.vimrc
set textwidth=78
set wrap

For chinese Wrapped:

" Wrap for Chinese
set formatoptions+=mM

77. More Detailed Systemd

Will display more detailed infos via:

# journalctl -r

78. On Build CloudStack

79. CloudInit

80. View VNC Port

[root@csagent ~]# virsh list
 Id    Name                           State
 2     v-1-VM                         running
 3     s-2-VM                         running
 4     r-7-VM                         running
 6     i-2-9-VM                       running

[root@csagent ~]# virsh vncdisplay i-2-9-VM

Then you could view it via vncviewer. Get the password for vnc via:

$ virsh edit 6
$ vncviewer