Monday, November 30, 2015

Journal of Cloud Computing

Journal of CLoud Computing
http://www.journalofcloudcomputing.com/content

International Journal of CLoud Computing
http://hipore.com/ijcc/contents.html


5 Principles for Cloud Computing Success


cloud computingCloud computing is really coming into its own. After several years of predictions, we’ve finally seen adoption of some cloud technologies at the consumer level. Cloud storage, for example, has taken the marketplace by storm as companies like Dropbox get into the public cloud provider routine.
Meanwhile, companies continue to explore just how cloud computing solutions can meet their needs. Just because something is billed as a cloud solution, however, doesn’t mean it’s a good idea.
Here are five principles your company needs to follow if it’s going to have successful cloud computing deployments:
1.    Start with the essentials. The very best of the cloud computing implementations are those that offer the most basic services. Those services are then turned into specific solutions. For example, a good API design can take a single cloud implementation and turn it into a truly robust solution. Offer a number of low-level API services to the users, and you’ll dramatically increase both the utility and the value of the cloud solution.
2.    Use centrally-controlled but distributed components. You want to configure your solution in many different ways, but there has to be a central hub that controls all of it. One of the most common mistakes companies make is to either have cloud solutions that are too tight in terms of distribution, or that lack central control. Striking the balance between the two is essential.
3.    Use tenant design principles. When you’re designing a cloud system, you’re not designing for users; you’re designing for tenants. You need to figure out how the system will be able to allocate and manage its resources; you’re not controlling access to applications and to data.
4.    Use virtualization as a tool, not a requirement. Virtualization is a technology that enables the cloud; it’s not a necessary component. Cloud solutions don’t always mean virtualization. Use virtualization when it makes sense for what you’re doing, not simply because you can.
5.    Build security and governance into your cloud system. These are issues that must be addressed in your cloud design, and whose capabilities have to be inherent from design through deployment.

Sunday, November 29, 2015

How to send mails in POSTFIX through external SMTP



postfixThere are many reasons why you may want to do it. I have set it up on my POSTFIX because I have dynamic IP that is banned in most spam databases. I could get mails to my mailbox but could not reply to any as my IP was rejected by most of mail servers. But there is a quick solution.

Requirements
So what will you need? Not to much. All that you need to set it up is working Postfix server (we will make changes in it’s configuration file) and external e-mail account with SMTP access (probably 99% of e-mail account will be ok, for ex. Gmail). So if you want to send emails with external (relay your mail). Here is a quick howto.

Step 1: Edit your configuration file
You will need to make changes in your configuration file (in standard postfix configuration it would be /etc/postfix/main.cf). You need to add at the end of configuration file following lines:
relayhost = smtp.provider.com:25
 
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes
 
# optional: necessary if email provider uses load balancing and
# forwards emails to another smtp server
# for delivery (ie: smtp.yahoo.com --> smtp.phx.1.yahoo.com)
smtp_cname_overrides_servername = no
 
# optional: necessary if email provider
# requires passwords sent in clear text
smtp_sasl_security_options = noanonymous
Just make sure that you will edit “relayhost” (in first line of this listing), with your account SMTP address and port number.

Step 2: Generate password file
Postfix have to know your account login and password as most SMTP servers would not allow to rely emails from unauthorized connections. You will need to make a password file “/etc/postfix/sasl_passwd” with similar content:
# The server info must exactly match the value
# for "relayhost" in /etc/postfix/main.cf
smtp.provider.com:25 username:password
Now you need to generate POSTFIX lookup table (from previous file), with the following command:
$ postmap hash:/etc/postfix/sasl_passwd
You may test it by typing:
$ postmap -q smtp.provider.com:25 /etc/postfix/sasl_passwd
If you will get an output like “username:password” it means that password file has been generated correctly.
You can remove “/etc/postfix/sasl_passwd“. POSTFIX will not need it anymore.
It should be working now! Restart your POSTFIX and test it! If you have any problems please make a comment below. I will try to help you.

How To Install and Setup Postfix on Ubuntu 14.04

Introduction

Postfix is a very popular open source Mail Transfer Agent (MTA) that can be used to route and deliver email on a Linux system. It is estimated that around 25% of public mail servers on the internet run Postfix.
In this guide, we'll teach you how to get up and running quickly with Postfix on an Ubuntu 14.04 server.

Prerequisites

In order to follow this guide, you should have a Fully Qualified Domain Name pointed at your Ubuntu 14.04 server. You can find help on setting up your domain name with DigitalOcean by clicking here.

Install the Software

The installation process of Postfix on Ubuntu 14.04 is easy because the software is in Ubuntu's default package repositories.
Since this is our first operation with apt in this session, we're going to update our local package index and then install the Postfix package:
sudo apt-get update
sudo apt-get install postfix
You will be asked what type of mail configuration you want to have for your server. For our purposes, we're going to choose "Internet Site" because the description is the best match for our server.
Next, you will be asked for the Fully Qualified Domain Name (FQDN) for your server. This is your full domain name (like example.com). Technically, a FQDN is required to end with a dot, but Postfix does not need this. So we can just enter it like:
example.com
The software will now be configured using the settings you provided. This takes care of the installation, but we still have to configure other items that we were not prompted for during installation.

Configure Postfix

We are going to need to change some basic settings in the main Postfix configuration file.
Begin by opening this file with root privileges in your text editor:
sudo nano /etc/postfix/main.cf
First, we need to find the myhostname parameter. During the configuration, the FQDN we selected was added to the mydestination parameter, but myhostname remained set to localhost. We want to point this to our FQDN too:
myhostname = example.com
If you would like to configuring mail to be forwarded to other domains or wish to deliver to addresses that don't map 1-to-1 with system accounts, we can remove the alias_maps parameter and replace it withvirtual_alias_maps. We would then need to change the location of the hash to/etc/postfix/virtual:
virtual_alias_maps = hash:/etc/postfix/virtual
As we said above, the mydestination parameter has been modified with the FQDN you entered during installation. This parameter holds any domains that this installation of Postfix is going to be responsible for. It is configured for the FQDN and the localhost.
One important parameter to mention is the mynetworks parameter. This defines the computers that are able to use this mail server. It should be set to local only (127.0.0.0/8 and the other representations). Modifying this to allow other hosts to use this is a huge vulnerability that can lead to extreme cases of spam.
To be clear, the line should be set like this. This should be set automatically, but double check the value in your file:
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

Configure Additional Email Addresses

We can configure additional email addresses by creating aliases. These aliases can be used to deliver mail to other user accounts on the system.
If you wish to utilize this functionality, make sure that you configured the virtual_alias_maps directive like we demonstrated above. We will use this file to configure our address mappings. Create the file by typing:
sudo nano /etc/postfix/virtual
In this file, you can specify emails that you wish to create on the left-hand side, and username to deliver the mail to on the right-hand side, like this:
blah@example.com username1
For our installation, we're going to create a few email addresses and route them to some user accounts. We can also set up certain addresses to forward to multiple accounts by using a comma-separated list:
blah@example.com        demouser
dinosaurs@example.com   demouser
roar@example.com        root
contact@example.com     demouser,root
Save and close the file when you are finished.
Now, we can implement our mapping by calling this command:
sudo postmap /etc/postfix/virtual
Now, we can reload our service to read our changes:
sudo service postfix restart

Test your Configuration

You can test that your server can receive and route mail correctly by sending mail from your regular email address to one of your user accounts on the server or one of the aliases you set up.
Once you send an email to:
demouser@your_server_domain.com
You should get mail delivered to a file that matches the delivery username in /var/mail. For instance, we could read this message by looking at this file:
nano /var/mail/demouser
This will contain all of the email messages, including the headers, in one big file. If you want to consume your email in a more friendly way, you might want to install a few helper programs:
sudo apt-get install mailutils
This will give you access to the mail program that you can use to check your inbox:
mail
This will give you an interface to interact with your mail.

Conclusion

You should now have basic email functionality configured on your server.
It is important to secure your server and make sure that Postfix is not configured as an open relay. Mail servers are heavily targeted by attackers because they can send out massive amounts of spam email, so be sure to set up a firewall and implement other security measures to protect your server. You can learn about some security options here.
By Justin Ellingwood

Configure Postfix to Use Gmail SMTP on Ubuntu

If you want to use a Gmail account as a free SMTP server on your Ubuntu-Linux server, you will find this article useful. This guide is tested with Ubuntu 12.04. If you face any issue, feel free to use comments-section below.

Relaying Postfix mails via smtp.gmail.com:

First, install all necessary packages:
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
If you do not have postfix installed before, postfix configuration wizard will ask you some questions. Just select your server as Internet Site and for FQDN use something likemail.example.com
Then open your postfix config file:
vim /etc/postfix/main.cf
and following lines to it:
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
You might have noticed that we haven’t specified our Gmail username and password in above lines. They will go into a different file. Open/Create
vim /etc/postfix/sasl_passwd
And add following line:
[smtp.gmail.com]:587    USERNAME@gmail.com:PASSWORD
If you want to use your Google App’s domain, please replace @gmail.com with your @domain.com
Fix permission and update postfix config to use sasl_passwd file:
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
Next, validate certificates to avoid running into error. Just run following command:
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
Finally, reload postfix config for changes to take effect:
sudo /etc/init.d/postfix reload

Testing

Check if mails are sent via Gmail SMTP server

If you have configured everything correctly, following command should generate a test mail from your server to your mailbox.
echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com
To further verify, if mail sent from above command is actually sent via Gmail’s SMTP server, you can log into Gmail account USERNAME@gmail.com with PASSWORD and check “Sent Mail” folder in that Gmail account. By default, Gmail always keeps a copy of mail being sent through its web-interface as well as SMTP server. This logging is one strong reason that we often use Gmail when mail delivery is critical.
Once configured, all emails from your server will be sent via Gmail. This method will be useful if you have many sites on your server and want them all to send emails via Gmail’s SMTP server.
Alternatively, you can use a plugin like WP Mail SMTP so that mails from your particular WordPress site will be sent using Gmail’s SMTP server.
Please note that Gmail’s SMTP server has a limit of 500 emails per day. So use wisely! :-)

Troubleshooting

Error: “SASL authentication failed; server smtp.gmail.com”
You need to unlock the captcha by visiting this pagehttps://www.google.com/accounts/DisplayUnlockCaptcha
You can run test again after unlocking captcha.
P.S. Do not miss out on our other helpful tutorials. Join us on twitter and facebook for more updates.

Friday, November 20, 2015

Postfix Flush the Mail Queue

Traditionally you use the "sendmail -q" command to flush mail queue under Sendmail MTA. Under Postfix MTA, just enter the following command to flush the mail queue:
# postfix flush
OR
# postfix -f
 see mail queue, enter:
# mailq
To remove all mail from the queue, enter:
# postsuper -d ALL
To remove all mails in the deferred queue, enter:
# postsuper -d ALL deferred

postfix-delete.pl script

Following script deletes all mail from the mailq which matches the regular expression specified as the first argument (Credit: ??? - I found it on old good newsgroup)
#!/usr/bin/perl
 
$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";
 
@data = qx</usr/sbin/postqueue -p>;
for (@data) {
  if (/^(\w+)(\*|\!)?\s/) {
     $queue_id = $1;
  }
  if($queue_id) {
    if (/$REGEXP/i) {
      $Q{$queue_id} = 1;
      $queue_id = "";
    }
  }
}
 
#open(POSTSUPER,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
 
foreach (keys %Q) {
  print POSTSUPER "$_\n";
};
close(POSTSUPER);
 
For example, delete all queued messages from or to the domain called fackspamdomain.com, enter:
./postfix-delete.pl fackspamdomain.com
Delete all queued messages that contain the word "xyz" in the e-mail address:
./postfix-delete.pl xyz
Updated for accuracy.

Tuesday, November 17, 2015

HPC Leaders Unite to Develop Open Source Framework


SAN FRANCISCO, Calif. and AUSTIN, Tex., Nov. 12 — The Linux Foundation, the nonprofit organization dedicated to accelerating the growth of Linux and collaborative development, today announced an intent to form the OpenHPC Collaborative Project. This project will provide a new, open source framework to support the world’s most sophisticated High Performance Computing environments.
The new initiative includes support from Allinea Software, Altair, ANSYS, Argonne National Laboratory, Atos, Barcelona Supercomputing Center, The Center for Research in Extreme Scale Technologies at Indiana University, Cray, Dassault Systemes SIMULIA, Dell, Fujitsu Systems Europe, Hewlett Packard Enterprise, Intel Corporation, Jülich Supercomputing Centre, Lawrence Berkeley National Laboratory, Lawrence Livermore National Laboratory, Leibniz Supercomputing Centre, Lenovo, Los Alamos National Laboratory, MSC Software, NEC, Oak Ridge National Laboratory, Pacific Northwest National Laboratory, ParTec, Penguin Computing, Pittsburgh Supercomputing Center, Sandia National Laboratories, SENAI CIMATEC, SUSE and Texas Advanced Computing Center.
For more than four decades, HPC has been used by universities and research centers for large-scale modeling and calculations required in meteorology, astronomy, engineering and nuclear physics, big data science, among others. With unique application demands and parallel runtime requirements, software remains one of the biggest challenges for HPC user adoption (See IDC Worldwide HPC Server 2015-2019 Forecast). Open source and Linux-based software components have become a standard way to reliably test and maintain stable operating conditions while providing a cost-effective means for scaling with data growth.
OpenHPC will provide a new, open source framework for HPC environments. This will consist of upstream project components, tools, and interconnections to enable the software stack. The community will provide an integrated and validated collection of HPC components that can be used to provide a full-featured reference HPC software stack available to developers, system administrators and users. OpenHPC will provide flexibility for multiple configurations and scalability to meet a wide variety of user needs.
OpenHPC members plan to work together to:

Create a stable environment for testing and validation: The community will benefit from a shared, continuous integration environment, which will feature a build environment and source control; bug tracking; user and developer forums; collaboration tools; and a validation environment.

Reduce Costs: By providing an open source framework for HPC environments, the overall expense of implementing and operating HPC installations will be reduced.

Provide a robust and diverse open source software stack: OpenHPC members will work together on the stability of the software stack, allowing for ongoing testing and validation across a diverse range of use cases.

Develop a flexible framework for configuration: The OpenHPC stack will provide a group of stable and compatible software components that are continually tested for optimal performance. Developers and end users will be able to use any or all of these components depending on their performance needs, and may substitute their own preferred components to fit their own use cases.

“The use of open source software is central to HPC, but lack of a unified community across key stakeholders — academic institutions, workload management companies, software vendors, computing leaders — has caused duplication of effort and has increased the barrier to entry,” said Jim Zemlin, executive director, The Linux Foundation. “OpenHPC will provide a neutral forum to develop an open source framework that satisfies a diverse set of cluster environment use-cases.”
For more information about OpenHPC or to become a member, please visit www.openhpc.community.
About The Linux Foundation
The Linux Foundation is a nonprofit consortium dedicated to fostering the growth of Linux and collaborative software development. Founded in 2000, the organization sponsors the work of Linux creator Linus Torvalds and promotes, protects and advances the Linux operating system and collaborative software development by marshaling the resources of its members and the open source community. The Linux Foundation provides a neutral forum for collaboration and education by hosting Collaborative Projects, Linux conferences including LinuxCon, and generating original research and content that advances the understanding of Linux and collaborative software development. More information can be found at www.linuxfoundation.org.




Sunday, November 15, 2015

Export and Import all MySQL databases at one time

I want to keep a backup of all my MySQL databases. I have more than 100 MySQL databases. I want export all of them them at the same time and again import the all of them into my MySQL server at one time. How can I do that?


Export:

mysqldump -u root -p --all-databases > alldb.sql
 
Look up the documentation for mysqldump. You may want to use some of the options mentioned in comments:
 
mysqldump -u root -p --opt --all-databases > alldb.sql
 
mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql

Import:

mysql -u root -p < alldb.sql
 
 

How clone a KVM virtual machine on Ubuntu Server



NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.

Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.

Before you can clone a virtual machine (vm) you first need to install the relevant package:

sudo apt-get install python-virtinst

Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:

virsh --connect qemu:///system list --all


This should produce output similar to the following:

$ virsh --connect qemu:///system list --all

    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....


If the machine you wish to clone is currently running then issue the following command to shut it down:

virsh --connect qemu:///system shutdown TheVMYouWishToStop

where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!

Once the machine has been shut down you issue the following command to clone it:

virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.qcow2

where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.

The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:
My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:

sudo rm /etc/udev/rules.d/70-persistent-net.rules


Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:

sudo vim /etc/hosts

sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:

mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try

Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:

sudo vim /etc/fstab

Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf

How clone a KVM virtual machine on Ubuntu Server

NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.
Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.
Before you can clone a virtual machine (vm) you first need to install the relevant package:
sudo apt-get install python-virtinst
Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:
virsh --connect qemu:///system list --all
This should produce output similar to the following:
$ virsh --connect qemu:///system list --all
    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....
If the machine you wish to clone is currently running then issue the following command to shut it down:
virsh --connect qemu:///system shutdown TheVMYouWishToStop
where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!
Once the machine has been shut down you issue the following command to clone it:
virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.gcow2
where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.
The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:

My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:
sudo vim /etc/hosts
sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:
mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try
Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:
sudo vim /etc/fstab
Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf

How clone a KVM virtual machine on Ubuntu Server

NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.
Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.
Before you can clone a virtual machine (vm) you first need to install the relevant package:
sudo apt-get install python-virtinst
Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:
virsh --connect qemu:///system list --all
This should produce output similar to the following:
$ virsh --connect qemu:///system list --all
    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....
If the machine you wish to clone is currently running then issue the following command to shut it down:
virsh --connect qemu:///system shutdown TheVMYouWishToStop
where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!
Once the machine has been shut down you issue the following command to clone it:
virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.gcow2
where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.
The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:

My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:
sudo vim /etc/hosts
sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:
mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try
Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:
sudo vim /etc/fstab
Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf

How clone a KVM virtual machine on Ubuntu Server

NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.
Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.
Before you can clone a virtual machine (vm) you first need to install the relevant package:
sudo apt-get install python-virtinst
Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:
virsh --connect qemu:///system list --all
This should produce output similar to the following:
$ virsh --connect qemu:///system list --all
    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....
If the machine you wish to clone is currently running then issue the following command to shut it down:
virsh --connect qemu:///system shutdown TheVMYouWishToStop
where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!
Once the machine has been shut down you issue the following command to clone it:
virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.gcow2
where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.
The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:

My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:
sudo vim /etc/hosts
sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:
mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try
Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:
sudo vim /etc/fstab
Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf

How clone a KVM virtual machine on Ubuntu Server

NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.
Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.
Before you can clone a virtual machine (vm) you first need to install the relevant package:
sudo apt-get install python-virtinst
Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:
virsh --connect qemu:///system list --all
This should produce output similar to the following:
$ virsh --connect qemu:///system list --all
    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....
If the machine you wish to clone is currently running then issue the following command to shut it down:
virsh --connect qemu:///system shutdown TheVMYouWishToStop
where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!
Once the machine has been shut down you issue the following command to clone it:
virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.gcow2
where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.
The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:

My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:
sudo vim /etc/hosts
sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:
mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try
Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:
sudo vim /etc/fstab
Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf

How clone a KVM virtual machine on Ubuntu Server

NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.
Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.
Before you can clone a virtual machine (vm) you first need to install the relevant package:
sudo apt-get install python-virtinst
Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:
virsh --connect qemu:///system list --all
This should produce output similar to the following:
$ virsh --connect qemu:///system list --all
    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....
If the machine you wish to clone is currently running then issue the following command to shut it down:
virsh --connect qemu:///system shutdown TheVMYouWishToStop
where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!
Once the machine has been shut down you issue the following command to clone it:
virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.gcow2
where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.
The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:

My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:
sudo vim /etc/hosts
sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:
mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try
Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:
sudo vim /etc/fstab
Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf

How clone a KVM virtual machine on Ubuntu Server

NOTE: This guide has been tested on Lucid Lynx 10.04 & Karmic Koala 9.10 although it may work equally well on earlier or later version of Ubuntu.
Following on from the guide showing you how to install KVM, one of the things that's very useful when using virtual machines is the ability to clone them.
Before you can clone a virtual machine (vm) you first need to install the relevant package:
sudo apt-get install python-virtinst
Once the package is installed you then need to ensure the machine you are about to clone is shutdown before you attempt to clone it. You can check the state of the machine by issuing the following command:
virsh --connect qemu:///system list --all
This should produce output similar to the following:
$ virsh --connect qemu:///system list --all
    Connecting to uri: qemu:///system
    Id Name State
    ----------------------------------
    2 MediaServer    running
    3 WindowsXP1    running
    4 UbuntuServer   shut off
    .....
    .....
If the machine you wish to clone is currently running then issue the following command to shut it down:
virsh --connect qemu:///system shutdown TheVMYouWishToStop
where TheVMYouWishToStop is the name of the VM you wish to stop. As mentioned in the previous guide, for Ubuntu machines you need to have installed acpid before you can close the machine down gracefully. If acpid is not installed then you can still halt the machine by issuing destroy instead of shutdown. The destroy argument is equivalent to pulling the power cord on the machine so it's quite brutal and can result in data loss and/or corruption. So you really should install acpid!
Once the machine has been shut down you issue the following command to clone it:
virt-clone --connect=qemu:///system -o CurrentVM -n NewVM -f /home/htkh/VMs/NewVM.gcow2
where CurrentVM is the name of the VM you wish to clone, NewVM is the name for the new VM and NewVM.gcow2 is the name of the physical file the VM will be stored in. Be sure to include the full path.
The new cloned machine should work without issue but I did come across a few gotcha's when cloning Ubuntu VMs that you should be aware of:

My cloned Ubuntu VM is not visible on my network

Although the original VM was able to see the network and was visible to other clients on the network the cloned VM was not. The clone would not get an IP address from my router. Even assigning a static IP address did not help. There is a workaround tho: You firstly need to gain console access to your cloned VM. This is simple if you've installed Virtual Machine Manager on your host. After gaining console access simply issue the following command:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
Then reboot the VM (reminder: sudo reboot -h now) and you should now have full network access to and from your cloned VM.

My cloned Ubuntu VM is conflicting with the original VM on my network

When you clone a VM you need to update the hostname for the cloned machine. If you don't then your network may act strangely. So change the hostname by updating the following two files on your cloned VM to give your new VM a unique hostname:
sudo vim /etc/hosts
sudo vim /etc/hostname

My cloned Ubuntu VM keeps giving me a mountall:cancelled error

If you clone an Ubuntu VM that is running NFS then you will receive the following error each time you try and edit a file on the cloned machine:
mountall:cancelled General error mounting filesystems. A maintenance shell will now be started. CONTROL-D will terminate this shell and re-try
Unfortunately I've not found a way to work round this problem AFTER you've cloned your VM. However, if you un-mount the NFS exports on the donor machine BEFORE cloning it then you will not get this error. Once you've cloned the machine simply re-mount the exports on both the original VM and the cloned VM. You can un-mount the NFS export by editing the /etc/fstab file and masking out the relevant exports/mounts:
sudo vim /etc/fstab
Once you've cloned the machine then simply unmask the exports/mounts on both machines.
- See more at: http://www.havetheknowhow.com/Configure-the-server/KVM-clone-a-vm.html#sthash.TC3o17sp.dpuf