Saturday, July 21, 2012

Ubuntu Server Disable screen blanking

This is so simple however I always seem to forget how to do it.

I have an Ubuntu server and often want to run htop over a few days while testing something. The problem is though that the screen keeps going blank. This is fine but then I quickly want to see what the current performance is at a glance while walking past. I don't want to have to press a key to get the screen live again.

As root run the following

setterm -powersave off -blank 0

Here are a few more interesting things you can do with setterm.

Thursday, July 12, 2012

Custom menus in Windows Start Menu

I like to keep bunch of portable utility apps on my Windows machines that I use from time to time. Normally I store these apps in C:\Utils and then just access them via Explorer but recently I have been using one of my new favourite apps (MobaXterm), to access my Linux media centers, a lot and it's becoming a bit of pain to always go via Explorer.

So with that in mind I decided to see if I could create a custom menu in my Start menu and guess what, you can.

To do this all you need to do is:

Right click the Start button and select Properties.
Click the Customize... button

Select one of the following menus that you are not using.
Documents, Downloads, Music, Pictures, Recorded TV or Videos.
I went with Recorded TV.
You can either use Display as a link or Display as a menu.
A link will just be a shortcut to your folder but a menu will display a pop out list, I chose menu because it's one less click.

Click the Start button and you will see the new menu, right click it and select Properties.
Add the folder or folders, you which to appear in your new menu, with the Include a folder... button. While you're there remove any default folders you don't want to appear.

Lastly right click on the new menu again and select Rename to give it a nice name and with that you are done.

Wednesday, July 4, 2012

Fix VirtualBox Time Sync

Today I needed to do some testing on a VirtualBox VM to ensure that our software handles crossing over midnight correctly, this meant that I either needed to change the time on my VM or wait until midnight to do my testing (yeah that's not going to happen).

That's no problem you might say, ah but you'd be wrong for if you change the time and wait a few seconds then the time will reset itself. Once again I hear you say "no problem, disable 'synchronisation with the Internet time server" and once again you'd be wrong and the reason for this is that VirtualBox syncs the time between your Host and Guest machines.
To prevent this from happening you need to stop your VM and run the following command:

vboxmanage setextradata "VMs Name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"

Just replace VMs Name with the registered name (how it appears in VirtualBox) of your VM and voilà problem solved.

Note: If that doesn't work you can also modify the vbox file of your VM manually. Open the file with your favourite text editor and add the following line

<ExtraDataItem name="VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" value="1"/>

under the <ExtraData> element.

Friday, June 22, 2012

My customizations to an Ubuntu Server 12.04 LTS

I have been toying with the idea of setting up an Ubuntu Server to run my media server at home.  Each time I go down this route there are several tweaks I do until I am happy.  The following is a list of the things I have to search the web to find most often.
I have also found some awesome suggestions for tools for xfce at their wiki.
Table of Contents
  1. Screen Resolution
  2. Console Font
  3. Set line numbers to always appear in vi
  4. Change command prompt to include colour
  5. Some additional aliases
  6. cp with a wget style progress bar
  7. Lightweight xfce4 gui
  8. phpMyAdmin for the mysql db
  9. phpPgAdmin for the PostgreSQL db
  10. Install Oracle JDK 6
  11. Webmin

  1. Screen resolution.
  2. This is simply done by editing the /etc/defaults/grub file like so
    sudo vi /etc/defaults/grub

    find the line that says GRUB_CMDLINE_LINUX="" and change it to look as follows

    save the file and REMEMBER to run
    sudo update-grub

    This will give you a console resolution of 1024x768
    You can chose other resolutions based on the following table

    VGA Resolution Codes for GRUB & Lilo<
    --- Depth --

    32000?vga=784vga=787vga=790vga= ? vga=793vga= ?
    16.7M24vga=786vga=789vga=792vga=795vga=799vga= ?

    All you need do then is reboot and you should see your server with the new resolution.

  3. Console Font
  4. Still trying to find a permanent solution to this - The closest I have come is here but this setting gets lost after a reboot.

  5. Set line numbers to always appear in vi
  6. In you home directory create a file called .vimrc and add the following line to it
    set number

    Save the file and the next time you open vi each line will automatically be numbered.

  7. Change command prompt to include colour
  8. I use this in case I login as root or if I have su'ed to root so I won't forget who I am running as at the moment. If I am running as root I want my user to appear in bright red otherwise in bright green. I also want the directories to be displayed after the username in dull green and if I am root in dull red.
    For my normal user (The green one) I edit my .bashrc file in my HOME dir
    vi ~/.bashrc

    and add the following at the end of it.
    # Set prompt: " username@hostname/directory/tree $ " (with colors)
    export PS1="\[\e[32;1m\]\u\[\e[0m\]\[\e[32m\]@\h\[\e[36m\]\w \[\e[33m\]\$ \[\e[0m\]"

    For the root user I add the following to the end of roots .bashrc
    # Set prompt: " username@hostname/directory/tree $ " (with colors)
    export PS1="\[\e[31;1m\]\u\[\e[0m\]\[\e[31m\]@\h\[\e[31m\]\w \[\e[33m\]\$ \[\e[0m\]"

  9. Some additional aliases
  10. I have some other aliases that I make use of also that I add to the end of my .bashrc file
    alias ver="cat /etc/lsb-release"
    alias free="free -m"
    alias update="sudo apt-get update"
    alias install="sudo apt-get install"
    alias upgrade="sudo apt-get upgrade"
    alias remove="sudo apt-get remove"

  11. cp with a wget style progress bar
  12. When I am copying files I like to see the speed and progress of the copy. To do this I create a file in my home dir called cppv which look as follows


    set -e

    if [ $# -lt 2 ]; then
    echo "cppv - copy files with progress bar and rate limiting ability"
    echo "Usage: cppv source_file[s] destination_file_or_directory"
    echo "No other non-positional command line arguments can be given"
    echo "Always recurses like find"
    echo "You can change copying speed limit on the fly with \"pv -R\" if you find out pv's PID"
    echo "Use FIND_OPTS, PV_OPTS, CPIO_O_OPTS, CPIO_I_OPTS to override arguments to the pipeline parts"
    echo "Examples:"
    echo " cppv a b # Copy file a to b. Just calls \"pv a > b\""
    echo " cppv a d/ # Copy file a to d/a. Calls \"find a | cpio -o | pv | (cd d && cpio -i)\""
    echo " cppv *{01..26}*.mkv /mnt/usb/ # Copy all matching files to /mnt/usb/."
    echo " cppv dir1 dir2 # duplicate dir1"
    echo " PV_OPTS=\"-L 1M\" cppv . /tmp/ # Limit copying rate to 1M"
    echo " cppv /home/vi/bin /tmp/ # Warning: Copy /home/vi/bin to /tmp/home/vi/bin"
    exit 1

    true ${CPIO_O_OPTS:="-H newc -0o"}
    true ${CPIO_I_OPTS:="-0diu --no-absolute-filenames"}
    true ${FIND_OPTS:="-depth -print0"}

    ARGS=( "$@" );

    unset ARGS[$#-1];

    if [[ ( "${1:0:1}" == "-" && ! -e "$1" ) || ( "${DEST:0:1}" == "-" && ! -e "$DEST" ) ]]; then
    echo "There should not be any command line options. Only file names." >&2
    exit 1;


    if [[ $# > 2 || "${DEST:${#DEST}-1:1}" == "/" || -d $DEST ]]; then
    elif [[ -d "$1" && ! -d "$2" ]]; then
    mkdir "$DEST";
    DEST=`readlink -f "$DEST"`;
    cd "$1";

    if [ $DIRMODE == 0 ]; then
    pv "$1" > "$2" && exit 0;

    if [ ! -d "$DEST" ]; then
    echo Not a directory: "$DEST" >&2
    exit 1

    if [ "${1:0:1}" == "/" ]; then
    echo "Warning: it will do a bit different thing than usual cp" >&2
    echo " For example, copying $1 to $DEST$1, not to $DEST/`basename $1`" >&2

    SIZE=`du -sb "${ARGS[@]}" | perl -ne '/^(\d+)/ and $q+=$1; END{print $q}'`

    find "${ARGS[@]}" $FIND_OPTS | cpio $CPIO_O_OPTS | pv -s $SIZE $PV_OPTS | (cd "$DEST" && cpio $CPIO_I_OPTS)

    I also create a static link in the /usr/bin dir to this file so I don't have to keep adding the path before the command. The command to create a static link looks like so:
    sudo ln -s ~/cppv /usr/bin/cppv

  13. Lightweight xfce4 gui

  14. From the CLI terminal, we will install a few software packages to make our life easy
    1. Install the Xfce desktop environment (a GUI for using the server) :

    2. sudo apt-get install xfce4 xfce4-terminal xauth xorg

    3. Install the Gnome Display Manager (which includes a GUI login manager) :

    4. sudo apt-get install gdm

      Alternately (what I prefer to do is) install lightdm

      sudo apt-get install lightdm-gtk-greeter

    5. If you find you have some icons missing try this to fix the problem. Also check under
      "Applications Menu->Settings->Appearance" under the icon tab and make sure you are using an icon theme.

    6. sudo apt-get install tango-icon-theme tango-icon-theme-extras gnome-icon-theme

    7. I change the font of my terminal to use "Monospace" size 10

    8. I want my terminal window to use more real estate so I edit the "~/.config/Terminal/terminalrc" file and change the MiscDefaultGeometry setting to look as follows.

    9. MiscDefaultGeometry=100x40

    10. OPTIONAL: Install the Synaptic package manager (a GUI for installing software) :

    11. sudo apt-get install synaptic

    12. OPTIONAL: Install the Update manager (a GUI for updating software) :

    13. sudo apt-get install update-manager

    14. OPTIONAL: Install the Gnome System Tools (which includes a GUI for user administration) :

    15. sudo apt-get install gnome-system-tools

    16. Now reboot the server, so that you can login to the Xfce GUI environment :

    17. sudo shutdown -r now

    When the server reboots, there will now be a GUI login screen
    Select the xfce-session, the username and enter the password
    The Xfce desktop environment will be displayed with the menu panel on top and a few icons on the desktop screen

  15. phpMyAdmin for the mysql db

  16. If I have installed mysql I normally install phpMyAdmin to make manipulation and admin of the database easier. This is easily done by following the setup found here. But basically you need to run the following with some configuration.

    sudo apt-get install libapache2-mod-auth-mysql phpmyadmin

  17. phpPgAdmin for the PostgreSQL db

  18. If I have installed PostgreSQL I normally install phpPgAdmin to make manipulation and admin of the database easier.

    The following instructions will get PostgreSQL accessible from a remote server on your lan

    If PostgreSQL is not installed already:

    sudo apt-get install postgresql

    Log into PostgreSQL and create an account and a database for the user:

    sudo -u postgres psql template1
    psql> create user acme with createdb password 'abcd';
    psql> create database acme with owner=acme; psql> \q

    Leave out the createdb option in the CREATE USER statement if you do not want to grant the user the privilege to create databases.

    By default PostgreSQL server does not accept remote connections. To enable remote connections (which is necessary for servers like CS3 but not for servers like CSNS), modify /etc/postgresql/9.1/main/postgresql.conf so:

    listen_addresses = '*'

    And modify /etc/postgresql/9.1/main/pg_hba.conf so that:

    host all all md5
    host all all ::0/0 md5

    To install phpPgAdmin:

    sudo apt-get install phppgadmin

    By default phpPgAdmin only allows local access. To allow remote access, edit /etc/phppgadmin/apache.conf so that

    #deny from all
    #allow from ::1/128
    allow from all

    Then restart Apache2. After that phpPgAdmin can be accessed at http://host/phpmyadmin/ .

    NOTE:I was looking for the quickest way to manage PostgreSQL I was not testing the security of the admin tool.

  19. Install Oracle JDK 6

  20. I followed this link to install the Oracle JDK6 onto my Ubuntu Server.
    I also add the following to my .bashrc
    # Java environment variables
    export JAVA_HOME=/usr/lib/jvm/java-6-oracle
    export PATH=$PATH:$JAVA_HOME/bin

  21. Webmin

  22. I can't believe I didn't remember to talk about installing Webmin. Firstly you'll need to have some dependancies installed. You can do this by running the following from the command line.
    apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

    Official instructions can be found here, but basically there are 2 ways to install webmin.
    1. Via APT
    As root edit /etc/apt/sources.list and add the following lines
    deb sarge contrib
    deb sarge contrib

    You will then need to install the GPG key which you can do using the following as rootcommand
    wget && sudo apt-key add jcameron-key.asc
    Once you have update the sources file you can install webmin using the following commands.
    sudo apt-get update
    sudo apt-get install webmin

    2. Manually Download the latest webmin archive.

    Install webmin with following command:
    sudo dpkg --install webmin-current

    You can connect to webmin by pointing your browser to: