aboutsummaryrefslogtreecommitdiffstats
path: root/tools/examples/createlinuxdom.py
diff options
context:
space:
mode:
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>2003-11-22 11:45:34 +0000
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>2003-11-22 11:45:34 +0000
commitbbfbd58d871ceea8cef59513bb842d46b6d24041 (patch)
treeee112fb615aa5280090856c54078864bc7e11470 /tools/examples/createlinuxdom.py
parent570b66d8add794c2133bbe96ef280a7faab1f455 (diff)
downloadxen-bbfbd58d871ceea8cef59513bb842d46b6d24041.tar.gz
xen-bbfbd58d871ceea8cef59513bb842d46b6d24041.tar.bz2
xen-bbfbd58d871ceea8cef59513bb842d46b6d24041.zip
bitkeeper revision 1.630 (3fbf4c5eGi95ZU5mjOHJ4L6ioUNlKA)
stopdom.py: Rename: tools/examples/xi_stopdom.py -> tools/examples/stopdom.py destroydom.py: Rename: tools/examples/xi_destroydom.py -> tools/examples/destroydom.py listdoms.py: Rename: tools/examples/xi_listdoms.py -> tools/examples/listdoms.py createlinuxdom.py: Rename: tools/examples/xi_createlinuxdom.py -> tools/examples/createlinuxdom.py
Diffstat (limited to 'tools/examples/createlinuxdom.py')
-rwxr-xr-xtools/examples/createlinuxdom.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/examples/createlinuxdom.py b/tools/examples/createlinuxdom.py
new file mode 100755
index 0000000000..2e25e303e8
--- /dev/null
+++ b/tools/examples/createlinuxdom.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+#
+# Example script for creating and building a new Linux guest OS for Xen.
+#
+
+import Xc, XenoUtil, sys, os
+
+# Variable declaration. Set these up properly later on, as needed.
+nfsserv = nfspath = root_partn = usr_partn = ""
+
+# STEP 1. Specify kernel image file.
+image = "FULL_PATH_TO_IMAGE"
+
+# STEP 2. Specify IP address, netmask and gateway for the new domain.
+ipaddr = "ADDRESS"
+netmask = XenoUtil.get_current_ipmask()
+gateway = XenoUtil.get_current_ipgw()
+
+# STEP 3a. Specify NFS server and path to rootfs (only needed for network boot)
+nfsserv = "ADDRESS"
+nfspath = "FULL_PATH_TO_ROOT_DIR"
+
+# STEP 3b. Specify root (and possibly /usr) on local disc (if not NFS booting)
+#root_partn = "/dev/sda2"
+#usr_partn = "/dev/sda6"
+
+# STEP 4. Check that the following cmdline setup is to your taste.
+cmdline = "ip="+ipaddr+":"+nfsserv+":"+gateway+":"+netmask+"::eth0:off"
+if root_partn:
+ # Boot from local disc. May specify a separate /usr.
+ cmdline = cmdline + " root="+root_partn+" ro"
+ if usr_partn:
+ " usr="+usr_partn
+elif nfsserv:
+ # NFS boot
+ cmdline = cmdline + " root=/dev/nfs"
+ cmdline = cmdline + " nfsroot="+nfspath
+
+if root_partn:
+ root_info = XenoUtil.lookup_blkdev_partn_info(root_partn)
+ if not root_info:
+ print "Could not obtain info on partition '" + root_partn + "'"
+ sys.exit()
+
+if usr_partn:
+ usr_info = XenoUtil.lookup_blkdev_partn_info(usr_partn)
+ if not usr_info:
+ print "Could not obtain info on partition '" + usr_partn + "'"
+ sys.exit()
+
+if not os.path.isfile( image ):
+ print "Image file '" + image + "' does not exist"
+ sys.exit()
+
+xc = Xc.new()
+
+id = xc.domain_create()
+if id <= 0:
+ print "Error creating domain"
+ sys.exit()
+
+if xc.linux_build( dom=id, image=image, cmdline=cmdline ):
+ print "Error building Linux guest OS"
+ xc.domain_destroy ( dom=id )
+ sys.exit()
+
+if root_partn:
+ if xc.vbd_create( dom=id, vbd=root_info[0], writeable=1 ):
+ print "Error creating root VBD"
+ xc.domain_destroy ( dom=id )
+ sys.exit()
+ if xc.vbd_add_extent( dom=id,
+ vbd=root_info[0],
+ device=root_info[1],
+ start_sector=root_info[2],
+ nr_sectors=root_info[3] ):
+ print "Error populating root VBD"
+ xc.domain_destroy ( dom=id )
+ sys.exit()
+
+if usr_partn:
+ if xc.vbd_create( dom=id, vbd=usr_info[0], writeable=0 ):
+ print "Error creating usr VBD"
+ xc.domain_destroy ( dom=id )
+ sys.exit()
+ if xc.vbd_add_extent( dom=id,
+ vbd=usr_info[0],
+ device=usr_info[1],
+ start_sector=usr_info[2],
+ nr_sectors=usr_info[3] ):
+ print "Error populating usr VBD"
+ xc.domain_destroy ( dom=id )
+ sys.exit()
+
+XenoUtil.setup_vfr_rules_for_vif( id, 0, ipaddr )
+
+if xc.domain_start( dom=id ):
+ print "Error starting domain"
+ xc.domain_destroy ( dom=id )
+ sys.exit()