Tuesday, January 15, 2019

Flexible server Part VI: cloning an image


In Part VI we clone our first guest VM from the image we have built over the previous Parts presented in this series of posts. Once this process is complete, you can clone as many VMs as you need.

We start by creating a new volume on the roots-vg volume group.
?

  
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
gsw@goat-lin:~$ sudo lvcreate -L 4GB -n goat-lin002.webber.net-disk roots-vg
  Logical volume "goat-lin002.webber.net-disk" created.
gsw@goat-lin:~$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                kIiicS-8PYH-Kjer-4veY-ae7S-AGq2-tm5Tzz
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2018-09-22 17:54:07 +1000
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  --- Logical volume ---
  LV Path                /dev/roots-vg/goat-lin001.webber.net-disk
  LV Name                goat-lin001.webber.net-disk
  VG Name                roots-vg
  LV UUID                1o1aVC-Ua3B-gnHE-M2r0-RxXN-iQjY-L2AwMK
  LV Write Access        read/write
  LV Creation host, time goat-lin, 2018-09-25 11:04:28 +1000
  LV Status              available
  # open                 0
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5
# etc…

  
gsw@goat-lin:~$ sudo lvcreate -L 4GB -n goat-lin002.webber.net-disk roots-vg
  Logical volume "goat-lin002.webber.net-disk" created.

gsw@goat-lin:~$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                kIiicS-8PYH-Kjer-4veY-ae7S-AGq2-tm5Tzz
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2018-09-22 17:54:07 +1000
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/roots-vg/goat-lin001.webber.net-disk
  LV Name                goat-lin001.webber.net-disk
  VG Name                roots-vg
  LV UUID                1o1aVC-Ua3B-gnHE-M2r0-RxXN-iQjY-L2AwMK
  LV Write Access        read/write
  LV Creation host, time goat-lin, 2018-09-25 11:04:28 +1000
  LV Status              available
  # open                 0
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

# etc…
?
  
1
gunzip -c /mnt/scratch/goat-lin/base_vm_guest_install.201809252308.img.gz | sudo dd of=/dev/roots-vg/goat-lin002.webber.net-disk
  
gunzip -c /mnt/scratch/goat-lin/base_vm_guest_install.201809252308.img.gz | sudo dd of=/dev/roots-vg/goat-lin002.webber.net-disk
We now need to configure the image so that xen can start it up. We can use an existing configuration file as a template and update some of the key sections.

?

  
1
gsw@goat-lin:/etc/xen$ sudo cp goat-lin002.webber.net.cfg goat-lin004.webber.net.cfg

  
gsw@goat-lin:/etc/xen$ sudo cp goat-lin002.webber.net.cfg goat-lin004.webber.net.cfg

The xen config files support a great many parameters and you can make a lot of hardware available to the guest if this is required for your workloads, including PCI pass-through for GPUs. For this example, concentrate on the basic items:

  • memory: a basic headless server can probably get away with 2GB as a starting point
  • disk: configure the disk from the volume creation step above
  • name: use the FQDN you have allocated for your network. Your DNS and/or DHCP servers will need to be configured appropriately.
  • dhcp: I personally prefer dhcp for throw-away environments but you could use static IPs
  • vif: Make sure this MAC is unique on your LAN or DHCP will not work as expected. xen tools will create random MACs for you but when you are copying config files this is something you will need to manage manually.

?

  
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# Configuration file for the Xen instance goat-lin002.webber.net, created
# by xen-tools 4.7 on Tue Sep 25 19:44:41 2018.
#
#
#  Kernel + memory size
#
bootloader = '/usr/lib/xen-4.9/bin/pygrub'
vcpus       = '2'
memory      = '2048'
#
#  Disk device(s).
#
root        = '/dev/xvda1 ro'
disk        = [
                  'phy:/dev/roots-vg/goat-lin002.webber.net-disk,xvda1,w',
              ]
#
#  Physical volumes
#
#
#  Hostname
#
name        = 'goat-lin002.webber.net'
#
#  Networking
#
dhcp        = 'dhcp'
vif         = [ 'mac=00:16:3E:AA:7D:4D' ]
#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

  
#
# Configuration file for the Xen instance goat-lin002.webber.net, created
# by xen-tools 4.7 on Tue Sep 25 19:44:41 2018.
#

#
#  Kernel + memory size
#


bootloader = '/usr/lib/xen-4.9/bin/pygrub'

vcpus       = '2'
memory      = '2048'


#
#  Disk device(s).
#
root        = '/dev/xvda1 ro'
disk        = [
                  'phy:/dev/roots-vg/goat-lin002.webber.net-disk,xvda1,w',
              ]


#
#  Physical volumes
#


#
#  Hostname
#
name        = 'goat-lin002.webber.net'

#
#  Networking
#
dhcp        = 'dhcp'
vif         = [ 'mac=00:16:3E:AA:7D:4D' ]

#
#  Behaviour
#
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

There are a few other modifications you may like to make on the cloned image that will help it to come up cleanly with its new identity. If you were doing this often it may make sense to script it. In the example above, mount the goat-lin002.webber.net-disk volume on the hypervisor at /mnt/img/ and find /mnt/img/etc/hosts and /mnt/img/etc/hostname and replace the hostname in the cloned image (ie goat-lin001) with the name you have configured for the clone (ie goat-lin002). You may find other configuration that is configured with the host-specific details of the master image and you can add these to your post-clone configuration scripts.

Next: Flexible server Part VII: Building a Kubernetes master node

No comments:

Post a Comment