Annotation of wikisrc/tutorials/how_to_set_up_a_guest_os_using_xen3.mdwn, revision 1.1

1.1     ! mspo        1: **Contents**
        !             2: 
        !             3: [[!toc levels=3]]
        !             4: 
        !             5: #  Requirements
        !             6: 
        !             7: Xen3 is supported from NetBSD-4.0 onward. If you plan on using NetBSD-CURRENT,
        !             8: please read the article [[How to build NetBSD-current]] to do so. Guest
        !             9: operating systems can run from their own partitions, or from image files in
        !            10: the main (DOM0) install.
        !            11: 
        !            12: This tutorial describes how to:
        !            13: 
        !            14:   * Install and configure NetBSD as a DOM0 
        !            15:   * Install and run a NetBSD as a DOMU 
        !            16:   * Install and run a Windows XP system as as DOMU 
        !            17:   * Install and run a Debian system as a DOMU 
        !            18: 
        !            19: #  Installing Xen tools and kernels
        !            20: 
        !            21: ##  Xen tools
        !            22: 
        !            23: To run and administer xen domains, we need the xentools3 or xentools33
        !            24: packages which are available in pkgsrc.
        !            25: 
        !            26: Xen 3.1 packages are under [sysutils/xentools3](http://pkgsrc.se/sysutils/xentools3) for traditional xentools,
        !            27: and [sysutils/xentools3-hvm](http://pkgsrc.se/sysutils/xentools3-hvm) for the additional **HVM** support to run un-
        !            28: modified OSes such as Windows XP.
        !            29: 
        !            30: Xen 3.3 packages are under [sysutils/xentools33](http://pkgsrc.se/sysutils/xentools33). Unlike Xen 3.1, no extra
        !            31: package is required for **HVM** support. Note, it is not possible to install
        !            32: Xen 3.1 and Xen 3.3 packages at the same time. They conflict with each other.
        !            33: 
        !            34: **HVM** stands for **Hardware Virtualization Managed**. The benefit of hardware virtualization is that you can run OSes that don't know they are being virutalized like Windows XP, for example. However, you must have a CPU which supports this. Intel CPUs must have the 'VT' instruction. AMD CPUs will have the 'SVM' instruction. You can find out if your CPU supports HVM by taking a look at this page: 
        !            35: 
        !            36: <http://wiki.xensource.com/xenwiki/HVM_Compatible_Processors>
        !            37: 
        !            38: In NetBSD 5.0 there's a new cpuctl command. This is an example output of an
        !            39: AMD CPU:
        !            40: 
        !            41:     
        !            42:      # cpuctl identify 0
        !            43:      cpu0: AMD Unknown K8 (Athlon) (686-class), 2210.22 MHz, id 0x60f82
        !            44:      cpu0: features 0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR>
        !            45:      cpu0: features 0x178bfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX>
        !            46:      cpu0: features 0x178bfbff<FXSR,SSE,SSE2,HTT>
        !            47:      cpu0: features2 0x2001<SSE3,CX16>
        !            48:      cpu0: features3 0xebd3fbff<SCALL/RET,NOX,MXX,FFXSR,RDTSCP,LONG,3DNOW2,3DNOW>
        !            49:      cpu0: features4 0x11f<LAHF,CMPLEGACY,SVM,EAPIC,ALTMOVCR0,3DNOWPREFETCH>
        !            50:      cpu0: "AMD Turion(tm) 64 X2 Mobile Technology TL-64"
        !            51:      cpu0: I-cache 64KB 64B/line 2-way, D-cache 64KB 64B/line 2-waycpu0: L2 cache 1MB 64B/line 16-way
        !            52:      cpu0: ITLB 32 4KB entries fully associative, 8 4MB entries fully associative
        !            53:      cpu0: DTLB 32 4KB entries fully associative, 8 4MB entries fully associativecpu0: Initial APIC ID 0
        !            54:      cpu0: AMD Power Management features: 0x7f<TS,FID,VID,TTP,HTC,STC,100>
        !            55:      cpu0: family 0f model 08 extfamily 00 extmodel 06
        !            56:     
        !            57: 
        !            58: Note the **SVM** feature flag in the **features4** line indicating that
        !            59: **HVM** support is present on this CPU. However, this feature may be disabled
        !            60: in the BIOS. In this case since NetBSD 5.0 there will show up this dmesg line
        !            61: on AMD CPUs only:
        !            62: 
        !            63:     
        !            64:      cpu0: SVM disabled by the BIOS
        !            65:     
        !            66: 
        !            67:   
        !            68: Xen 3.1 (the xentools3-hvm package will automatically bring in the base
        !            69: xentools3):
        !            70: 
        !            71:     
        !            72:     # cd /usr/pkgsrc/sysutils/xentools3-hvm
        !            73:     # make install
        !            74:     
        !            75: 
        !            76: Xen 3.3:
        !            77: 
        !            78:     
        !            79:     # cd /usr/pkgsrc/sysutils/xentools33
        !            80:     # make install
        !            81:     
        !            82: 
        !            83: ##  Xen kernel
        !            84: 
        !            85: Next, we will get the xen hypervisor kernel itself. For NetBSD 4.x and 5.x the
        !            86: i386 port does not support 'PAE' kernels and must run the Xen 3.1 package.
        !            87: This restriction has been removed in -current and is not relevant for the
        !            88: amd64 port.
        !            89: 
        !            90: For Xen 3.1, in pkgsrc this is [sysutils/xenkernel3](http://pkgsrc.se/sysutils/xenkernel3), for Xen 3.3, this is
        !            91: [sysutils/xenkernel33](http://pkgsrc.se/sysutils/xenkernel33):
        !            92: 
        !            93:     
        !            94:     # cd /usr/pkgsrc/sysutils/xenkernel3
        !            95:     # make install
        !            96:     
        !            97: 
        !            98: And copy it into / directory, like this:
        !            99: 
        !           100:     
        !           101:     # cp /usr/pkg/xen3-kernel/xen.gz /
        !           102:     
        !           103: 
        !           104: Finally, decompress it so that all versions of GRUB can read it:
        !           105: 
        !           106:     
        !           107:     # gunzip /xen.gz
        !           108:     
        !           109: 
        !           110: ##  Xen DOM0 kernel
        !           111: 
        !           112: Lastly, we need a XEN-enabled kernel for our DOM0 domain. There are two
        !           113: possibilities: downloading the binary version, or building it from source.
        !           114: 
        !           115: ##  Downloading the binary version
        !           116: 
        !           117: From NetBSD-4.0 onward, NetBSD supports Xen, and provides some XEN-enabled
        !           118: kernel directly from [[1]][36], in each `binary/kernel` directory associated
        !           119: with a particular release.
        !           120: 
        !           121: For example, with NetBSD-4.0, You can grab one from
        !           122: (<ftp.NetBSD.org/pub/NetBSD/NetBSD-4.0/i386/binary/kernel>/netbsd-XEN3_DOM0.gz):
        !           123: 
        !           124:     
        !           125:     # ftp -a ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-4.0/i386/binary/kernel/netbsd-XEN3_DOM0.gz
        !           126:     
        !           127: 
        !           128: The `netbsd-XEN3_DOM0.gz` file contains a gzipped version of the kernel. Just
        !           129: copy and move it into the root directory like this:
        !           130: 
        !           131:     
        !           132:     # cp netbsd-XEN3_DOM0.gz /
        !           133:     
        !           134: 
        !           135: Now decompress it to avoid any issues GRUB or Xen might have with gzipped
        !           136: kernels
        !           137: 
        !           138:     
        !           139:     # gunzip /netbsd-XEN3_DOM0.gz
        !           140:     
        !           141: 
        !           142: ##  Building it from source
        !           143: 
        !           144: Building a kernel from source is out of the scope of this section. Please
        !           145: consult [How to build a kernel](http://www.netbsd.org/docs/kernel/#how_to_build_a_kernel) from NetBSD's FAQ for more details.
        !           146: 
        !           147: Once building is done, you can find them in
        !           148: `/usr/src/obj/_releasedir_/i386/binary/kernel/`. Identically to binary
        !           149: version, copy or move netbsd-XEN3_DOM0 in the root directory `/`.
        !           150: 
        !           151: #  Selecting a bootloader
        !           152: 
        !           153: In NetBSD 5.0 the native boot loader, /boot, can load Xen directly. For
        !           154: earlier versions of NetBSD you will need to use Grub. The NetBSD 5.0
        !           155: bootloader can be easily dropped into a NetBSD 4.x system by coping them into
        !           156: /boot and running installboot(8) properly.
        !           157: 
        !           158: ##  Updating /boot
        !           159: 
        !           160: For full details refer to installboot(8), but for a standard configuration
        !           161: with VGA console and an IDE or SATA drive with an FFSv1 root file system use
        !           162: the following:
        !           163: 
        !           164:     
        !           165:     # cp /usr/mdec/boot /boot
        !           166:     # installboot -v -o timeout=5 /dev/rwd0a /usr/mdec/bootxx_ffsv1
        !           167:     
        !           168: 
        !           169: ##  Updating /boot.cfg
        !           170: 
        !           171: NetBSD 5.0 or later will already have a /boot.cfg file with a basic
        !           172: configuration. Enabling Xen support only requires one additional line in this
        !           173: case. If you're upgrading from an earlier version or do not have an existing
        !           174: /boot.cfg use the following example:
        !           175: 
        !           176:     
        !           177:     
        !           178:     banner=Welcome to NetBSD
        !           179:     banner==================
        !           180:     banner=
        !           181:     banner=Please choose an option from the following menu:
        !           182:     menu=Boot normally:boot netbsd
        !           183:     menu=Boot single-user:boot netbsd -s
        !           184:     menu=Boot backup kernel:boot onetbsd
        !           185:     menu=Drop to boot prompt:prompt
        !           186:     menu=Boot Xen with 256MB for dom0:load /netbsd-XEN3_DOM0 console=pc;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
        !           187:     menu=Boot Xen with 256MB for dom0 (serial):load /netbsd-XEN3_DOM0 console=com0;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M console=com1 com1=115200,8n1
        !           188:     menu=Boot Xen with dom0 in single-user mode:load /netbsd-XEN3_DOM0 -s;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
        !           189:     timeout=5
        !           190:     default=1
        !           191:     
        !           192: 
        !           193: Make sure you update the "load /netbsd-XEN3_DOM0" and the "dom0_mem=256M"
        !           194: arguments to match your setup. On next boot select the 'Boot Xen with 256MB
        !           195: for dom0' option and make sure you see Xen kernel messages and the normal
        !           196: NetBSD kernel messages. Once you're satisfied it is working you can change the
        !           197: "default=1" line to "default=5" to automatically boot Xen on reboot.
        !           198: 
        !           199: #  Setting up Grub
        !           200: 
        !           201: Before installing and configuring XEN3, we need to install grub, the
        !           202: bootloader required to boot our XEN-enabled system.
        !           203: 
        !           204: To install it, use its package provided in pkgsrc ([sysutils/grub](http://pkgsrc.se/sysutils/grub)):
        !           205: 
        !           206:     
        !           207:     # cd /usr/pkgsrc/sysutils/grub
        !           208:     # make install
        !           209:     
        !           210: 
        !           211: Building grub may take a while.
        !           212: 
        !           213: When installation is finished, you can proceed to grub's configuration in the
        !           214: _/grub_ directory.
        !           215: 
        !           216: ##  GRUB configuration
        !           217: 
        !           218: First, create `/grub` (if it is not present), and copy paste the menu.lst file
        !           219: below used by grub to read its configuration:
        !           220: 
        !           221:     
        !           222:     # mkdir /grub
        !           223:     # vi /grub/menu.lst
        !           224:     
        !           225: 
        !           226: This typical _/grub/menu.lst_ file should have following content:
        !           227: 
        !           228:     
        !           229:     
        !           230:     #Grub config file for NetBSD/xen. Copy as /grub/menu.lst and run
        !           231:     # grub-install /dev/rwd0d (assuming your boot device is wd0).
        !           232:     #
        !           233:     # The default entry to load will be the first one
        !           234:     default=0
        !           235:     
        !           236:     # boot after 10s the default entry if the user didn't hit keyboard
        !           237:     timeout=10
        !           238:     
        !           239:     # Same as above, but using VGA console
        !           240:     # We can use console=tty0 (Linux syntax) or console=pc (NetBSD syntax)
        !           241:     title Xen 3.0 / NetBSD (hda0, vga)
        !           242:       root(hd0,0)
        !           243:       kernel (hd0,a)/xen dom0_mem=514624
        !           244:       module (hd0,a)/netbsd-XEN3_DOM0 bootdev=/dev/wd0a ro console=tty0 
        !           245:     
        !           246:     #Load a regular NetBSD/i386 kernel. Can be useful if you end up with a
        !           247:     #nonworking /xen.gz
        !           248:     title NetBSD 4.0
        !           249:       root (hd0,a)
        !           250:       kernel --type=netbsd /netbsd
        !           251:     
        !           252:     #Load the NetBSD bootloader, letting it load the NetBSD/i386 kernel.
        !           253:     #May be better than the above, as grub can't pass all required infos
        !           254:     #to the NetBSD/i386 kernel (e.g. console, root device, ...)
        !           255:     title NetBSD via chain
        !           256:     root        (hd0,a)
        !           257:     chainloader +1
        !           258:     
        !           259:     # end of grub config file.
        !           260:     
        !           261: 
        !           262: Notice that the statement **dom0_mem** is allocating half a gig to Xen. If you
        !           263: have a box with 4Gb of RAM you probably want to change that to something
        !           264: larger. A smaller number might be wise on systems with less RAM, etc...
        !           265: 
        !           266: #  Setting up DOM0
        !           267: 
        !           268: ##  Creating xen devices
        !           269: 
        !           270: To create all xen devices, change to /dev and run ./MAKEDEV xen
        !           271: 
        !           272:     
        !           273:     cd /dev
        !           274:     ./MAKEDEV xen
        !           275:     
        !           276: 
        !           277: This should create the devices **xencons**, **xenevt** and **xsd_kva**. If any
        !           278: of these are missing you may not have updated to _CURRENT_ using the latest
        !           279: sources and you will have to create the missing device files.
        !           280: 
        !           281: ##  Configuring the bridge interface
        !           282: 
        !           283: The [bridge(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bridge+4+NetBSD-current) interface is used to provide network access to DOMUs.
        !           284: 
        !           285: To use one, edit (or create) the file `/etc/ifconfig.bridge0` and insert
        !           286: following lines to:
        !           287: 
        !           288:     
        !           289:     create
        !           290:     !brconfig $int add bge0 stp bge0 up
        !           291:     
        !           292: 
        !           293: Where 'bge0' should be changed to the name of the interface you want to use
        !           294: with your guest operating systems. use [ifconfig(8)](http://netbsd.gw.com/cgi-bin/man-cgi?ifconfig+8+NetBSD-current) to get more details
        !           295: about your actual interfaces.
        !           296: 
        !           297: ##  Rebooting into DOM0
        !           298: 
        !           299: Time to reboot:
        !           300: 
        !           301:     
        !           302:     # shutdown -r now
        !           303:     
        !           304: 
        !           305: If all has gone well, you should have booted into the XEN3_DOM0 kernel. Check
        !           306: this with [uname(1)](http://netbsd.gw.com/cgi-bin/man-cgi?uname+1+NetBSD-current):
        !           307: 
        !           308:     
        !           309:     # uname -v
        !           310:     NetBSD 4.0 (XEN3_DOM0) #0: Sun Dec 16 01:20:31 PST 2007
        !           311:     builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/XEN3_DOM0
        !           312:     
        !           313: 
        !           314: You should have **XEN3 DOM0** mentioned somewhere.
        !           315: 
        !           316: ##  Configuring rc scripts
        !           317: 
        !           318: Copy or symlink xend, xenbackendd and xendomains from
        !           319: `/usr/pkg/share/examples/rc.d` to `/etc/rc.d`.
        !           320: 
        !           321:     
        !           322:     # cp /usr/pkg/share/examples/rc.d/xend /etc/rc.d/
        !           323:     # cp /usr/pkg/share/examples/rc.d/xenbackendd /etc/rc.d/
        !           324:     # cp /usr/pkg/share/examples/rc.d/xendomains /etc/rc.d/
        !           325:     
        !           326: 
        !           327: Edit `/etc/rc.conf` and add the following lines:
        !           328: 
        !           329:     
        !           330:     xend=YES
        !           331:     xenbackendd=YES
        !           332:     xendomains="dom1"
        !           333:     
        !           334: 
        !           335: Later on, when you have created a configuration file for 'dom1', the
        !           336: xendomains variable specified above will trigger 'dom1' to be started when the
        !           337: system is booted. At this point no configuration exists for dom1, therefore it
        !           338: does nothing at this point. If you choose to name your configuration file
        !           339: something else, adapt the name accordingly.
        !           340: 
        !           341: To avoid rebooting a second, start all three services:
        !           342: 
        !           343:     
        !           344:     # /etc/rc.d/xend start
        !           345:     # /etc/rc.d/xenbackendd start
        !           346:     # /etc/rc.d/xendomains start
        !           347:     
        !           348: 
        !           349: Run `ifconfig -a` to ensure the bridge interface is present and issue a `ps ax
        !           350: | grep xen` to ensure you have a similar output.
        !           351: 
        !           352:     
        !           353:     
        !           354:     12 ?     DK   0:00.00 [xenwatch]
        !           355:     13 ?     DK   0:00.00 [xenbus]
        !           356:     411 ?     I    0:00.24 xenstored --pid-file=/var/run/xenstore.pid
        !           357:     594 ?     IWa  0:00.26 xenconsoled
        !           358:     629 ?     IW   0:00.00 /usr/pkg/bin/python2.3 /usr/pkg/sbin/xend start
        !           359:     631 ?     IWsa 0:00.02 /usr/pkg/sbin/xenbackendd
        !           360:     639 ?     IWa  0:00.52 /usr/pkg/bin/python2.3 /usr/pkg/sbin/xend start
        !           361:     
        !           362: 
        !           363: The DOM0 configuration is now done. We will proceed to configuring DOMU
        !           364: domains.
        !           365: 
        !           366: #  Configuring DOMU
        !           367: 
        !           368: ##  Configuring and installing a NetBSD DOMU
        !           369: 
        !           370: Create (or modify) `/usr/pkg/etc/xen/dom1` and include this:
        !           371: 
        !           372:     
        !           373:     
        !           374:     kernel = "/usr/src/obj/releasedir/i386/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz"
        !           375:     #kernel = "/netbsd-XEN3_DOMU"
        !           376:     memory = 64
        !           377:     name = "dom1"
        !           378:     #vcpus = 1
        !           379:     disk = [ 'phy:/dev/wd0g,0x03,w','file:/usr/src/obj/releasedir/i386/installation/cdrom/netbsd-i386.iso,0x04,r' ]
        !           380:     vif = [ 'bridge=bridge0' ]
        !           381:     root = "/dev/wd0d"
        !           382:     
        !           383: 
        !           384: This configuration boots into the NetBSD sysinst program and allows you to
        !           385: install a NetBSD DOMU using the normal sysinst method. This configuration uses
        !           386: a DOMU_INSTALL kernel and an ISO image provided by a successful 'build
        !           387: release' and 'build iso-image'. You may be able to locate a valid Xen3
        !           388: DOMU_INSTALL kernel from <ftp://ftp.netbsd.org/pub/NetBSD-daily/> but if
        !           389: not, building a release is your best bet.
        !           390: 
        !           391: In this configuration file, `/dev/wd0g` is the reserved partition for the
        !           392: guest operating system. This should be changed to the partition you reserved
        !           393: prior to following the instructions within this document.
        !           394: 
        !           395: If you would like to use a physical CDROM instead of an ISO image, change the
        !           396: disk line to:
        !           397: 
        !           398:     
        !           399:     disk = [ 'phy:/dev/wd0g,0x03,w','phy:/dev/cd0a,0x04,r' ]
        !           400:     
        !           401: 
        !           402: Now boot into sysinst using the command:
        !           403: 
        !           404:     
        !           405:     xm create dom1 -c
        !           406:     
        !           407: 
        !           408: The reserved partition will appear as `/dev/xbd0`. Proceed as you would with a
        !           409: normal NetBSD installation using xbd0 as the target drive and xbd1 as the
        !           410: CDROM.
        !           411: 
        !           412: When you have finished, run `shutdown -hp now` to dom1.
        !           413: 
        !           414: Now edit `/usr/pkg/etc/xen/dom1`. Comment the INSTALL kernel and uncomment the
        !           415: DOMU kernel.
        !           416: 
        !           417: You should now have a working NetBSD DOMU (dom1). Boot into dom1 again with
        !           418: the command:
        !           419: 
        !           420:     
        !           421:     xm create dom1 -c
        !           422:     
        !           423: 
        !           424: and ensure the file, `/etc/ttys` contains only this line or has all other
        !           425: lines commented:
        !           426: 
        !           427:     
        !           428:     console "/usr/libexec/getty Pc"         vt100   on secure
        !           429:     
        !           430: 
        !           431: and the file `/etc/wscons.conf` is completely empty or has all lines commented
        !           432: out. These last two steps ensure no errors should be present on boot. Setting
        !           433: wscons=NO in `/etc/rc.conf` may effectively do the same thing.
        !           434: 
        !           435: From here, configure `/etc/rc.conf` and all runtime configuration files as you
        !           436: would normally. The network interface name should be _**xennet0**_. Use this
        !           437: name when configuring an IP address.
        !           438: 
        !           439: More information can be obtained by referencing the [Xen user guide](http://www.cl.cam.ac.uk/Research/SRG/netos/xen/readmes/user/) and
        !           440: [the official NetBSD Xen Howto](http://www.netbsd.org/Ports/xen/howto.html). Questions can be addressed to the port-
        !           441: xen@NetBSD.org mailling list.
        !           442: 
        !           443: ##  Configuring and installing a Windows XP DOMU
        !           444: 
        !           445: This requires an HVM capable processor and xentools (see sections above).
        !           446: 
        !           447: This assumes you have a copy of the Windows install CD in /home/xen/winxp.iso,
        !           448: and wish to create a file /home/xen/winxp.img to hold the install. First
        !           449: create a blank file to hold the install. This assumes a size of 4GB (4096M).
        !           450: If you want a different size adjust the numbers to match:
        !           451: 
        !           452:     
        !           453:     # dd if=/dev/zero of=/home/xen/winxp.img bs=1m count=4096
        !           454:     
        !           455: 
        !           456: Create `/usr/pkg/etc/xen/win01`:
        !           457: 
        !           458:     
        !           459:     
        !           460:     kernel = '/usr/pkg/lib/xen/boot/hvmloader'
        !           461:     builder = 'hvm'
        !           462:     memory = '400'
        !           463:     device_model='/usr/pkg/libexec/qemu-dm'
        !           464:     
        !           465:     disk = [ 'file:/home/xen/winxp.img,ioemu:hda,w',
        !           466:               'file:/home/xen/winxp.iso,ioemu:hdb:cdrom,r', ]
        !           467:     
        !           468:     # Hostname
        !           469:     name = "win01"
        !           470:     
        !           471:     vif = [ 'type=ioemu, bridge=bridge0' ]
        !           472:     
        !           473:     boot= 'd'
        !           474:     vnc = 1
        !           475:     usbdevice = 'tablet' # Helps with mouse pointer positioning
        !           476:     
        !           477: 
        !           478: You may want to modify the amount of memory and pathnames.
        !           479: 
        !           480: Ensure you have a vncviewer installed, such as [net/tightvncviewer](http://pkgsrc.se/net/tightvncviewer) or
        !           481: [net/vncviewer](http://pkgsrc.se/net/vncviewer) from pkgsrc.
        !           482: 
        !           483: Then start the XENU and connect to it via VNC.
        !           484: 
        !           485:     
        !           486:     # xm create /usr/pkg/etc/xen/win01
        !           487:     # vncviewer :0
        !           488:     
        !           489: 
        !           490: This will boot the Windows ISO image and let you install Windows as normal. As
        !           491: Windows reboots during install you may need to restart vncviewer.
        !           492: 
        !           493: After install change the **boot d** to **boot c** to have the system boot
        !           494: directly from the disk image.
        !           495: 
        !           496: ##  Configuring and installing a GNU/Linux DOMU
        !           497: 
        !           498: We will do this in two steps:
        !           499: 
        !           500:   * install a GNU/Linux system, from a livecd or any installation media 
        !           501:   * configure the DOM0 so that it can create and start the Linux DOMU. 
        !           502: 
        !           503: ###  Installing a Linux distribution (soon-to-be DOMU)
        !           504: 
        !           505: Before proceeding with DOMU configuration, we will install our favorite
        !           506: GNU/Linux distribution on the computer.
        !           507: 
        !           508: In order to do it, we need at least two partitions (only one, if you do not
        !           509: consider the swap). These partitions must reside outside of the NetBSD slice,
        !           510: and may be either of primary or extended type. Of course, you can use more
        !           511: than two, but adapt your labels and partitions accordingly.
        !           512: 
        !           513: We do not cover the partition/slices manipulations through [fdisk(8)](http://netbsd.gw.com/cgi-bin/man-cgi?fdisk+8+NetBSD-current) and
        !           514: [disklabel(8)](http://netbsd.gw.com/cgi-bin/man-cgi?disklabel+8+NetBSD-current), as it depends strongly on how you manage your hard drive's
        !           515: space.
        !           516: 
        !           517: For this tutorial, we will use this partitioning:
        !           518: 
        !           519:     
        !           520:     
        !           521:     # fdisk /dev/wd0d                                                      
        !           522:     fdisk: removing corrupt bootsel information
        !           523:     fdisk: Cannot determine the number of heads
        !           524:     Disk: /dev/wd0d
        !           525:     NetBSD disklabel disk geometry:
        !           526:     cylinders: 486344, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
        !           527:     total sectors: 490234752
        !           528:     
        !           529:     BIOS disk geometry:
        !           530:     cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
        !           531:     total sectors: 490234752
        !           532:     
        !           533:     Partition table:
        !           534:     0: Linux native (sysid 131)
        !           535:         start 63, size 20482812 (10001 MB, Cyls 0-1274)
        !           536:             PBR is not bootable: All bytes are identical (0x00)
        !           537:     1: Linux swap or Prime or Solaris (sysid 130)
        !           538:         start 20482875, size 1959930 (957 MB, Cyls 1275-1396)
        !           539:             PBR is not bootable: All bytes are identical (0x00)
        !           540:     2: NetBSD (sysid 169)
        !           541:         start 61464690, size 428770062 (209360 MB, Cyls 3826-30515/178/63), Active
        !           542:     3: <UNUSED>
        !           543:     Drive serial number: -286527765 (0xeeebeeeb)
        !           544:     
        !           545: 
        !           546: Here, you notice that we decide to use two primary partitions for our future
        !           547: Linux DOMU:
        !           548: 
        !           549:   * partition 0 (for the **root directory /**) 
        !           550:   * partition 1 (for the **swap**) 
        !           551: 
        !           552: Labels:
        !           553: 
        !           554:     
        !           555:     
        !           556:     16 partitions:
        !           557:     #        size    offset     fstype [fsize bsize cpg/sgs]
        !           558:      a:  30720816  61464690     4.2BSD   2048 16384     0  # (Cyl.  60976*-  91453*)
        !           559:      b:   1049328  92185506       swap                     # (Cyl.  91453*-  92494*)
        !           560:      c: 428770062  61464690     unused      0     0        # (Cyl.  60976*- 486343)
        !           561:      d: 490234752         0     unused      0     0        # (Cyl.      0 - 486343)
        !           562:      e:  20480000  93234834     4.2BSD      0     0     0  # (Cyl.  92494*- 112812*)
        !           563:      f:  20480000 113714834     4.2BSD      0     0     0  # (Cyl. 112812*- 133129*)
        !           564:      g:  20480000 134194834     4.2BSD      0     0     0  # (Cyl. 133129*- 153447*)
        !           565:      h: 335559918 154674834     4.2BSD      0     0     0  # (Cyl. 153447*- 486343)
        !           566:      i:  20482812        63 Linux Ext2      0     0        # (Cyl.      0*-  20320*)
        !           567:      j:   1959930  20482875       swap                     # (Cyl.  20320*-  22264*)
        !           568:     
        !           569: 
        !           570: Bear in mind that we added two labels here, namely **i** and **j**, which maps
        !           571: respectively to partition 0 and partition 1 of the disk. We will use these
        !           572: labels later for DOMU configuration.
        !           573: 
        !           574: Now that we have partitioned the disk, proceed with installing your Linux
        !           575: distribution. We will not cover that part in this tutorial. You can either
        !           576: install it from an installation media (a cdrom from example), or copy files
        !           577: from an already installed distribution on your computer.
        !           578: 
        !           579: Tip: to manipulate ext2/3 filesystems (the traditional fs under Linux) from
        !           580: NetBSD, you can use [sysutils/e2fsprogs](http://pkgsrc.se/sysutils/e2fsprogs) from pkgsrc:
        !           581: 
        !           582:     
        !           583:     # cd /usr/pkgsrc/sysutils/e2fsprogs
        !           584:     # make install
        !           585:     
        !           586: 
        !           587: And then use e2fsck, mke2fs and [mount_ext2fs(8)](http://netbsd.gw.com/cgi-bin/man-cgi?mount_ext2fs+8+NetBSD-current) directly from NetBSD.
        !           588: 
        !           589: ###  Getting XEN aware Linux kernels
        !           590: 
        !           591: Once installation is done, reboot your computer and return to our Xen-NetBSD
        !           592: system.
        !           593: 
        !           594: To boot our Linux DOMU, we will need a Linux kernel supporting the XENU
        !           595: virtualisation. Depending on your Linux distribution, you can grab one from
        !           596: its repository (it is up to you to find it through aptitude, yum or whatever
        !           597: package manager you use), or get one from the Xen binary distribution.
        !           598: 
        !           599: To get a XENU Linux kernel from Xen binary distribution, get it directly from
        !           600: [Xen website download page](http://www.xen.org/download/dl_31tarballs.html). Download the tarball and extract the
        !           601: **vmlinuz-*-xen** from it. In our case, with a 2.6.18 Linux kernel:
        !           602: 
        !           603:     
        !           604:     # ftp -a http://bits.xensource.com/oss-xen/release/3.1.0/bin.tgz/xen-3.1.0-install-x86_32.tgz
        !           605:     # cd /tmp
        !           606:     # tar -xzf xen-3.1.0-install-x86_32.tgz dist/install/boot/vmlinuz-2.6.18-xen
        !           607:     
        !           608: 
        !           609: **vmlinuz-2.6.18-xen** is the kernel that Xen will use to start the DOMU. Move it to any directory you like (just remember it when configuring the _kernel_ entry in the DOMU configuration file): 
        !           610:     
        !           611:     # mv dist/install/boot/vmlinuz-2.6.18-xen /vmlinuz-XEN3-DOMU
        !           612:     
        !           613: 
        !           614: ###  Configuring DOMU
        !           615: 
        !           616: Configuring the Linux DOMU is a bit different than a NetBSD one; some options
        !           617: tend to differ.
        !           618: 
        !           619: Edit (or create) the configuration file **domu-linux**, in
        !           620: `/usr/pkg/etc/xen/`:
        !           621: 
        !           622:     
        !           623:     # vi /usr/pkg/etc/xen/domu-linux
        !           624:     
        !           625: 
        !           626: Here's a typical config file for a Linux DOMU:
        !           627: 
        !           628:     
        !           629:     
        !           630:     #----------------------------------------------------------------------------
        !           631:     # Kernel image file. This kernel will be loaded in the new domain.
        !           632:     kernel = "/vmlinuz-XEN3-DOMU"
        !           633:     
        !           634:     # Memory allocation (in megabytes) for the new domain.
        !           635:     memory = 256
        !           636:     
        !           637:     # A handy name for your new domain. This will appear in 'xm list',
        !           638:     # and you can use this as parameters for xm in place of the domain
        !           639:     # number. All domains must have different names.
        !           640:     #
        !           641:     name = "domu-linux"
        !           642:     
        !           643:     # Which CPU to start domain on (only relevant for SMP hardware).  CPUs
        !           644:     # numbered starting from ``0''.
        !           645:     #
        !           646:     cpu = "^1"   # leave to Xen to pick
        !           647:     
        !           648:     #----------------------------------------------------------------------------
        !           649:     # Define network interfaces for the new domain.
        !           650:     
        !           651:     # Number of network interfaces (must be at least 1). Default is 1.
        !           652:     vif = [ '' ]
        !           653:     
        !           654:     # Define MAC and/or bridge for the network interfaces.
        !           655:     #
        !           656:     # The MAC address specified in ``mac'' is the one used for the interface
        !           657:     # in the new domain. The interface in domain0 will use this address XOR'd
        !           658:     # with 00:00:00:01:00:00 (i.e. aa:00:00:51:02:f0 in our example). Random
        !           659:     # MACs are assigned if not given.
        !           660:     #
        !           661:     # ``bridge'' is a required parameter, which will be passed to the
        !           662:     # vif-script called by xend(8) when a new domain is created to configure
        !           663:     # the new xvif interface in domain0.
        !           664:     #
        !           665:     # In this example, the xvif is added to bridge0, which should have been
        !           666:     # set up prior to the new domain being created -- either in the
        !           667:     # ``network'' script or using a /etc/ifconfig.bridge0 file.
        !           668:     #
        !           669:     vif = [ 'mac=aa:00:00:50:02:f0, bridge=bridge0' ]
        !           670:     
        !           671:     #----------------------------------------------------------------------------
        !           672:     # Define the disk devices you want the domain to have access to, and
        !           673:     # what you want them accessible as.
        !           674:     #
        !           675:     # Each disk entry is of the form:
        !           676:     #
        !           677:     #       phy:DEV,VDEV,MODE
        !           678:     #
        !           679:     # where DEV is the device, VDEV is the device name the domain will see,
        !           680:     # and MODE is r for read-only, w for read-write.  You can also create
        !           681:     # file-backed domains using disk entries of the form:
        !           682:     #
        !           683:     #       file:PATH,VDEV,MODE
        !           684:     #
        !           685:     # where PATH is the path to the file used as the virtual disk, and VDEV
        !           686:     # and MODE have the same meaning as for ``phy'' devices.
        !           687:     #
        !           688:     # /dev/wd0i will be seen as "hda1" under DOMU (the root partition)
        !           689:     # /dev/wd0j will be seen as "hda2" under DOMU (the swap)
        !           690:     #
        !           691:     disk = [ 'phy:/dev/wd0i,hda1,w','phy:/dev/wd0j,hda2,w' ]
        !           692:     
        !           693:     #----------------------------------------------------------------------------
        !           694:     # Set the kernel command line for the new domain.
        !           695:     
        !           696:     # Set root device.
        !           697:     root = "/dev/hda1"
        !           698:     
        !           699: 
        !           700: Now, you should be able to start your first Linux DOMU!
        !           701: 
        !           702:     
        !           703:     # xm create -c /usr/pkg/etc/xen/domu-linux
        !           704:     
        !           705: 
        !           706: #  Possible caveats
        !           707: 
        !           708: If you intend to have more than one box configured with the above
        !           709: configuration on the same network, you will most likely have to specify a
        !           710: unique MAC address per guest OS, otherwise it is likely you will have a
        !           711: conflict. I'm not sure if the MAC assignment is random, incremental or if Xen
        !           712: is able to check for the existence of the proposed MAC address, so specifying
        !           713: the MAC address is recommended.
        !           714: 
        !           715: Here is a method to assign a MAC address to a newly created Xen Domu. First as
        !           716: described before, use the following vif parameter in your config file :
        !           717: 
        !           718:     
        !           719:     
        !           720:     vif = [ 'bridge=bridge0' ]
        !           721:     
        !           722: 
        !           723: Then, run the Xen DomU and, once logged run the following command :
        !           724: 
        !           725:     
        !           726:     
        !           727:     # ifconfig xennet0
        !           728:     
        !           729:     Output Sample : 
        !           730:     
        !           731:     xennet0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        !           732:             capabilities=2800<TCP4CSUM_Tx,UDP4CSUM_Tx>
        !           733:             enabled=0
        !           734:             address: 00:16:3e:2e:32:5f
        !           735:             inet 192.168.4.81 netmask 0xffffff00 broadcast 192.168.4.255
        !           736:             inet6 fe80::216:3eff:fe2e:325f%xennet0 prefixlen 64 scopeid 0x2
        !           737:     
        !           738:     
        !           739: 
        !           740: A MAC address is automaticaly generated, use it in your config file with the
        !           741: following syntax :
        !           742: 
        !           743:     
        !           744:     
        !           745:     vif = [ 'mac=00:16:3e:2e:32:5f, bridge=bridge0' ]
        !           746:     
        !           747: 
        !           748: And now you can restart the Xen DomU.
        !           749: 
        !           750: Please, note that the MAC Address MUST start with "00:16:3e".
        !           751: 
        !           752:   
        !           753: 
        !           754: #  See also
        !           755: 
        !           756:   * [The official NetBSD Xen Howto](http://www.netbsd.org/Ports/xen/howto.html)
        !           757:   * [The official Xen Wiki](http://wiki.xensource.com/xenwiki/)
        !           758: 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb