plz check the following URL.
https://help.ubuntu.com/12.04/serverguide/jeos-and-vmbuilder.html
[ install vmbuilder ]
KVM host
# uname -ri 3.2.0-29-generic x86_64 # tail -1 /etc/lsb-release DISTRIB_DESCRIPTION="Ubuntu 12.04.1 LTS" # libvirtd --version libvirtd (libvirt) 0.9.8 # kvm --version QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice Bellard # virt-install --version 0.600.1 |
I assume that you have already installed KVM and KVM-related packages.
on the KVM host , install vmbuilder.
# apt-get install python-vm-builder –y |
# apt-cache policy python-vm-builder python-vm-builder: Installed: 0.12.4+bzr477-0ubuntu1 Candidate: 0.12.4+bzr477-0ubuntu1 Version table: *** 0.12.4+bzr477-0ubuntu1 0 500 http://jp.archive.ubuntu.com/ubuntu/ precise/universe amd64 Packages 100 /var/lib/dpkg/status |
[ build JeOS with vmbuilder ]
make a working directory.
# mkdir VMbuilder_works # cd VMbuilder_works/ |
make a partition design file for VMs.
# cat partition.list root 10000 swap 2000 |
create a configuration file for a VM
# cat myappliance.cfg [DEFAULT] arch = amd64 ip = 192.168.10.111 net = 255.255.255.0 gw = 192.168.10.254 dns = 192.168.10.14 part = /root/VMbuilder_works/partition.list user = user pass = default tmpfs = - [ubuntu] mirror = http://jp.archive.ubuntu.com/ubuntu/ suite = precise flavour = virtual addpkg = openssh-server, acpid [kvm] libvirt = qemu:///system |
build a VM
# vmbuilder kvm ubuntu -c myappliance.cfg --hostname ubuntu12-04-vm1 --bridge br0 –m 512 2012-08-15 21:16:40,554 INFO : Calling hook: preflight_check 2012-08-15 21:16:40,558 INFO : Calling hook: set_defaults 2012-08-15 21:16:40,558 INFO : Calling hook: bootstrap 2012-08-15 21:20:46,349 INFO : Calling hook: configure_os 2012-08-15 21:21:27,720 INFO : Updating certificates in /etc/ssl/certs... 152 added, 0 removed; done. 2012-08-15 21:21:27,721 INFO : Running hooks in /etc/ca-certificates/update.d....done. 2012-08-15 21:21:29,653 INFO : invoke-rc.d: policy-rc.d denied execution of start. 2012-08-15 21:21:30,504 INFO : Creating SSH2 RSA key; this may take some time ... 2012-08-15 21:21:30,651 INFO : Creating SSH2 DSA key; this may take some time ... 2012-08-15 21:21:30,656 INFO : Creating SSH2 ECDSA key; this may take some time ... 2012-08-15 21:21:31,217 INFO : invoke-rc.d: policy-rc.d denied execution of stop. 2012-08-15 21:21:31,218 INFO : 2012-08-15 21:21:31,218 INFO : Warning: Fake initctl called, doing nothing 2012-08-15 21:21:31,219 INFO : 2012-08-15 21:21:31,219 INFO : Warning: Fake initctl called, doing nothing 2012-08-15 21:21:36,986 INFO : 2012-08-15 21:21:36,986 INFO : Current default time zone: 'Etc/UTC' 2012-08-15 21:21:36,989 INFO : Local time is now: Wed Aug 21 04:21:36 UTC 2012. 2012-08-15 21:21:36,989 INFO : Universal Time is now: Wed Aug 21 04:21:36 UTC 2012. 2012-08-15 21:21:36,989 INFO : 2012-08-15 21:21:53,755 INFO : gpg: key 437D05B5: "Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>" not changed 2012-08-15 21:21:53,757 INFO : gpg: key FBB75451: "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>" not changed 2012-08-15 21:21:53,758 INFO : gpg: Total number processed: 2 2012-08-15 21:21:53,758 INFO : gpg: unchanged: 2 2012-08-15 21:21:59,726 INFO : invoke-rc.d: policy-rc.d denied execution of stop. 2012-08-15 21:22:15,572 INFO : invoke-rc.d: policy-rc.d denied execution of stop. 2012-08-15 21:22:19,185 INFO : invoke-rc.d: policy-rc.d denied execution of start. 2012-08-15 21:22:20,819 INFO : invoke-rc.d: policy-rc.d denied execution of start. 2012-08-15 21:22:25,586 INFO : invoke-rc.d: policy-rc.d denied execution of restart. 2012-08-15 21:22:29,041 INFO : invoke-rc.d: policy-rc.d denied execution of start. 2012-08-15 21:22:37,384 INFO : Cleaning up 2012-08-15 21:22:37,385 INFO : Calling hook: preflight_check 2012-08-15 21:22:38,352 INFO : Calling hook: configure_networking 2012-08-15 21:22:38,370 INFO : Calling hook: configure_mounting 2012-08-15 21:22:38,397 INFO : Calling hook: mount_partitions 2012-08-15 21:22:38,398 INFO : Mounting target filesystems 2012-08-15 21:22:38,398 INFO : Creating disk image: "/tmp/tmpJ6O7nM" of size: 5120MB 2012-08-15 21:22:38,441 INFO : Adding partition table to disk image: /tmp/tmpJ6O7nM 2012-08-15 21:22:38,961 INFO : Adding type 4 partition to disk image: /tmp/tmpJ6O7nM 2012-08-15 21:22:38,961 INFO : Partition at beginning of disk - reserving first cylinder 2012-08-15 21:22:39,433 INFO : Adding type 3 partition to disk image: /tmp/tmpJ6O7nM 2012-08-15 21:22:39,437 INFO : [0] ../../libparted/filesys.c:148 (ped_file_system_type_get): File system alias linux-swap(new) is deprecated 2012-08-15 21:22:39,900 INFO : Creating loop devices corresponding to the created partitions 2012-08-15 21:22:39,908 INFO : Creating file systems 2012-08-15 21:22:39,911 INFO : mke2fs 1.42 (29-Nov-2011) 2012-08-15 21:22:41,544 INFO : mkswap: /dev/mapper/loop0p2: warning: don't erase bootbits sectors 2012-08-15 21:22:41,545 INFO : on whole disk. Use -f to force. 2012-08-15 21:22:44,337 INFO : Calling hook: install_bootloader 2012-08-15 21:23:14,357 INFO : Removing update-grub hooks from /etc/kernel-img.conf in favour of 2012-08-15 21:23:14,358 INFO : /etc/kernel/ hooks. 2012-08-15 21:23:14,507 INFO : Searching for GRUB installation directory ... found: /boot/grub 2012-08-15 21:23:14,562 INFO : Searching for default file ... Generating /boot/grub/default file and setting the default boot entry to 0 2012-08-15 21:23:14,563 INFO : Searching for GRUB installation directory ... found: /boot/grub 2012-08-15 21:23:14,568 INFO : Testing for an existing GRUB menu.lst file ... 2012-08-15 21:23:14,568 INFO : 2012-08-15 21:23:14,568 INFO : Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub: line 1094: read: read error: 0: Bad file descriptor 2012-08-15 21:23:18,577 INFO : Searching for GRUB installation directory ... found: /boot/grub 2012-08-15 21:23:18,630 INFO : Searching for default file ... found: /boot/grub/default 2012-08-15 21:23:18,634 INFO : Testing for an existing GRUB menu.lst file ... 2012-08-15 21:23:18,634 INFO : 2012-08-15 21:23:18,634 INFO : Could not find /boot/grub/menu.lst file. 2012-08-15 21:23:18,635 INFO : Generating /boot/grub/menu.lst 2012-08-15 21:23:18,700 INFO : Searching for splash image ... none found, skipping ... 2012-08-15 21:23:18,854 INFO : grep: /boot/config*: No such file or directory 2012-08-15 21:23:18,937 INFO : Updating /boot/grub/menu.lst ... done 2012-08-15 21:23:18,937 INFO : 2012-08-15 21:23:19,302 INFO : Searching for GRUB installation directory ... found: /boot/grub 2012-08-15 21:23:19,355 INFO : Searching for default file ... found: /boot/grub/default 2012-08-15 21:23:19,360 INFO : Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst 2012-08-15 21:23:19,470 INFO : Searching for splash image ... none found, skipping ... 2012-08-15 21:23:19,503 INFO : grep: /boot/config*: No such file or directory 2012-08-15 21:23:19,591 INFO : Updating /boot/grub/menu.lst ... done 2012-08-15 21:23:19,592 INFO : 2012-08-15 21:23:19,748 INFO : Searching for GRUB installation directory ... found: /boot/grub 2012-08-15 21:23:19,756 INFO : Calling hook: install_kernel 2012-08-15 21:23:35,687 INFO : Done. 2012-08-15 21:23:47,637 INFO : Running depmod. 2012-08-15 21:23:47,733 INFO : update-initramfs: deferring update (hook will be called later) 2012-08-15 21:23:47,741 INFO : Examining /etc/kernel/postinst.d. 2012-08-15 21:23:47,742 INFO : run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.2.0-29-virtual /boot/vmlinuz-3.2.0-29-virtual 2012-08-15 21:23:47,746 INFO : update-initramfs: Generating /boot/initrd.img-3.2.0-29-virtual 2012-08-15 21:23:50,134 INFO : run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.2.0-29-virtual /boot/vmlinuz-3.2.0-29-virtual 2012-08-15 21:23:50,284 INFO : Searching for GRUB installation directory ... found: /boot/grub 2012-08-15 21:23:50,338 INFO : Searching for default file ... found: /boot/grub/default 2012-08-15 21:23:50,342 INFO : Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst 2012-08-15 21:23:50,453 INFO : Searching for splash image ... none found, skipping ... 2012-08-15 21:23:50,526 INFO : Found kernel: /boot/vmlinuz-3.2.0-29-virtual 2012-08-15 21:23:50,634 INFO : Replacing config file /run/grub/menu.lst with new version 2012-08-15 21:23:50,659 INFO : Updating /boot/grub/menu.lst ... done 2012-08-15 21:23:50,659 INFO : 2012-08-15 21:23:55,082 INFO : Calling hook: post_install 2012-08-15 21:23:55,083 INFO : Calling hook: unmount_partitions 2012-08-15 21:23:55,083 INFO : Unmounting target filesystem 2012-08-15 21:23:58,998 INFO : Calling hook: convert 2012-08-15 21:23:58,999 INFO : Converting /tmp/tmpJ6O7nM to qcow2, format ubuntu-kvm/tmpJ6O7nM.qcow2 2012-08-15 21:24:04,118 INFO : Calling hook: fix_ownership 2012-08-15 21:24:04,157 INFO : Calling hook: deploy |
In my environment , the VM image was created under “/root/VMbuilder_works/ubuntu-kvm” directory , named tmpJ6O7nM.qcow2.
# virsh list --all | grep ubuntu12 - ubuntu12-04-vm1 shut off |
# virsh dumpxml ubuntu12-04-vm1 <domain type='kvm'> <name>ubuntu12-04-vm1</name> <uuid>f439b59e-2c1d-02b2-0cb9-fa71d5b189ed</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64' machine='pc-1.0'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/root/VMbuilder_works/ubuntu-kvm/tmpJ6O7nM.qcow2'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk> <controller type='ide' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'> <mac address='xx:xx:xx:xx:xx:xx'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'> <listen type='address' address='127.0.0.1'/> </graphics> <video> <model type='cirrus' vram='9216' heads='1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </memballoon> </devices> </domain> |
virsh # start ubuntu12-04-vm1 Domain ubuntu12-04-vm1 started |
access to the VM via “virsh console”
oh ,,, the VM has no serial port..
virsh # console ubuntu12-04-vm1 Connected to domain ubuntu12-04-vm1 Escape character is ^] error: internal error cannot find character device (null) |
access to the VM over SSH
# ssh 192.168.10.111 -l user user@192.168.10.111's password: Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-29-virtual x86_64) user@ubuntu12-04-vm1:~$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04.1 LTS" user@ubuntu12-04-vm1:~$ uname -ri 3.2.0-29-virtual x86_64 |
okay , I could build a VM with vmbuilder.
[ How to access to the VM via virsh console ]
shutdown the VM
on the KVM host.
# virsh shutdown ubuntu12-04-vm1 |
edit VM’s xml file
on the KVM host.
# virsh edit ubuntu12-04-vm1 |
add a serial port like this
<serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target type='serial' port='0'/> </console> |
edit config files within the VM using guestfish
on the KVM host , install guestfish
# apt-get install guestfish |
edit /boot/grub/menu.lst
on the KVM host
# guestfish --rw -d ubuntu12-04-vm1 -i edit /boot/grub/menu.lst |
add red lines in /boot/grub/menu.lst
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 terminal --timeout=10 serial console ## ## End Default Options ## title Ubuntu 12.04.1 LTS, kernel 3.2.0-29-virtual uuid dd3e1234-f569-4a8e-9bff-5f2fd4bad248 kernel /boot/vmlinuz-3.2.0-29-virtual root=UUID=dd3e1234-f569-4a8e-9bff-5f2fd4bad248 ro quiet splash initrd /boot/initrd.img-3.2.0-29-virtual console=tty0 console=ttyS0,115200n8 |
create a “ttyS0.conf” file and write console settings.
on the KVM host
# guestfish --rw -d ubuntu12-04-vm1 -i write /etc/init/ttyS0.conf " > start on stopped rc RUNLEVEL=[2345] > stop on runlevel [!2345] > respawn > exec /sbin/getty -L 115200 ttyS0 vt102 > " # |
check /etc/init/ttyS0.conf file.
on the KVM host
# guestfish --ro -d ubuntu12-04-vm1 -i cat /etc/init/ttyS0.conf start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 115200 ttyS0 vt102 # |
start the VM and connect to that VM over virsh console.
# virsh start ubuntu12-04-vm1 Domain ubuntu12-04-vm1 started # virsh console ubuntu12-04-vm1 Connected to domain ubuntu12-04-vm1 Escape character is ^] Press any key to continue. Boot from (hd0,0) ext4 dd3e1234-f569-4a8e-9bff-5f2fd4bad248 Starting up ... Ubuntu 12.04.1 LTS ubuntu12-04-vm1 ttyS0 ubuntu12-04-vm1 login: user Password: Last login: Wed Aug 15 04:38:03 UTC 2012 from 192.168.10.14 on pts/0 Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-29-virtual x86_64) |
okay , I could access to the VM via “virsh console”
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.