Monthly Archives: October 2014

VirtualBox and phpvirtualbox

Headless Virtualbox running on Ubuntu 12.04 server

http://www.howtoforge.com/phpvirtualbox-running-virtual-machines-with-virtualbox-4.2-and-phpvirtualbox-on-a-headless-ubuntu-12.04-server
http://www.howtoforge.com/vboxheadless-running-virtual-machines-with-virtualbox-4.1-on-a-headless-ubuntu-12.04-server
http://www.howtoforge.com/managing-a-headless-virtualbox-installation-with-phpvirtualbox-on-nginx-ubuntu-12.04

/etc/apt/sources.list.d/virtualbox.list

deb http://download.virtualbox.org/virtualbox/debian precise contrib

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -
apt-get update
apt-get install linux-headers-$(uname -r) build-essential virtualbox-4.3 dkms
wget http://download.virtualbox.org/virtualbox/4.3.10/Oracle_VM_VirtualBox_Extension_Pack-4.3.10-92957.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.10-92957.vbox-extpack
useradd -d /home/vbox -m vbox
passwd vbox
adduser vbox vboxusers

/etc/default/virtualbox

VBOXWEB_USER=vbox

update-rc.d vboxweb-service defaults

phpvirtualbox in Nginx

apt-get install nginx php5-common php5-mysql php5-suhosin php5-fpm php-pear wget

/etc/nginx/sites-available/virtualbox.conf

server {
    listen 80;
    server_name virtualbox.example.org;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name virtualbox.example.org;
    client_max_body_size 15M;

    ssl on;
    ssl_certificate /etc/ssl/private/example_org.crt;
    ssl_certificate_key /etc/ssl/private/example_org.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    ssl_prefer_server_ciphers on;

    root /usr/share/nginx/www/phpvirtualbox;
    index index.php index.html index.htm;

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~ /\.ht {
            deny all;
    }

    access_log /var/log/nginx/virtualbox/access.log;
    error_log  /var/log/nginx/virtualbox/error.log;

}

cd /usr/share/nginx/www
wget http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-4.3-1.zip
unzip phpvirtualbox-4.3-1.zip
mv phpvirtualbox-4.3-1 phpvirtualbox
cd /usr/share/nginx/www/phpvirtualbox/
cp config.php-example config.php

/usr/share/nginx/www/phpvirtualbox/config.php

var $username = 'vbox';
var $password = 'the password you used when you created vbox user';

cd /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/virtualbox.conf /etc/nginx/sites-enabled/virtualbox.conf 
nginx -t
service nginx reload

Login to phpVirtualbox
https://virtualbox.example.org/

user: admin
default password: admin
new password: pick your own

Create VM from command line

VBoxManage --help

Create an Ubuntu 12.04 Server VM with 512MB memory and a 10GB hard drive from the Ubuntu 12.04 Server iso image:

$ VBoxManage createvm --name "Ubuntu 12.04 Server" --register
$ VBoxManage modifyvm "Ubuntu 12.04 Server" --memory 512 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0
$ VBoxManage createhd --filename Ubuntu_12_04_Server.vdi --size 10000
$ VBoxManage storagectl "Ubuntu 12.04 Server" --name "IDE Controller" --add ide
$ VBoxManage storageattach "Ubuntu 12.04 Server" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium Ubuntu_12_04_Server.vdi
$ VBoxManage storageattach "Ubuntu 12.04 Server" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/ubuntu-12.04-server-amd64.iso

Importing an existing VM
VBoxManage registervm Machines/examplevm/examplevm.xml

Starting a VM with VBoxHeadless
VBoxHeadless --startvm "Ubuntu 12.04 Server"

Stop a VM
VBoxManage controlvm "Ubuntu 12.04 Server" poweroff

Pause a VM
VBoxManage controlvm "Ubuntu 12.04 Server" pause

Reset a VM
VBoxManage controlvm "Ubuntu 12.04 Server" reset

Grep tips and tricks

Grep configuration file without comments:
grep -Ev "(^[[:blank:]]*#|^$)" /etc/nginx/nginx.conf

Grep log file without unwanted messages:
grep 'Nov 17' /var/log/syslog | egrep -vi "\[UFW BLOCK\] | CRON"

Postfix server configuration

Postfix server (Debian / Ubuntu) is:

  • configured to primary domain faix.cz
  • listening on SMTP port 25 on home-server machine
  •  
    From Internet it delivers email for following domain: faix.cz
    From LAN it delivers email for following domain: home.lan

  • Every LAN computer forwards it’s mail for any user to home-server mail server and is processed to users following rules in /etc/postfix/recipient_canonical
  • Sender mapping follows the rules in /etc/postfix/canonical and /etc/postfix/sender_canonical configuration files (not in use now).
  • All mail is forwarded to users in following virtual table /etc/postfix/virtual
  • Any internal email domain is changed following rules in /etc/postfix/generic configuration file
  • Do not forget to use command postmap /etc/postfix/configuration_file every time you change file with ‘hash:‘ prefix
  • After any configuration change you have to reload Postfix service postfix reload
  •  
    Postfix installation

    apt-get install postfix
    postmap /etc/aliases
    postmap /etc/postfix/canonical
    postmap /etc/postfix/sender_canonical
    postmap /etc/postfix/generic
    postmap /etc/postfix/virtual

    /etc/mailname

    faix.cz
    

    /etc/postfix/main.cf

    alias_database = hash:/etc/aliases
    alias_maps = hash:/etc/aliases
    append_dot_mydomain = yes
    biff = no
    config_directory = /etc/postfix
    inet_interfaces = 192.168.122.1
    mailbox_command = /usr/bin/procmail
    mailbox_size_limit = 0
    mydomain = faix.cz
    myhostname = mail.$mydomain
    mynetworks = 127.0.0.0/8 192.168.122.0/27
    myorigin = /etc/mailname
    recipient_delimiter = +
    relayhost =
    smtpd_banner = $myhostname NO UCE ESMTP
    smtpd_delay_reject = no
    smtpd_helo_required = yes
    
    canonical_maps = hash:/etc/postfix/canonical
    sender_canonical_maps = hash:/etc/postfix/sender_canonical
    recipient_canonical_classes = envelope_recipient
    recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical
    smtp_generic_maps = hash:/etc/postfix/generic
    local_header_rewrite_clients = static:all
    
    smtpd_recipient_restrictions =
    permit_sasl_authenticated
    permit_mynetworks
    reject_unknown_sender_domain
    reject_unauth_destination
    reject_rbl_client cbl.abuseat.org
    reject_rbl_client sbl-xbl.spamhaus.org
    reject_rbl_client bl.spamcop.net
    reject_rhsbl_sender dsn.rfc-ignorant.org
    
    unknown_address_tempfail_action = $reject_tempfail_action
    reject_tempfail_action = defer_if_permit
    
    strict_rfc821_envelopes = yes
    
    virtual_maps = hash:/etc/postfix/virtual
    mydestination = $myhostname, smtp.$mydomain, mail.$mydomain, home.lan, localhost, localhost.localdomain

    /etc/postfix/virtual

    faix.cz virtual domain
    postmaster@faix.cz faix@gmail.com
    admin@faix.cz faix@gmail.com
    root@faix.cz faix@gmail.com zada@gmail.com
    @faix.cz faix@gmail.com

    /etc/aliases

    postmaster: admin
    webmaster: admin
    www-data: admin
    abuse: admin
    nagios: root
    admin: faix@gmail.com
    root: faix@gmail.com

    /etc/postfix/recipient_canonical

    /^root(.*)home[.]lan$/ root@faix.cz
    /^root(.*)$/ root@faix.cz
    /^pytlicek(.*)$/ faix@gmail.com
    /^zada(.*)$/ zada@gmail.com

    /etc/postfix/generic

    @home.lan @faix.cz
    

    Chromium v38 sign in problem

    I have installed Chromium v38 from my Debian Jessie repositories and I’m facing the following error “Service unavailable; try again later” when a try to sign in from Chromium.

    Until the new version v38 starts to work correctly, I will stick with previous one v37.

    Download Chromium v37 packages from here.

    chromium_37.0.2062.120-2_amd64.deb
    chromium-l10n_37.0.2062.120-2_all.deb
    chromium-inspector_37.0.2062.120-2_all.deb

    apt-get purge chromium chromium-browser
    cd ~/Download/
    dpkg -i chromium_37.0.2062.120-2_amd64.deb chromium-l10n_37.0.2062.120-2_all.deb chromium-inspector_37.0.2062.120-2_all.deb
    apt-mark hold chromium chromium-inspector chromium-l10n
    

    You have to ‘hold‘ selected Chromium packages not to be updated. If you know new version already works fine, you may ‘unhold‘ those packages with similar command above.

    How I boosted performance of my HTC Desire Z 4.2 custom ROM

    A. Install custom ROM of your choice
    B. Install Smart Launcher 2
    C. Create and enable swap
    D. Install Pim my ROM and tune CPU

    HTC Desire Z (Vision)
    AOSP 4.2.2 – Jelly Baby – v2.0.0
    Smart Launcher 2
    Pim my ROM
    Swapper 2
    Terminal Emulator

    A. Install custom ROM of your choice

    1. Download Android 4.2.2 Jelly Baby ROM and Google Apps for HTC Desire Z (Vision) to your computer.
    2. Connect Your Device to your computer and copy the above downloaded file to your device.
    3. Turn Off your device and disconnect it from PC.
    4. Now to get in the Bootloader Mode. Switch ON the phone while pressing and holding Volume Down + Power buttons together.
    5. Follow the navigation instructions on the screen. Select BOOTLOADER and then go to RECOVERY.
    6. In Clockwork Mode Recovery perform full data wipe, then Scroll down to ‘Flash zip from sd card’ and press the power button to select it.
    7. Now use your volume keys to highlight the Android 4.2.2 ROM zip file and select it using power button,confirm the installation on next screen.
    8. After the installation is complete go back and select ‘Reboot system now’, the phone will boot now and it will take almost 5-minutes to run it for the first time, So Please be Patient

    NOTE: Repeat Step 7 TO Install Google Apps on your device.

    Some useful Android SDK hints:

    cd ~/android-sdk-linux/
    tools/android update sdk
    cd platform-tools
    ./adb kill-server
    sudo ./adb start-server
    ./adb devices
    ./adb shell
    mount /system
    umount /system
    exit
    ./adb reboot bootloader

    B. Install Smart Launcher 2

    I really love Trebuchet because it’s simplicity, but there is something much simpler and that’s Smart Launcher 2.

    C. Create and enable swap

    http://forum.xda-developers.com/showthread.php?t=1821071

    What is Swap?

    A swap file allows an operating system to use hard disk space to simulate extra memory. When the system runs low on memory, it swaps a section of RAM that an idle program is using onto the hard disk to free up memory for other programs. Then when you go back to the swapped out program, it changes places with another program in RAM. I can say Swap file is like Virtual Memory on your PC.

    Requirements:
    • Any ROM (Tested on Jelly Baby above)
    • Any _CUSTOM_ Kernel (Tested on Fyodor 3.0.83 Kernel)
    • 300+ MB space on MicroSD HC class 10
    • Terminal Emulator

    1. Download the Swapper 2 and the Terminal Emulator and install them. Make sure you have BusyBox installed too.
    2. Go to Terminal Emulator type “free” without the quotation. Make sure you see “0” on the Swap.
    3. Open Swapper 2 application, go to Setting, Swap size=300 MB, Swappiness=60 (you can play on the numbers as you like). Go Advanced preferences check “Recreate swap file” and “Reformat swap” then exit…
    4. Open Swapper 2 click ON it will show some Fail. Just wait for few secs and it will continue. If not, click the ON again.
    5. Go to Terminal Emulator type “free” and you will see that the “0” has been replaced.


    If you like it hard core, like I do (sometimes), I use swap partition instead of swap file. Just be VERY careful co select your SD card. If you know the size of you SD card (from Android Settings -> Storage), use ‘fdisk /dev/block/mmcblkX’ (replace X mostly with number 1) and (p)rit command to identify it. It will show you the size of the SD card and current partition(s) (mostly only one, type FAT32). As you correctly identified the SD card, you may proceed to create swap partition.

    D. Install Pim my ROM and tune CPU

    The tuning of your device may bring excellent performance, but you have to pay it with the battery which will last less than you were used to.
    Download the application Pimp my ROM from Google Play. Start it, choose TOOLS and Pimp My CPU. Overclock your processor Current max. speed to maximum (or as much as you like) and Current min. to some reasonable low amount. Very important is Governor: interactive and IO Scheduler: deadline. Don’t forget to Set on Boot: ON to keep your settings persistent. Select save and restart your phone. Enjoy the speed! This works for me on my HTC Desire Z and HTC One V. YMMV.

    Some hints:

    My SD card was fully occupied by FAT32 partition. So I removed SD card from my device, connect it to my computer and used GParted to shink the partition (not much hardcore, but I love that GUI).
    In my example below, I’m using partition #3. You may need to replace it.

    
    fdisk /dev/block/mmcblk1
    (p)rint, (n)ew, (p)rimary, partition number (3), first cylinder (RETURN), last cylinder (+384M), (t)ag, partition number (3), hex code (82), (p)rint, (w)rite
    mkswap /dev/block/mmcblk1p3
    swapon /dev/block/mmcblk1p3
    free
    

    Configure Swapper 2 according to article above, just in “Settings”, select “Advanced preference”, check “Use swap partition” and point “Swap partition” to ‘/dev/block/mmcblk1p3’. It will show same false positive failures, but don’t worry. Restart you phone, launch Terminal Emulator and type ‘free’. If you see swap usage (not 0), your swap partition works.

    Kernel compilation (Debian Jessie)

    Kernel compilation (Debian Jessie)

    http://www.tecmint.com/kernel-compilation-in-debian-linux/

    You will need 8-10 GB of free disk space!

    
    apt-get install fakeroot kernel-package
    wget -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.14.20.tar.xz
    tar -xvJf linux-3.14.20.tar.xz
    cd linux-3.14.20
    cp /boot/config-`uname -r` .config
    

    
    apt-get install libncurses5-dev
    make menuconfig
    make-kpkg clean
    export CONCURRENCY_LEVEL=3
    fakeroot make-kpkg --append-to-version "-customkernel" --revision "1" --initrd kernel_image kernel_headers
    cd ..
    dpkg -i linux-image-3.14.20-customkernel_1_amd64.deb linux-headers-3.14.20-customkernel_1_amd64.deb
    

    Install Kernel 3.12 stable release on 64 bit Ubuntu

    http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.12.29-trusty/

    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.12.29-trusty/linux-headers-3.12.29-031229-generic_3.12.29-031229.201409301235_amd64.deb
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.12.29-trusty/linux-image-3.12.29-031229-generic_3.12.29-031229.201409301235_amd64.deb
    

    Install
    dpkg -i linux-headers-3.12*.deb linux-image-3.12*.deb

    Remove
    apt-get purge linux-image-3.12.0-* linux-headers-3.12.0-*