Wednesday, March 21, 2012

Installing the latest Google Picasa in Ubuntu over wine

Google Picasa is not really created for linux, but can be installed via Wine in Ubuntu.

These are the steps:

Get the Google signing key
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

Add the repo for picasa
sudo sh -c 'echo "deb http://dl.google.com/linux/deb/ testing non-free" >> /etc/apt/sources.list.d/google.list'

Update apt and installing picasa
sudo apt-get update && sudo apt-get install picasa

Run Picasa once and close it
picasa &

Download the latest version of Google Picasa into your home folder
cd ~ && wget http://dl.google.com/picasa/picasa39-setup.exe

Run the Picasa installer with wine
sudo WINEPREFIX=/tmp/.wine_picasa /opt/google/picasa/3.0/wine/bin/wine ~/picasa39-setup.exe

After installation completes, close all the open Picasa windows.
Then copy the installation over package files
sudo cp -r /tmp/.wine_picasa/drive_c/Program\ Files/Google/Picasa3/* /opt/google/picasa/3.0/wine/drive_c/Program\ Files/Google/Picasa3/

Clean up your home folder
rm -rf ~/.google/picasa/
rm ~/picasa39-setup.exe

Suggested installing IE6 to overcome picasa authentication errors
env WINEARCH=win32 WINEPREFIX=~/.google/picasa/3.0/ winetricks ie6

Wednesday, September 29, 2010

Ubuntu running in low-graphic mode

Solution 1:
Reconfigure xserver xorg, with the command
sudo dpkg-reconfigure xserver-xorg
Solution 2: (Try only if you know what you are doing)

  • Take a backup of xorg.conf file:
sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf_bkp
  • Open the xorg.conf file for editing:
sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf_bkp
  • Delete this Section Device:
Section “Device”
Identifier     “Device0″
Driver         “nvidia”
VendorName     “NVIDIA Corporation”
BoardName      “GeForce 8400M GS”
EndSection
  • Edit the Section Screen as:
Section “Screen”
Identifier     “Screen0″
Device         “Device0″
Monitor        “Monitor0″
DefaultDepth    24
SubSection     “Display”
Depth       24
Modes “1440×990″
EndSubSection
EndSection

Sunday, September 19, 2010

Installing hamachi VPN in Ubuntu as a service

Hamachi is a free vpn service, useful to create a private LAN over the internet. For more details of hamachi, go to www.hamachi.cc

The following covers installing hamachi in Ubuntu as a service.

  • We start with installing the 'tun' module to enable IP tunneling in linux
sudo modprob tun
(If that gives an error tun module failed try installing faketun as given in the blog post Installing faketun)
  • Open the modules file and add ‘tun’ to the list
sudo nano /etc/modules
Your file should look similar to the example below.
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
lp
rtc
tun
(Incase 'tun' is not on that file, write 'tun' in a new line)
  • Save the file and exit out of nano (Ctrl-O to save & Ctrl-X to exit), lets move on and verify that a tunneling node has been created. (*If you have compiled your own kernel you likely need to recompile it with IP Tunneling support if you receive an error with modprobe. This is not covered in this guide. And if you are unsure, you most likely did not compile yourself and you would definitely remember doing so.)
ls /dev/net/tun
You should recieve a response like the example below
/dev/net/tun
  • If you received something along the lines of “No Such File or Directory” you may need to manually create the node (run the commands below).  If you received the response (/dev/net/tun), jump to the next step.
sudo mkdir /dev/net
sudo mknod /dev/net/tun c 10 200
Run ls /dev/net/tun again and you should now receive the correct response.
  • With our IP Tunnel node created, it is time to install Hamachi itself.  First download the latest version.  As of writing this guide, the latest version is 0.9.9.9-20
wget http://files.hamachi.cc/linux/hamachi-0.9.9.9-20-lnx.tar.gz
Expected output below
--2010-09-19 18:40:55--  http://files.hamachi.cc/linux/hamachi-0.9.9.9-20-lnx.tar.gz
Resolving files.hamachi.cc... 74.201.74.16
Connecting to files.hamachi.cc|74.201.74.16|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 344866 (337K) [text/plain]
Saving to: `hamachi-0.9.9.9-20-lnx.tar.gz'
100%[======================================>] 3,44,866    --.-K/s   in 0.002s  
2010-09-19 18:41:19 (149 MB/s) - `hamachi-0.9.9.9-20-lnx.tar.gz' saved [344866/344866]
  • Extract our newly downloaded archive
tar zxvf hamachi-0.9.9.9-20-lnx.tar.gz
Expected output below
hamachi-0.9.9.9-20-lnx/
hamachi-0.9.9.9-20-lnx/Makefile
hamachi-0.9.9.9-20-lnx/LICENSE
hamachi-0.9.9.9-20-lnx/README
hamachi-0.9.9.9-20-lnx/LICENSE.tuncfg
hamachi-0.9.9.9-20-lnx/LICENSE.openssh
hamachi-0.9.9.9-20-lnx/LICENSE.openssl
hamachi-0.9.9.9-20-lnx/hamachi
hamachi-0.9.9.9-20-lnx/tuncfg/
hamachi-0.9.9.9-20-lnx/tuncfg/Makefile
hamachi-0.9.9.9-20-lnx/tuncfg/tuncfg.c
hamachi-0.9.9.9-20-lnx/tuncfg/tuncfg
hamachi-0.9.9.9-20-lnx/CHANGES
  • Navigate into the extracted directory
cd hamachi-0.9.9.9-20-lnx/
  • Start the installation
sudo make install
Expected output below
Copying hamachi into /usr/bin ..
Creating hamachi-init symlink ..
Compiling tuncfg ..
Copying tuncfg into /sbin ..
Hamachi is installed. See README for what to do next.
  • Run the tunnel
sudo tuncfg
This should complete the install, we will now configure the user permission in order for it to run correctly.  Create a ‘hamachi’ user group
sudo groupadd hamachi
Add youself as a user to the ‘hamachi’ group.  Be sure to replace your user name where appropriate.
sudo gpasswd -a YOURUSERNAME hamachi
Add the root user to the ‘hamachi’ group
sudo gpasswd -a root hamachi
Set the correct permissions for the tuncfg socket
sudo chmod 760 /var/run/tuncfg.sock
Change the ownership of the socket file
sudo chgrp hamachi /var/run/tuncfg.sock
That should do it for the permissions, Now onto setting Hamachi up & configuring it to start as a system service.
sudo hamachi-init -c /etc/hamachi
Expected output
Initializing Hamachi configuration (/etc/hamachi). Please wait ..
   generating 2048-bit RSA keypair .. ok
   making /etc/hamachi directory .. ok
   saving /etc/hamachi/client.pub .. ok
   saving /etc/hamachi/client.pri .. ok
   saving /etc/hamachi/state .. ok
 Authentication information has been created. Hamachi can now be started with
'hamachi start' command and then brought online with 'hamachi login'.
Start hamachi
sudo hamachi -c /etc/hamachi start
Expected output
Starting Hamachi hamachi-lnx-0.9.9.9-20 .. ok
Set your computer’s nickname
sudo hamachi -c /etc/hamachi set-nick "COMPUTERNICKNAME"
Login to the Hamachi network
sudo hamachi -c /etc/hamachi login
To join an existing network (optional)  “NETWORKNAME” and “PASSKEY” should be replaced with your network name and network password
sudo hamachi -c /etc/hamachi join NETWORKNAME PASSKEY
To create a new network (optional) “NETWORKNAME” and “PASSKEY” should be replaced with your network name and network password
sudo hamachi -c /etc/hamachi create NETWORKNAME PASSKEY
If you joined an existing network you must tell hamachi to then “go-online”. Be sure to replace NETWORKNAME with your relevant network name.
sudo hamachi -c /etc/hamachi go-online NETWORKNAME
Check your hamachi status to verify everything is as it should be
sudo hamachi -c /etc/hamachi
Expected output

Hamachi, a zero-config virtual private networking utility, ver 0.9.9.9-20

  version  : hamachi-lnx-0.9.9.9-20
  pid      : 5754
  status   : logged in
  nickname : NICKNAME(assigned nickname)

  • Now to configure to startup and login automatically when the computer starts:
  • Create the startup script file:
sudo touch /etc/init.d/hamachi
(Else you can download the file directly from here. Place it in the /etc/init.d folder.)

  • Open the startup script file for editing (Incase you have downloaded the file and placed in the /etc/init.d folder, you need not do this step)
sudo nano /etc/init.d/hamachi
Paste the following contents in the file:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          hamachi
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start hamachi at boot time
# Description:       Starts up hamachi daemon. Networking is required.
### END INIT INFO

hamachi_start() {
  echo "Starting hamachi..."
  /sbin/tuncfg
  /usr/bin/hamachi -c /etc/hamachi start
  /bin/chmod 760 /var/run/tuncfg.sock
  /bin/chgrp hamachi /var/run/tuncfg.sock
}

hamachi_stop() {
  echo "Stopping hamachi..."
  killall tuncfg
  /usr/bin/hamachi -c /etc/hamachi stop
}

hamachi_restart() {
  hamachi_stop
  sleep 1
  hamachi_start
}

case "$1" in
'start')
  hamachi_start
  ;;
'stop')
  hamachi_stop
  ;;
'restart')
  hamachi_restart
  ;;
*)
  hamachi_start
esac
Save the file Ctrl+O and exit nano Ctrl+X

  • Make the file executable and configure it to run it at startup:
sudo chmod +x /etc/init.d/hamachi
sudo update-rc.d hamachi defaults
 Expected output
 Adding system startup for /etc/init.d/hamachi ...
   /etc/rc0.d/K20hamachi -> ../init.d/hamachi
   /etc/rc1.d/K20hamachi -> ../init.d/hamachi
   /etc/rc6.d/K20hamachi -> ../init.d/hamachi
   /etc/rc2.d/S20hamachi -> ../init.d/hamachi
   /etc/rc3.d/S20hamachi -> ../init.d/hamachi
   /etc/rc4.d/S20hamachi -> ../init.d/hamachi
   /etc/rc5.d/S20hamachi -> ../init.d/hamachi

Tuesday, September 14, 2010

Tweaking the Login Screen in Ubuntu

Ever thought of making the default Ubuntu login screen behave the way you want?


  • Probably you are the only user (and you do not fear someone else prying in your PC/laptop) and you feel entering the password everytime a nuisance! You would want Ubuntu to log in automatically for you.
  • Or there might be other users (like an admin and a standard user), and you may want the login screen to be visible for 10 seconds (in case you want to login as admin user) and on no response for 10 seconds (or any time you choose) log in to the standard user automatically.
  • Else, you like the old secure linux way to ask you to choose the user and enter password everytime.


There may be other things you like;
  • Like playing a sound when you log in.
  • Select the session (Gnome/Kde/xfce etc) as default
Either ways, you have your pick.
Simply go to System>Administration>Login Screen and you would find all the options to tweak the login the way you like.

Note: You will need to be logged in as admin user and enter the admin password again to Unlock the Login Screen menu.

Saturday, September 4, 2010

initramfs update error

Duringa ubuntu linux system update an initramfs error sometimes come up:


update-initramfs: Generating /boot/initrd.img-x.x.x.x-generic
.: 4: Can't open /scripts/functions

Often this results in broken update, and many other issues.
If the system is unable to boot to the new updated kernel, select the older version from the boot menu and try updating initramfs again.

Then try the following:

1, Delete only broken files in /var/lib/initramfs-tools/. (Be careful, delete onlt if you are sure of what you are doing, else you may try the other steps skipping this.)
2, sudo dpkg --configure -a
3, sudo dpkg --configure initramfs-tools (make sure no errors, otherwise repeat step 1 & 2).
4, sudo update-initramfs -u (Maybe not neccessary).

Thursday, August 5, 2010

tun module fails in Ubuntu 10, install fake tun

Problem: In Ubuntu 10.04, tun fails. while running the command
$ sudo modprobe tun
results into
tun module failed

The tun module is used in several VPN softwares like hamachi

Resolution:

Install fake tun in Ubuntu. Then run the command 'sudo modprobe tun'
Note: You need to be one of the admins (in sudo group).

To install fake tun, copy/paste and then run each command (below) separately. Make sure there is no line-breaks within a command

$ sudo apt-get install build-essential linux-headers-`uname -r`
$ mkdir faketun
$ cd faketun
$ echo -e "#include \nstatic int start__module(void) {return 0;}\nstatic void end__module(void){return;}\nmodule_init(start__module);\nmodule_exit(end__module);">tun.c
$ echo -e "obj-m += tun.o\nall:\n\tmake -C /lib/modules/\$(shell uname -r)/build/ M=\$(PWD) modules\nclean:\n\tmake -C /lib/modules/\$(shell uname -r)/build/ M=\$(PWD) clean\nclean-files := Module.symvers">Makefile
$ make
$ sudo install tun.ko /lib/modules/`uname -r`/kernel/net/tun.ko
$ sudo depmod -a
$ sudo modprobe tun
Incase, you get an  error, check tun.c and Makefile files (in the faketun folder) are created correctly. You may download the files from the address below, into the faketun folder, and then start from the 'make' command again:

File: tun.c download link


File: Makefile download link

Installing Guest Additions in VirtualBox

VirtualBox has made it pretty easy to install the Guest Additions for improved integration between guest and host. Some of these benefits are mouse-capture improvements and improved video resolution. The mouse capture improvements now allow you to control your virtual machine when the mouse is over the window, and seamlessly return to your host when it is not. Improved video resolution should allow you to customize a better resolution for your guests.

What we need to do to install the Guest Additions is select the option from the VirtualBox menu. You’ll want to do this after your guest is running (the guest-additions are installed to the guest, not the host). Select:
Devices > Install Guest Additions...

This sometimes takes a minute so don’t worry if you don’t see anything right away. This should then prompt you and say something along the lines of:
The Guest Additions image is not found on your host. Would you like to download this image now?

We’ll select YES and let it download the image. The image is downloaded to the host machine and then mounted within the guest. This way it can be shared with future guests without needing to download multiple times. It should also prompt you whether or not you’d like to mount the image. Again, select YES.

At this point you should see a disk image mounted on your desktop. What we’ll do here is run a script that will generate the proper modules to allow for guest additions. In my preferred method we’ll do this:
  1. Open a terminal by pressing ALT-F2 and enter “gnome-terminal” on gnome or “konsole” on KDE.
  2. cd /media/cdrom
    The Guest Addition iso file do not mount automatically sometimes. In the case if you do not see a cdrom, run sudo mount /dev/scd0 /media/cdrom
  3. sudo bash ./VBoxLinux*
    OR
    sudo sh ./VBoxLinuxAdditions-x86.run
    OR
    sudo sh ./VBoxLinuxAdditions-amd64.run

This will grind away at generating the proper modules and then prompt you to restart your guest machine. Once this has finished and you’ve rebooted your guest operating system you should have the guest improvements ready to go. No additional configuration for the mouse integration should be needed, but you may have to manually update to a better resolution as wanted.

Hopefully I’ll have the tutorial for building proper network bridging soon as well. Until then, enjoy your virtualization with VirtualBox!

_____________________________________

This article is taken from http://ubuntu-tutorials.com

Keyboard stops working in Virtualbox guest

Problem: Sometimes the keyboard would stop working in Virtualbox guest. The mouse works. The issues temporarily disappears on rebooting the guest.

Suggested solution: If you are in Ubuntu host, install the packages scim-bridge-client
sudo apt-get install scim-bridge-client-qt scim-bridge-client-gtk

Reboot the host.

The issue should be fixed by now.

Friday, April 30, 2010

Quick Opera install in Linux

In my opinion Opera is a very light weight, no-nonsense software. While opinions may vary, here is a easy way to install Opera in your Ubuntu/ Debian system.

Open to edit the apt sources.list file
sudo nano /etc/apt/sources.list
add the opera repo in a new line
deb http://deb.opera.com/opera/ stable non-free
Add the Opera GPG key with the command (recommended)
wget -O - http://deb.opera.com/archive.key | sudo apt-key add -
If you get authentication warnings, you may try (optional)
sudo apt-get install debian-archive-keyring
Run aptitude update
sudo apt-get update
Finally install Opera browser
sudo apt-get install opera

Tuesday, April 27, 2010

How to Set a Static IP in Linux Ubuntu Debian

We may require to configute a static IP address in our linux system. It is the easiest if you arterunning Ubuntu / debian distro.

Open up terminal and edit the 'interfaces' file in sudo mode
sudo nano /etc/network/interfaces

You would see the following lines
auto lo
iface lo inet loopback

replace the contents with the following:
auto lo eth0
iface lo inet loopback

iface eth0 inet static
address xxx.xxx.xxx.xxx(your static ip address)
netmask xxx.xxx.xxx.xxx(your network netmask)
gateway xxx.xxx.xxx.xxx(the gateway ip)

Save the file (Ctrl+O) and exit (Ctrl+X)

The ethusually the default network adapter. In a few cases it may be eth1.

I usually also change the nameservers to OpenDNS nameservers
sudo nano /etc/resolv.conf

replacing the contents with:
nameserver 208.67.222.222
nameserver 208.67.220.220

After that it is time to restart networking
sudo /etc/init.d/networking restart

Reboot your PC and check the ip with the command
ifconfig

Wednesday, April 14, 2010

Virtualbox Windows guest LAN Ethernet driver

In case you have a Windows guest in Virtualbox (Windows XP or Windows server), and the guest does not find the software of the Ethernet (LAN) card, you may download the drivers from here

AMD PCNet drivers

Intel PRO driver

You may download the drivers from the host OS, in a Shared Folder and install it from there.

Tuesday, November 17, 2009

Set up a PDF Printer in your Linux box

Do you wish to take a pdf copy of the pages or convert a document into a .pdf file? or you do not have a printer and wish to print a web-page?

You can install a PDf printer in your linux machine, so that all you need (to convert a document into a pdf file) is to print the document and choose your PDF printer instead of your usual printer.

By default, CUPS-PDF is not installed, so grab it by using
$ sudo apt-get install cups-pdf
You should then be able to add a fake printer that will convert print jobs to PDF files.

Go to System -> Administration -> Printing to bring up the Printer configuration dialog. Select New Printer from the toolbar, and walk through the New Printer Wizard. You can give the printer pretty much any name you want. PDF seems like a logical choice. The Description and Location fields are optional.

On the next screen, when asked to select a connection, choose Virtual Printer, and leave the device URI as it is: cups-pdf:/. Next, on the screen where you can select a Printer from the database, choose Generic. On the next screen, choose PostScript as the Model and as the driver for the printer. Then you'll see a screen that says "Going to create a new printer PDF at cups-pdf:/." Click Apply and you should have a virtual PDF printer.

Now you should be able to create PDF files from most Linux apps by sending your print jobs to the PDF printer. When you send jobs to the printer, they'll be saved to a directory under your home directory that's named after the virtual printer -- so if you choose PDF as the name of your virtual printer, then the jobs will be sent to /home/yourusername/PDF.

Happy printing :)

Thursday, November 12, 2009

Install Google Chrome browser in Ubuntu Linux

Here is a way to run your favourite Google Chrome browser in your Ubuntu Linux desktop.

(Note: Athough there are other ways of installing Chrome on Wine, I have found that is not very efficient.)

So here is a quick and dirty way :)

Open apt sources file
$ sudo nano /etc/apt/sources.list
Add these lines at the end

deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main

Save (Ctrl+O) and Exit (Ctrl+X) nano.

Update apt
$ sudo apt-get update
Then install Chrome browser with the following command
$ sudo apt-get install chromium-browser
Enjoy ! ;)

___________________________________

Incase you get the following error (while running apt-get update):
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5A9BF3BB4E5E17B5

(It means you need to import the key for "Launchpad PPA for chromium-daily")

Resolution: Run the following command
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5A9BF3BB4E5E17B5

---------------------------------------

Installing Java in Ubuntu Linux

One of the reasons I love Ubuntu (Linux) is because it comes with a great number of packages.

Ubuntu has the following Java packages

sun-java6-bin – Contains the binaries
sun-java6-demo – Contains demos and examples
sun-java6-doc – Contains the documentation
sun-java6-fonts – Contains the Lucida TrueType fonts from the JRE
sun-java6-jdk – Contains the metapackage for the JDK
sun-java6-jre – Contains the metapackage for the JRE
sun-java6-plugin – Contains the plug-in for Mozilla-based browsers
sun-java6-source – Contains source files for the JDK

Here is a quick and dirty way to install Java in your Ubuntu desktop / server

Edit the sources list
$ sudo nano /etc/apt/sources.list
Insert the following lines at the end of the file

deb http://us.archive.ubuntu.com/ubuntu dapper main restricted
deb http://us.archive.ubuntu.com/ubuntu dapper universe multiverse

Save (Ctrl+O ) and Exit (Ctrl+X) the file.

Update apt
$ sudo apt-get update
Now in terminal run the command line
$ sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
Agree to the terms and java will install automatically.


Test that Java install is successful
Run command
$ java -version
You will get something like
java version “1.6.0″
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
________________________________________________________

For manually installing java, you may follow the instructions here
http://sites.google.com/site/easylinuxtipsproject/java#TOC-HOW-TO-FOR-32-BIT-UBUNTU
________________________________________________________

Monday, November 2, 2009

Hamachi gets killed in Ubuntu 9.10

Problem: Hamachi gets Killed after upgrading to Ubuntu 9.10

Cause: Hamachi's binary is compressed with upx. You just need to uncompress it.

Resolution:
Assuming /usr/bin is were hamachi's binary is in the computer, run the following commands

# sudo apt-get install upx-ucl
# cd /usr/bin    [Assuming /usr/bin is were hamachi's binary is]
# sudo upx -d hamachi
Ultimate Packer for eXecutables
Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007
UPX 3.01        Markus Oberhumer, Laszlo Molnar & John Reiser   Jul 31st 2007
File size         Ratio      Format      Name
--------------------   ------   -----------   -----------
830676 <-    331144   39.86%    linux/386    hamachi
Unpacked 1 file.

Try starting hamachi after that.

Thursday, October 29, 2009

Clone VirtualBox hard disk image

Since I am now testing VirtualBox performance, I need to clone existing guest image for multi-testing. This mini-HOWTO will guide you though the procedure for cloning a guest storage file for a new guest, under MS Windows host.

When following the official guideline and document, using VBoxManage clonehd command for disk clone, the result image is ALWAYS not functioning. Finally I figure out that a non-documented internal command is required: VBoxManage internalcommands sethduuid.

Within this artical, I am using the following system setup:

VirtualBox: v2.1.0

Host: MS Windows Vista Home Basic

Guest: Debian Lenny

Official procedure for cloning disk image (not function on MS Windows host)

Cloning an existing disk image for VirtualBox is much more than a simple copy command: it is because VirtualBox assigns a unique identity number (UUID) to each disk image, which also stored inside the image. VirtualBox will refuse to work with two image that use the same number. You need some extra handling.

According to official document, what you need is the console command VBoxManage clonehd, e.g. (host with MS Windows):

"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" clonehd hda.vdi hdb.vdi

or (host with Linux):

VBoxManage clonehd hda.vdi hdb.vdi

Therefore VirtualBox will copy your disk image, assign a new UUID for it, and import to its virtual media manager. You can now use it for your new guest system.

Alternative non-documented solution

As now you understand how the vboxmanage clonehd work around, what we needed is a new-and-unique UUID for our cloned disk image. There is a non-documented internal command which target for this procedure: VBoxManage.exe internalcommands sethduuid.

So what you needed for are:

(Optional) Shutdown your target guest before disk clone.

Manually copy the existing disk image, e.g.

copy hda.vdi hdb.vdi

Set a new UUID for the cloned disk, e.g.

"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" internalcommands sethduuid hdb.vdi

Manually add this newly cloned disk image though VirtualBox "Virtual Media Manager".

Create a new guest profile as old system, and point the primary harddisk to your newly cloned disk image.

(Document is retrieved from Google cache http://209.85.229.132/search?q=cache:http://edin.no-ip.com/content/clone-virtualbox-disk-image-ms-windows-mini-howto )

Monday, October 19, 2009

Managing Disk space with OpenVZ

You can increase the limit from the host system (VE0) only. This is how:

1. Get the current values for disk quota:

# vzquota stat 123
resource usage softlimit hardlimit grace
1k-blocks 327664 1048576 1153434
inodes 18857 200000 220000

2. To increase the disk space quota, use vzctl set --diskspace. For example, we want to increase it by a factor of 2:

vzctl set 123 --diskspace $(( 1048576*2 )):$(( 1153434*2 )) --save

3. To increase the disk inodes quota, use vzctl set --diskinodes. For example, we want to increase it by a factor of 3:

vzctl set 123 --diskinodes $(( 200000*3 )):$(( 220000*3 )) --save

Note: shell does not support floating-point arithmetics, i.e. you can not use expressions like $(( 220000*1.5 )). To use floating point, try bc instead, something like this: $(echo 220000*1.5 | bc).

Disk space and inodes are different things. Inodes identify the physical location on a disk where a file resides in unix filesystems. The inode count reflects the number of files on the server, not the amount of space used. This allows for multiple paths (hard links) to point to a single file.

A guide to running OpenVZ

By Joe 'Zonker' Brockmeier

One of the many virtualization options for Linux is OpenVZ, the free software component of SWsoft's Virtuozzo. OpenVZ, and Virtuozzo, are OS-level virtualization solutions that allow you to partition servers into multiple virtual private servers (VPS). Plowing through the OpenVZ documentation can be a bit intimidating, so let's walk through the easy way of getting started with OpenVZ on a Debian Etch system.
Last year, I reviewed Virtuozzo 3.0 for Linux, and I'd had some hands-on experience with prior versions of Virtuozzo from my days working with a hosting company in Denver. My budget doesn't have room for the Virtuozzo licensing, but OpenVZ fits my pocketbook just fine.
When would you want to use OpenVZ rather than VMware Server or Xen? It depends on the situation. For tasks where you don't want to run multiple OSes, but rather just multiple guests, in order to make the most of hardware or provide separation between services (for instance, separating your Web server from your file and print server) with minimal overhead, OpenVZ is a good choice. However, when you want to run non-Linux operating systems (such as FreeBSD or Windows Server) on top of a Linux host, you'd want to go with VMware rather than OpenVZ (or its commercial and proprietary big brother, Virtuozzo), since OpenVZ doesn't offer the ability to run multiple OSes.
OpenVZ also supports more processor platforms than the alternatives. VMware Server and Xen are available for x86 and AMD64, while OpenVZ is available for x86, AMD64, Itanium (IA64), PowerPC, and UltraSPARC.
Note that there are no pre-built PowerPC kernels for Debian at the moment, but OpenVZ is supported on PowerPC.
Installing OpenVZ
You can run OpenVZ guests on any host system. I'm running my guests on a Debian system, but you can use Ubuntu, Fedora Core, Gentoo, or any other distro that has an OS template. The OS template is the set of packages used to populate a VPS, AKA virtual environment (VE) in OpenVZ lingo.
Debian kernels for OpenVZ guests are available from the OpenVZ repository, but only for Etch. Grab the most recent kernel and linux-headers package from the OpenVZ repository, and install them using

dpkg -i linux-image-2.6.18-openvz-686_02_i386.deb

and

dpkg -i linux-headers-2.6.18-openvz-686_02_i386.deb .
Replace the package name with the name of the file that you download, of course. When I installed the packages, dpkg complained about two symlinks pointing to missing directories, but I haven't seen any problems while using OpenVZ, so as far as I can tell this isn't a problem.
Once you've installed the kernel and the headers, you'll want to add a few parameters (found on the the OpenVZ wiki) to /etc/sysctl.conf to prep the system for running OpenVZ. For example, you need to tell the system to enable IP forwarding so that the VPSes can have networking as well. Just add these lines to sysct.conf if they're not already present, or make sure they match:

net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

After installing the kernel and making these changes, you'll need to reboot the system. The OpenVZ kernel should be set to the default kernel in the GRUB menu already, so just rebooting should do the trick.
Next, you'll need to grab the OpenVZ utilities, using apt-get install vzctl. This will install the vzctl and vzquota packages, which include the utlities (like vzctl) that you need to use to manage OpenVZ.
OpenVZ will be set to start up at boot after you install these utilities, but if you want to start playing right away, you need to start up OpenVZ manually this time (or reboot). Start up OpenVZ by running the init script:
/etc/init.d/vz start

Setting up a guest system
So far so good. Now it's time to grab a few templates and set up a guest operating system. You can find precreated templates on the OpenVZ download site, including several versions of Fedora Core, Debian Sarge and Debian Etch, CentOS, Gentoo, Mandriva, and openSUSE. Note that templates are processor-specific, so be careful not to download the AMD64 or UltraSPARC version of a template if you're going to be running it on a x86 system.
You'll also notice that there's a contrib directory with OS templates from the OpenVZ community. These aren't "official" templates, but if you want to run Ubuntu, Slackware, AltLinux, or another distro not found with the OpenVZ templates, look here.
If you want to run a distro that doesn't have a template, see the OpenVZ wiki for documentation on creating OS templates. This is one area where OpenVZ is at a disadvantage to VMware and some of the other virtualization technologies. Installing a Linux distro in VMware Server or VMware Workstation is usually as simple as running through that distro's installation procedure. In OpenVZ it's much more complicated, and you'll need to learn a lot more about OpenVZ than you might want to just to run a couple of guest instances.
Downloaded OS templates need to be stored in /var/lib/vz/template/cache. The templates are tarred and gzipped when you download them, and you want to leave them that way -- don't uncompress them.
To set up a system, use the vzctl utlity. The bad news is that the vzctl utility is nowhere near as easy to use as the GUI tools that come with Virtuozzo. The good news is that vzctl isn't that difficult to use, it's scriptable, and it's free in every sense of the word. If you manage a lot of OpenVZ systems, you'll have the syntax down in no time, and if you don't create or muck with your OpenVZ guest systems very often, it shouldn't be too time-consuming to whip out the vzctl utlity man page and figure out the options you want. Let's take a look at the most common commands.
The syntax for creating a guest system is vzctl create vpsid --ostemplate ostemplatename . The vpsid is the number assigned to the new system. OpenVZ reserves IDs below 100 for internal use, so I usually start assigning IDs at 1001. So, for instance, if you download the Debian Sarge OS template for x86, you'd run:
vzctl create 1001 --ostemplate debian-3.1-i386-minimal
Once a guest host is set up, you can find its filesystem under /var/lib/vz/root/vpsid, and its private area under /var/lib/vz/private/vpsid -- unless you change the defaults using the --root or --private options. The private directory contains files specific to the virtual environment (VE).
So, if you created the guest as vz number 1001, its root filesystem would be under /var/lib/vz/root/1001. This may come in handy if you ever need to access the files directly for some reason -- for example, if the guest's admin has made a configuration that prevents the guest from booting normally -- or for backup purposes.

Now, let's set up networking. Again, this isn't terribly difficult:

vzctl set --ipadd ipaddr --nameserver nameserverIP --hostname hostname --save

The --ipadd parameter assigns the IP address to the first venet interface in the guest OS, the --hostname assigns the VPS its hostname, and the --nameserver paramter provides the first nameserver. The venet interface provided to OpenVZ guest systems by default does not have a MAC address, which means that (among other things) you cannot grab an address via DHCP for an interface.

However, the OpenVZ folks have added a new type of interface called a veth, which can provide a MAC address. The veth device also allows users to set up a DHCP server within the guest OS, and users can set their own network settings -- which is not possible using the venet devices. Whether this is desirable is another question. If you'd like to provide veth interfaces rather than venet interfaces, see the OpenVZ wiki for setup instructions.


Managing OpenVZ
Once the VPS is set up, go ahead and start the guest by running vzctl start vpsid , where vpsid is the ID that you assigned to the guest when you created it.
You should see a few messages logged to the console about starting the VPS, ending with "VPS start in progress..." You can see what VPSes are running with the vzlist command. After running vzlist, you should see something like this:

VPSID       NPROC         STATUS   IP_ADDR     HOSTNAME
1002              4                running     10.0.1.34   vroomfondle

Use the -a option to display all VPSes, whether they are running or not. You might also want to see what resources are being consumed by a VPS. To see how much memory is being used by a VPS, run
vzcalc -v vpsid
You should see something like this:

Resource    Current(%)        Promised(%)          Max(%)
Low Mem        0.13                   1.20                        1.20
Total RAM      0.55                   n/a                          n/a
Mem + Swap  0.36                  1.83                         n/a
Alloc. Mem     0.67                 1.83                         13.82
Num. Proc      0.06                  n/a                          0.40
--------------------------------------------------------------
Memory          0.67                   1.83                        13.82

This will show you how much memory is being used by the VPS, how much is allocated to the VPS, and what it can grow to.

You can also see other VPS parameters using the -o option. See the vzcalc man page for more information.
By default, VPSes will not be started up when you boot the system. In most situations, though, you probably do want VPSes to load after a system has restarted. You can change this setting using vzctl:
vzctl set vpsid --onboot yes --save
The vzctl utility is also used to set system parameters, including the amount of memory, CPU resources, access to iptables modules, and more. Let's look at a few examples.
One of the things that is frustrating about OpenVZ is that it's not straightforward to say "give a VPS 256MB of RAM"; instead, you have to adjust a couple of parameters and read through some fairly technical docs to try to make sense of the way that OpenVZ deals with memory.

To make things a bit simpler, let's look at setting a VPS with a minimum of 256MB of RAM, and up to 1GB. To do that, set the vmguarpages (that's the memory that's guaranteed to the VPS) and privvmpages (that's the maximum amount of memory that will be granted) parameters:

vzctl set vpsid --vmguarpages 65536 --save
vzctl set vpsid --privvmpages 262144 --save
I found another way to do this that is much more intuitive than calculating the amount of RAM by "pages" on the SWsoft forum. Just multiply the amount of RAM that you want by 256 as an easy way to arrive at the right amount of RAM:
vzctl set vpsid --vmguarpages $((256 * 256)) --save
vzctl set vpsid --privvmpages $((256 * 1024)) --save
Read the vzctl man page, as well as the OpenVZ wiki and other documentation, for more information.
As you set parameters for each VPS, the configuration settings are stored in /etc/vz/conf/vpsid.conf. If you make any changes to this file manually, you can use the vzcfgvalidate utility to make sure that the configuration file is correct.
Often, in hosting situations, you need to get into a system where the admin has changed the root password. With physical systems, you need to reboot the system and enter single-user mode to get root access to handle administrative tasks. With OpenVZ, all you need to do is log into the hardware node and use vzctl to log in:
vzctl enter vpid
That will log you into the VPS as root. After you've finished whatever admin tasks you need to perform, just type exit and you'll be returned to the session on the host system. Or, if you want to reset a password for a user, you can just use the --userpasswd option:
vzctl set vpsid --userpasswd user:passwd
If the user does not exist, it will be created.
If you'd like to run a command in a VPS without actually entering the VPS, you can use the exec parameter for vzctl to run a command as root. For example, if you want to run a quick upgrade inside a Debian VPS:
vzctl exec vpsid apt-get upgrade
This will run apt-get upgrade within the VPS itself.
To shut down a VPS, run vzctl stop vpsid, which will execute a clean shutdown within the VPS.
Running vzctl restart vpsid will restart the VPS. VPSes can also be shut down or rebooted normally from within the VPS.
So long, goodbye
So, your guest system has had a good run, but it's time to pack it in. For whatever reason, if you have a VPS that you'd like to get rid of, use the destroy command with vzctl:
vzctl destroy veid
A note of caution here: the vzctl utility does not ask for confirmation before destroying the VPS. As soon as you press Enter, that's all she wrote -- the VPS will be removed, its private data directories removed, and if you don't have a backup, you are up a creek without a paddle if you need to retrieve the data.

First openVZ installation with yum

So in short after having my bare bones install here is my quick and dirty easy to follow steps
from Scott's article:
1. cd /etc/yum.repos.d
2. wget http://download.openvz.org/openvz.repo
3. yum install ovzkernel
4. nano -w /etc/sysctl.conf with these changes:

______________________
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
# Enables the magic-sysrq key
kernel.sysrq = 1
# TCP Explict Congestion Notification
# net.ipv4.tcp_ecn = 0
# we do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

_____________________

5. Set the default kernel in grub to the new one
6. Reboot using the new kernel
7. yum install vzctl vzquota
8. service vz start
9. yum install vzpkg vzyum vzrpm43-python vzrpm44-python
10. yum install vztmpl-centos-4
11. nano -w /vz/template/centos/4/i386/config/default.list appending this:
yum
mc
links
system-config-date
nano
12. vzpkgcache -f centos-4
13. vzctl create 101 --ostemplate centos-4 --config vps.basic
14. vzctl set 101 --ipadd 192.168.0.101 --save
15. vzctl set 101 --hostname vps101 --save
16. vzctl set 101 --nameserver 192.168.0.1 --nameserver 192.168.0.2 --save
17. vzctl set 101 --userpasswd root:areallycoolpassword
18. vzctl set 101 --onboot yes --save
19. vzctl start 101
20. vzctl enter 101

Okay so that is it in a nutshell. Then this is where I start getting into trouble with my wild
ideas. I mentioned wanting to make this my backup server and I normally use Dirvish, but this
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
backups and I planned on just mounting it inside this new VPS.

Problem is I couldn't figure out
how to give it enough diskspace quota. The most it would give was from my 40GB drive and
that was a 34GB quota. So I called Scott and pretty much just decided to do LVM (logical
volume management) and merge the drives together to make it look like one big drive. This
however entailed starting from scratch again as I'm pretty lazy when it comes to trying to
figure out installing something like this after the fact.
So I find my single CentOS CD and attempt to boot it but my crappy old Dell has an abused
CD-R drive. So I borrow the one out of another Dell and off we go. So when I get back to the
point I was last, I run this:

vzctl set 101 --diskspace 315621376:315621376 --save

This gives me 301GB disk space to work with in my VPS. Problem is I was told by Scott there is
an rpm for BackupPC but currently there are no rpm's for CentOS. So this brings me to another
task... create another VPS with a distribution that includes rpm package management for
BackupPC. I found out the hard way that these guys are yet another that uses caps in their
package name and caused me a bit of headache searching for it.
I picked FC-5 for the new VPS as it seems to be the latest to carry BackupPC. To do this I
needed to build the template similar to building the CentOS template above.
yum install vztmpl-fedora-core-5
The rest was pretty much as stated above. Of course I forgot to edit the default.list and had to
later go back and update the cache after already creating the VPS with FC5. So I needed yum
installed on this to fill in the blanks and Scott to the rescue again; I could install this from the
host with:
vzyum 102 install yum
This is it for now. I have yet to configure BackupPC. I will have to blog about it later.

Friday, October 9, 2009

Configuring Static ip address in Linux (ubuntu/debian)

Like most desktops, mine was connecting to network using DHCP. While it is nice and automatic, it is often clumsy as the ip address (of the Desktop) usually changes after every reboot.

If you have only command-line access, here is a simple way to assign a static ip address (in my case it is 192.168.1.3) to your desktop. Make sure you consult your site administrator before doing that, as ip address and gateway ip address may vary.

There are two files that must be configured /etc/network/interfaces and /etc/resolv.conf.

Open /etc/network/interfaces in your favorite editor (mine being nano).? What you will most likely see is this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp

The last line is what you need to edit (and add to.) To configure eth0 (your network device) for a static IP address that last line should resemble:

iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1


Naturally you will need to change the last three lines to reflect your own networking setup.

Once that file has been edited you can restart your network connection with the command:

sudo /etc/init.d/networking restart

Now Configuring DNS

That file is /etc/resolv.conf. This file is in charge of holding your DNS server addresses. Open this file up in your editor. What you need are two lines:

nameserver 208.67.220.220

nameserver 208.67.222.222