Saturday, November 4, 2017

install virtual machine guest OSs, using oz and libvirt

1- install packages
$ sudo apt-get install oz libvirt-bin libvirt-daemon virt-view

1- create template and preseed file

$ mkdir ~/test/oz -p
$ cd ~/test/oz 

then create file oztemplate.tdl  with content below

<template>
  <name>oztemplate</name>
  <description>oz template</description>
  <disk>
    <size>5</size>
  </disk>
  <os>
   <name>Ubuntu</name>
   <version>12.04</version>
   <arch>x86_64</arch>
   <install type='url'>
     <url>http://archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot</url>
   </install>
   <rootpw>PassP@ss4w0rd</rootpw>
  </os>
  <commands>
    <command name='hostname'>
      echo 'oztemplate' > /etc/hostname
    </command>
  </commands>
</template>



file oz.preseed with content below




d-i debian-installer/locale string en_US.UTF-8
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us

d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/wireless_wep string

d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern

d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select home
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password %ROOTPW%
d-i passwd/root-password-again password %ROOTPW%

tasksel tasksel/first multiselect standard
d-i pkgsel/include/install-recommends boolean true
d-i pkgsel/include string openssh-server python-software-properties wget whois curl acpid

d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true

d-i apt-setup/security_host string
base-config apt-setup/security-updates boolean false

ubiquity ubiquity/summary note
ubiquity ubiquity/reboot boolean true

d-i finish-install/reboot_in_progress note

d-i mirror/country string manual
d-i mirror/http/hostname string archive.ubuntu.com
d-i mirror/http/directory string /ubuntu



3- now we can start the oz-install

$ virsh net-start default 
$ sudo oz-install -b virtio -n virtio -p -u  -x ~/test/oz/oztemplate.xml -a ~/test/oz/oz.preseed  ~/test/oz/oztemplate.tdl

- after a  while  the os will be installed, if you want to see the progress
$ virt-view oztemplate.tdl

4- after completing the os installation, we can run it from virsh
$ virsh define   oztemplate.xml 
$ virsh start oztemplate

5- to list all the domain
$ virsh list --all

6- to shutdown
$ virsh shutdown  oztemplate

or force it
$ virsh destroy oztemplate


7- if you start to modify it to boot from iso
$ virsh dump oztemplate > oztemplate.xml

then add the following to it
<disk type='file' device='cdrom'>
  <source file='/home/tun/iso/ubuntu-14.04-desktop-amd64.iso'/>
  <target dev='hda'  bus='ide'/>
  <readonly/>
</disk>


  <os>
    <type arch='x86_64' machine='pc-i440fx-yakkety'>hvm</type>
    <boot dev='cdrom'/>
  </os>


then run virsh define again
$ virsh define oztemplate.xml


now we can virsh start again and it will boot from iso

2 comments:

  1. How do you guys even come up with these.... It's simply spiffing!! I mean, I know what I have to do now but I don't know WHY I have to do it!! Even after reading all of this... Is this another one of the coder thingys? Can't us normal people do it too?

    ReplyDelete
  2. Thanks for sharing, nice post!

    Anthaison chuyên cung cấp máy đưa võng chất lượng với blog http://mayduavongtudongts.simplesite.com/ hay blog máy đưa võng uy tín http://mayduavongts.moonfruit.com/ hay blog máy đưa võng cho bé với http://mayduavongts.zohosites.com/ hay blog mdv http://mayduavongts.portfoliobox.net/ để tìm được máy đưa võng tốt cho bé.

    ReplyDelete