The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.5.

June 25th, 2012 by Andrea Matesi 2181 Views

[Bonus]: INDEPENDENT VMs!

Once you decide your Child VM is "mature enough" to stand on its own (i.e.: you want to separate your Child VM from your Father VM, such as to create an "independent" VM), you can simply create a new "traditional" vhd, plug it into your Child VM, then a simple dd-magic command should get you covered!

Here's how to do it:

Boot your Child VM at least once, so it generates the new SSH Keys (no need to login).

Shut it  down.

Go to the VM Settings (by now you should already know how to do this), then ADD a new dynamic hard drive (that's right, add a second hard drive to your Child VM).

PRECISELY IDENTIFY your /dev/sdX hdds.

Download Gparted iso, attach the ISO to your Child VM's DVD Drive (by now you should already be an expert at this), then boot the system from the Gparted ISO.

Open "Partition Editor" and make sure you PRECISELY IDENTIFY your drives (mine are the usual /dev/sda and /dev/sdb).

Open a Terminal

Close the "Partition Editor" application and Open the terminal.

Input the following command (again, make sure you know which ones are your drives):

DCFLDD running.

dcfldd if=/dev/sda of=/dev/sdb statusinterval=10 bs=10M conv=notrunc

 

dcfldd is like a dd on stereoids (but with true muscles!) and it shows you some progress, so you can have a visual clue on what's happening.

 

Once the process is finished, you can shutdown your Child VM.

Go back to your Child VM Settings, then remove the Gparted iso image from your DVD Drive (or remove the whole drive...).

Go to the Hard Disk section, then remove the first original, Differencing vhd.

Configure your second VHD as the "first" on your controller.

Boot your Child VM.

Congratulations! Now you should have a new INDEPENDENT Virtual Machine!

Here we have:

  • "Centos6.2X64.vhd" is the Father VHD.
  • "201.pwrusr.com-dev1.vhd" is the Differenching, Child VM's VHD.
  • "201.pwrusr.com-dev1-hd2.vhd" is the new independent VHD.

Please note how smart the VHD format is: it always kept the size of you cloned VHDs at a minimum! I second what I affirmed once:"both Hyper-V and CentOS are great products"!

Posted in LINUX, Microsoft, System Administration | Comments Off on The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.5.

The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.4.

June 19th, 2012 by Andrea Matesi 2602 Views

Hi, hope you've followed my previous articles (over the last couple of days I've been pretty busy...), since this article builds on the previous ones.

Just in case you missed them, here, have a look:

  1. The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.1 - A Summary.
  2. Download the programs needed.
  3. Create the "Father" VM (a New, independent VM).

As of now, I'm assuming you've just followed what I've explained so far (you may have skipped the [OPTIONAL STEPS] from my last article, but that's alright: they're optional for a reason!).

Anyway, it's now time to create the "Child Virtual Machine", a new VM that, to function properly, will depend from the previous Father VM.

Why would you want to have 2 VMs depending one-another? Read my first article from the series, The Summary, then tell me what you think!

Preparing the Father VM for distribution.

Before creating new Children VMs based on our Father VM, we need to prepare the Father first.

The preparation process is just a matter of deleting some files (which will be recreated automatically upon boot, inside the new Child VM).

From the Hyper-V main Window, login to the terminal console, then launch the following commands:

rm -f /etc/udev/rules.d/70-persistent-net.rules
rm -f /etc/ssh/ssh_host*key*
halt

  1. The first command will delete the udev rule used to assign the "ethX" tag to a new Ethernet device. By deleting this file, you're making sure that, upon the next reboot inside the new Child VM, the new Ethernet Device will automatically acquire the name "eth0" name. Please note that this file is automatically created upon reboot.
  2. The second command will delete the SSH keys automatically generated by the host. To prevent creating many Child VMs with the same SSH host keys, just delete them. Upon booting inside any new Child VM, those keys will be automatically re-generated (this way you'll have new Child VMs with new keys).
  3. The 3rd command will simply shutdown the Father VM.

After shutting down your Father VM, locate, use [Win]dows [E]xplorer to locate your Father VM's "VHD Image file" (i.e.: by opening D:\Data\HyperV\CentOS-6.2.vhd), Right Click on the "Father VHD image file", choose "Properties", then put a flag on the "Read-only" box and Click "Ok" to confirm.

Set your original Father VM VHD Image to "READ ONLY".

Set your original Father VM VHD Image to "READ-ONLY".

 

Once you're sure your Father VM has been flagged as "Read-only" (this also implies you won't touch it anymore), you can proceed to create a New 2nd Child VM.

The procedure is similar to the one you've followed while creating the Father VM: first create a new VHD, then create a new VM, then attach the new VHD to your new VM.

I'll show you the step-by-step process, no worries.

New Child Differencing VHD.

From the Hyper-V Main Window:

Create a new vhd by clicking on "New" > "Hard Disk..."

This time we'll create a new "Differencing" Virtual Hard Disk Drive, which will technically store the differencing data not found inside the Father VM VHD Image. In other words, this Child VHD Image will contain only the files and the programs that you'll choose to install into this new Virtual Machine (which are not present on the Father VM). Also, any updated application or program will increase the size of the Child VM.

 

This time you'll create a "Differencing" vhd...

On the "New Virtual Hard Disk Wizard" you'll select "Differencing" Virtual Hard Disk.

 

Here you'll simply specify where the "Child Differencing VHD Image" will be located.

Here you'll simply specify where the "Child Differencing VHD Image" will be located.

Name this Child Differencing VHD Image such as to help you easily identify it and pay attention not to confuse this image with the Father VHD-one, then Press Next to Continue.

 

Here you'll specify the "Father VHD Image".

Pay attention: here you'll specify which one is the "Father VHD Image" of the previously-defined "Child Differencing Image".

Press Next to continue, then you'll be presented with a Summary of your selected options. Verify that everything is correct, then press "Finish" to end the "New Virtual Hard Disk Wizard".

 

New Child Virtual Machine.

Now, from the Hyper-V main window, you'll create the Child Virtual Machine.

Click on "New" -> "Virtual Machine..."

Click on "New" -> "Virtual Machine..." and the "New Virtual Machine Wizard" will begin.

 

The New Virtual Machine Wizard.

Name your new Child Virtual Machine to something that will help you recognize it (i.e.:CentOS-6.2x64-diff), and specify where your new Virtual Machine configuration files will be located then click "Next" to continue.

 

Specify how much RAM to assign to your new vm.

Specify the amount of memory to assign to your VM, depending from the available memory on your computer.

 

Select a network adapter on your lan capable of going online (ie.External Virtual Network).

Select a network adapter from your LAN capable of going online (i.e.:your "External Virtual Network" adapter). It is not essential, but it's good give your new VM internet connectivity after CentOS-minimal has been installed.

 

Specify the Child VHD to attach to your New Child VM.

Pay attention here: Select "Use an existing virtual hard disk", then "Browse..." for your previously created Child VHD (i.e.:D:\Data\HyperV\CentOS6.2x64-diff.vhd), to be attached to your Child VM.

Press Next, have a look at the Summary page, then press Finish to end the "New Virtual Machine Wizard".

Well done: now those 2 virtual machines are linked by a Father-Child relationship.

IF the Father VM is modified or missing somehow -> the Child VM won't be able to boot anymore (that's why, at the beginning of this article, I showed you how to set the Father VHD image to "Read-only").

On the contrary, now you can do whatever you desire inside your Child VM - not only: you can make as many children copies as you wish.

Simply repeat the procedure explained by this article to create additional Children VMs!

You can simply boot your New Child VM while the Father VM is OFF!

While the Child VM boots, it will first read the Father VM's VHD, then will act upon its own VHD.

Some Considerations.

This procedure brings obvious advantages that will help you streamline your VM deployment.

The only disadvantage that comes to mind is, say you have 10 Children VMs, all depending from a single Parent VM: the Storage device holding the Parent VM will be under more stress as a result.

This is not always true, it highly depends on how you're going to use your Children VMs, but rest assured that if you're booting 10 VMs at once you will experience some bottlenecks.

Example:

Say you create a Parent VM, then create a couple of Children VMs, then install additional software on your Children VMs and limit yourself using only the services provided to you by the additional software and keep adding/reading data localized to every Children VMs (i.e.:apache, mysql, etc.): no worries here, the Parent VM will be read once and forgotten.

On the opposite side, say you need to read a lot from the kernel (and in the meantime you didn't update it from inside your new Child VM - which I'd say it is highly unlikely): on this particular scenario, the "reads" will be against your Parent VM and the "writes" will be against your Child VM.

That's the only scenario I can  think of as a "disadvantage": a very specific situation that won't affect the majority of users!

Other than that, the process is safe and works perfectly fine for your development purposes.

But I'm not over yet: over my next article I will present you a practical solution on how to definitively BREAK this parent-child relationship and allow you to create independent VMs starting from Children VMs.

So, if you had doubts about the potential disadvantage described above, look no further.

Follow me on twitter at https://twitter.com/amatesi and you'll get free updates about my new articles!

Posted in LINUX, Microsoft, System Administration | Comments Off on The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.4.

The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.3.

June 10th, 2012 by Andrea Matesi 5914 Views

Now it's time to create the Father Virtual Machine, install CentOS-minimal, then install the "Linux Integration Services for Hyper-V" component on it.

First you'll have to create a New Dynamic Virtual Hard Disk Drive (the VHD), then a New Virtual Machine, based on your New Dynamic VHD Drive.

New Father Dynamic VHD.

From the Hyper-V main Window.

"New" -> "Hard Disk..."

Create a new dynamically expanding hdd by clicking on "New" > "Hard Disk..."

 

Choose "Dynamically expanding" vhd.

Select "Dynamically expanding" VHD.

 

Specify New vhd Name and Location.

Specify the New VHD Name and Path.

 

Specify the size of your Virtual Hard Disk Drive.

Specify the size of your Dynamically Expanding Virtual Hard Disk Drive or just leave the default of 127GB as I did. A Dynamically expanding VHD will only use as much space as necessary, by allocating it on an incremental basis.

 

Summary page showing you the details of your chosen options.

This is the summary page, showing you all the details of your chosen options.

After following the previous steps, you'll end up with a very small VHD image, occupying something like ~256K.

 

New Father Virtual Machine.

Now, from the main Hyper-V window, you'll create a new Virtual Machine with the "New Virtual Machine Wizard" and attach the previously created Dynamic VHD to this Father VM.

Click on "New" -> "Virtual Machine..."

Click on "New" -> "Virtual Machine..." and the "New Virtual Machine Wizard" will start.

 

the New Virtual Machine Wizard.

Name your new Virtual Machine (i.e.:CentOS-6.2-dist), and specify where your new Virtual Machine configuration files will be located, then click "Next".

Please note the "VM config files" and the "VHD image" created on the previous section are two separate things.

 

Specify how much RAM to assign to your new vm.

Specify how much memory to assign to your VM (i.e.: <512MB for a text installer or 1024MB for the GUI installer), depending from the memory available on your computer.

 

Select a network adapter on your lan capable of going online (ie.External Virtual Network).

Select a network adapter from your LAN capable to go online (i.e.:your "External Virtual Network" adapter). It is not essential, but it's good to offer internet connectivity to your new VM after CentOS-minimal has been installed.

 

Specify where your vhd image is located.

Pay attention to this particular step: here you'll need to specify where your "VHD image" is located for your VM to use.

 

Specify where your CentOS-minimal ISO image is located.

Here you'll specify where your CentOS-minimal ISO image is located (you downloaded this image at the beginning of the tutorial - i.e.:D:\LINUX\). Then click next, read the Summary page and check if everything it's alright, then click finish to end the "New Virtual Machine Wizard".

 

Install CentOS-minimal to your New Father VM.

It's now time to install CentOS-minimal on your newly-created VM.

Select your newly created Father VM.

On the main Hyper-V window, select the Virtual Machine and Click "Settings..."

Open your VM Settings.

Click "BIOS", verify that "Boot from CD" is selected and/or make sure CD appears as first on "Startup order", then Click Ok.

Back on the Hyper-V main window, select the Father VM, then click "Start..." to boot it.

If the previous settings are correct, the CentOS boot installer will start automatically.

CentOS-minimal installer boot screen.

The CentOS-minimal installer boot screen.

Select "Install or upgrade an existing system" (it's autoselected and if you just wait for 60 secs. it will autostart), then Press Enter and follow the on-screen instructions.

  • Please note that once your mouse cursor is focused inside the CentOS window, you won't be able to interact with the other windows. To regain control of your mouse cursor, press CTRL+ALT+LEFT-ARROW.

 

CentOS-minimal text installer.

If you specified a small amount of RAM during your "New Virtual Machine Configuration Wizard", you may be welcomed by a text installer.

No matter how your installer is, in 2012, the CentOS setup has become a matter of "Next", "Next", "Next", especially so for CentOS-minimal, where the amount of customization is almost non-existent.

During the installation wizard, you'll be asked to choose a password for the root user. Input this password and record it somewhere (don't lose it because you''ll need it later).

 

Feel free to have a break now :)

Make a screenshot of this window or save it, because by following my tutorial you're not gonna see it anymore (or at least for a little while)!

Then Click the "Reboot" button to reboot your New CentOS-minimal VM.

 

Install the Linux Integration Services for Hyper-V.

It's now time to install the Linux Integration Services for Hyper-V on your Father VM.

Once your New VM rebooted, you'll be shown a console with a login prompt.

Now you'll need to go back to your Virtual Machine Settings (even if it is running, don't worry!), then attach the "Linux Integration Services for Hyper-V" ISO Image to your Father VM DVD Drive.

Select your VM from the Hyper-V VMs list.

Select your Father VM.

 

Open your VM Settings.

Click on "Settings..." to open the New VM Settings.

 

DVD Drive Properties Window.

Select your DVD Drive, Click on "Image File" and "Browse..." for your "Linux Integration Services for Hyper-V" ISO image, then Click "Ok" to confirm.

 

At this point, you'll need to "slide your hands into the jam" (I like this Italianism (Italian colloquialism)), by typing some bash commands into your Linux Console Window.

Click inside a black part of your terminal window and let the window get the focus (your cursor will feel as being captured like a fly on a spider web - but don't worry, it's just CentOS!).

Input your CentOS credentials that you specified during the setup process (i.e.: root/p@ssw0rd), to login to your VM.

Once you are logged in, you'll be welcomed by a terminal prompt followed by a blinking cursor.

Input the following commands to install your Linux Integration Services for Hyper-V:

Installing Linux Integration Services for Hyper-V on CentOS.

mount -r /dev/sr0 /media
cd /media
./install.sh

Then read the on-screen instructions and wait...seriously, just be patient :)

Once the Linux Integration Services for Hyper-V are installed, type "reboot" and press ENTER to reboot your VM.

Linux Integration Services for Hyper-V installed successfully, time to reboot!

Once your Father VM reboots, you'll end up with a working system that won't catch your mouse anymore (like a fly on a spider web as before...).

Technically speaking, your new VM is now "enlightened" (sounds too cool, isn't it?), and now the kernel loads a module that, basically, allows it to communicate with the Hyper-V host on a more "intimate way".

[OPTIONAL] Now maybe the perfect timing to configure CentOS Networking, download and install some applications/updates and, if you're a pro, generalize and customize the distribution according to your possible scenarios ;-).

That's it for now, follow me on twitter to receive free notifications about my next articles in the series, where I'll show you how to create the 2nd Child (dependant) VM and finish the series with an article which will show you how to break the father-child relation.

Posted in LINUX, Microsoft, System Administration | 3 Comments »

The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.2

June 6th, 2012 by Andrea Matesi 3875 Views

Assumptions.

This guide is built assuming the following software:

  • Microsoft Windows 2008 R2 SP1 with the Hyper-V Role enabled.
  • CentOS-6.2-x86_64-minimal.iso.
  • Linux Integration Services for Hyper-V 3.2.

Download CentOS-minimal.

The first thing to do is download an updated CentOS-minimal distribution.

I suggest you get the x64 build because Windows Server 2008 R2 SP1 works natively on 64bit CPUs only. CentOS-6.2-x86_64-minimal is a RedHat derivative, so it is supported by the Hyper-V Host and by the Linux Integration Services for Hyper-V (version 3.2 at the moment of this writing).

You can download CentOS-6.2-x86_64-minimal.iso from the following address:

http://isoredirect.centos.org/centos/6/isos/x86_64/

Remember to download "CentOS-minimal" (NOT CentOS-network - refer to the note below why not), because:

  1. Is the smallest (after CentOS-network).
  2. It allows you to have a full OS up-and-running without depending on the network configuration.

Then store it somewhere where it makes sense for you, say D:\LINUX\

Download Linux Integration Services for Hyper-V.

Once we're at downloading, fetch the latest Linux Integration Services for Hyper-V from Microsoft.

The latest version, at the time of this writing, was version 3.2 and can be downloaded from the following address:

http://www.microsoft.com/download/en/details.aspx?id=28188

Save it to where you can find it!

That's all for the "downloading part".

Over the next article I'll show you how to create a new CentOS VM inside your Hyper-V Host.

CentOS-network Note.

Please note that even if CentOS-network is actually smaller than CentOS-minimal, if you try and follow my guide with CentOS-network, you won't be able to proceed with the setup process, because CentOS-network isn't able to recognize the Hyper-V network adapters (not the Legacy nor the Synthetic one).

This happens because CentOS-network (as the name suggests) depends on the network for the successful installation process. CentOS-minimal, instead, does not depend on the network and offers you a booting environment straight away.

Been there, done that ;-)

Andrea Matesi when tried to install CentOS-network. Been there, done that!

This is what is gonna happen if you attempt to follow my guide with CentOS-network. You've been warned...

Posted in LINUX, Microsoft, System Administration | Comments Off on The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.2

The fastest CentOS VM Deployment on MS Hyper-V Servers - Pt.1.

June 1st, 2012 by Andrea Matesi 6684 Views

Intro.

This article series is related to my latest speech at the Linux SA Meeting on Tuesday May 15th, somehow related to my previous post about CentOS Networking configuration ([SOLVED] CentOS 6 networking and Hyper-V) and to my recently released VHD/Virtual Appliances (New Centos-6.2-x86_64-minimal Hyper-V VHD - Ubuntu 12.04 LTS X64 Desktop Hyper-V Virtual Appliance available & Ubuntu 12.04 LTS X64 Server Hyper-V Virtual Appliance available).

On this series I'm going to show you how to efficiently deploy new CentOS Virtual Machines inside your Microsoft Windows Server 2008 R2 SP1 with the Hyper-V Role enabled.

Please note that this is also the fastest way to deploy new CentOS VMs on your lab since you don't have to go through the whole setup procedure again and again and it could be scaled as-well for your production environments and/or datacenter environments, by using a combination of Microsoft Hyper-V Server 2008 R2 (which is the freeware, CLI-only Hypervisor Edition), and the automation offered by the PowerShell scripting environment.

Once you prepare your main VHD, the VM provisioning is streamlined and New CentOS VMs are ready in no time.

This article series is aimed at those who wish to prepare their own set of virtual appliances (and have plenty of time, patience and resources).

If you wish to get up and running, simply Download my ready-made Virtual Appliances and off you go: no need to wait for the whole article series to be released :O

The procedure described could be adapted to other (Supported) Linux Distributions like Red Hat and Novell, to unsupported (but reported to work) Ubuntu/Debian (recent news has Ubuntu not even needing the Linux Integration Services for Hyper-V since the mouse seems to be working even during the setup process!), and of course, to the Microsoft Windows family of products.

Outside Hyper-V, the procedure I'm describing is also known as "base image" on Linux and "template" on VMWARE.

Efficient:

  1. Have plenty of VMs with no impact to your (limited) storage.
  2. Save bandwidth! CentOS 6.2 Minimal is a very small download - 321 MB only!
  3. CentOS-minimal allows you to install into your new VMs only the software needed to accomplish your specific tasks.

Once you deploy new VMs based on your main image, you will simply launch the update process and/or customize your distribution to your liking, the point here is that you'll only download and install the programs needed for the specific tasks your VM needs to perform, while the main, "distribution" instance, will remain "frozen" in time (and powered OFF for good!).

This article is just a descriptive introduction and a placeholder index for the whole procedure, the next articles will present you a complete step-by-step tutorial and I will conclude with a final surprise. I will also update this index with direct links to the other articles (once they've been authored...that is!).

if you wish to know when my follow-up articles will be released, open a twitter account (it's that easy!) and follow me by clicking at the following address: https://twitter.com/amatesi

Alternatively you may receive updates about my articles through Facebook or Linked-in.

Articles Index.

  1. This Summary.
  2. Download the software needed.
  3. Create the "Father" VM (a New VM).
  4. Create the "Child" VM (a 2nd VM, that depends from the previous Father VM).
  5. Make the Child VM independent!

Bibliography:

  • Mastering Windows Server® 2008 R2 - Wiley Publishing - ISBN: 978-0-470-53286-7.

Posted in LINUX, Microsoft, System Administration | 6 Comments »