Difference between revisions of "Creating a Virtual Machine from an Existing one Manually"

From Supercomputación y Cálculo Científico UIS
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Back to: [[Xen on Debian]]
+
__NOTOC__
  
Assuming an LVM setup, this is the command for allocating the required disk space (in this example 20Gb) for the main disk of the virtual machine. Another ammount is required for the swap space.
+
Back to [[Xen on Debian]]
  
{{Command|<nowiki> lvcreate -L20G -n machine-name volumegroup-name  
+
Assuming an LVM setup, this is the command for allocating the required disk space (in this example 20Gb) for the main disk of the virtual machine. Another amount is required for the swap space.
lvcreate -L20G -n machine-name-swap volumegroup-name </nowiki>}}
+
{{Command|<nowiki>lvcreate -L20G -n machine-name volumegroup-name
 
+
lvcreate -L2G -n machine-name-swap volumegroup-name</nowiki>}}
where machine-name and volumegroup-name are specific to the intended configuration.
+
where machine-name and volumegroup-name are specific to the specific setup.
  
 
The virtual units are formatted
 
The virtual units are formatted
 +
{{Command|<nowiki>mkfs.ext4 /dev/volumegroup-name/machine-name
 +
mkswap /dev/volumegroup-name/machine-name-swap</nowiki>}}
 +
At this point the base filesystem should be copied. 
 +
First mount the partition:
 +
{{Command|<nowiki>mount /dev/volumegroup-name/machine-name /mnt/some-directory</nowiki>}}
 +
You must copy the existing machine filesystem except for the directories /proc and /dev.  Sometimes you must skip /home or other diretories. First create a file with the list of the directories to skip:
 +
{{File|./ex|<pre><nowiki>
 +
/proc
 +
/sys
 +
</nowiki></pre>}}
 +
Then use rsync to copy the whole filesystem. Note the --exclude-from clausule, and its parameter which is the last file.
 +
{{command|<nowiki>rsync -av --exclude-from ex 192.168.66.120:/ /mnt/some-directory/</nowiki>}}
 +
After the file copy, it is necessary to edit some configuration files (All of them in the etc directory on the mounted partition, for example /mnt/some-directory): securetty, inittab and fstab.  First edit securetty
 +
{{Command|<nowiki>vi /mnt/some-directory/securetty</nowiki>}}
 +
A line containing hvc0 should be in the file.
 +
{{File|/mnt/some-directory/etc/securetty|<pre><nowiki>
 +
#...
  
mkfs.ext4 /dev/VG1/machine-name
+
# IBM iSeries/pSeries virtual console
mkswap /dev/VG1/machine-name-swap
 
 
 
After the file copy, it is necessary to edit some configuration files: securetty, inittab and fstab
 
 
 
 
 
vi securetty
 
 
hvc0
 
hvc0
 
+
hvc1
 
+
#...
vi inittab
+
</nowiki></pre>}}
 +
Then search inittab for a line with tty like the one below:
 +
{{File|/mnt/some-directory/etc/inittab|<pre><nowiki>
 +
#c1:12345:respawn:/sbin/agetty 38400 tty1 linux
 +
</nowiki></pre>}}
 +
and edit it to:
 +
{{File|/mnt/some-directory/etc/inittab|<pre><nowiki>
 
c1:12345:respawn:/sbin/agetty 38400 hvc0 linux
 
c1:12345:respawn:/sbin/agetty 38400 hvc0 linux
#c1:12345:respawn:/sbin/agetty 38400 tty1 linux
+
</nowiki></pre>}}
 
+
Next, edit fstab to reflect the virtual drive configuration
 
+
{{File|/mnt/some-directory/etc/fstab|<pre><nowiki>
vi fstab
 
 
/dev/xvda1              /                      ext3    defaults        1 1
 
/dev/xvda1              /                      ext3    defaults        1 1
 
/dev/xvda4              swap                    swap    defaults        0 0
 
/dev/xvda4              swap                    swap    defaults        0 0
Line 32: Line 48:
 
sysfs                  /sys                    sysfs  defaults        0 0
 
sysfs                  /sys                    sysfs  defaults        0 0
 
proc                    /proc                  proc    defaults        0 0
 
proc                    /proc                  proc    defaults        0 0
 
+
</nowiki></pre>}}
 
+
It is important that in the moment the files were copied, the directories /proc and /sys had been left out.  Now it is important to create those directories. With the partition mounted create the directories:
 
+
{{Command|<nowiki>cd /mnt/some-directory
 
+
mkdir proc sys</nowiki>}}
cd /dev
+
And then create the devices for the virtual machines
 +
{{Command|<nowiki>cd /mnt/some-directory/dev
 
mknod xvc0 c 204 191
 
mknod xvc0 c 204 191
 
mknod hvc0 c 229 0
 
mknod hvc0 c 229 0
 
mknod xvda b 202 0
 
mknod xvda b 202 0
mknod xvda1 b 202 1
+
mknod xvda1 b 202 1</nowiki>}}

Latest revision as of 16:17, 21 June 2016


Back to Xen on Debian

Assuming an LVM setup, this is the command for allocating the required disk space (in this example 20Gb) for the main disk of the virtual machine. Another amount is required for the swap space.

lvcreate -L20G -n machine-name volumegroup-name lvcreate -L2G -n machine-name-swap volumegroup-name

where machine-name and volumegroup-name are specific to the specific setup.

The virtual units are formatted

mkfs.ext4 /dev/volumegroup-name/machine-name mkswap /dev/volumegroup-name/machine-name-swap

At this point the base filesystem should be copied. First mount the partition:

mount /dev/volumegroup-name/machine-name /mnt/some-directory

You must copy the existing machine filesystem except for the directories /proc and /dev. Sometimes you must skip /home or other diretories. First create a file with the list of the directories to skip:

File: ./ex
/proc
/sys

Then use rsync to copy the whole filesystem. Note the --exclude-from clausule, and its parameter which is the last file.

rsync -av --exclude-from ex 192.168.66.120:/ /mnt/some-directory/

After the file copy, it is necessary to edit some configuration files (All of them in the etc directory on the mounted partition, for example /mnt/some-directory): securetty, inittab and fstab. First edit securetty

vi /mnt/some-directory/securetty

A line containing hvc0 should be in the file.

File: /mnt/some-directory/etc/securetty
#...

# IBM iSeries/pSeries virtual console
hvc0
hvc1
#...

Then search inittab for a line with tty like the one below:

File: /mnt/some-directory/etc/inittab
#c1:12345:respawn:/sbin/agetty 38400 tty1 linux

and edit it to:

File: /mnt/some-directory/etc/inittab
c1:12345:respawn:/sbin/agetty 38400 hvc0 linux

Next, edit fstab to reflect the virtual drive configuration

File: /mnt/some-directory/etc/fstab
/dev/xvda1               /                       ext3    defaults        1 1
/dev/xvda4               swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

It is important that in the moment the files were copied, the directories /proc and /sys had been left out. Now it is important to create those directories. With the partition mounted create the directories:

cd /mnt/some-directory mkdir proc sys

And then create the devices for the virtual machines

cd /mnt/some-directory/dev mknod xvc0 c 204 191 mknod hvc0 c 229 0 mknod xvda b 202 0 mknod xvda1 b 202 1