summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-07-28 22:53:51 +0300
committerAlon Levy <alevy@redhat.com>2011-07-28 22:53:51 +0300
commit029ea629a4bff500cf33249b8300a6fb153fd792 (patch)
treec3bfd24614527daebbf2a9815a360e2e178639e2
parent633cc1a03b805f6000d3e80de1b2528db6f0a535 (diff)
add helper to copy qxl drivers into image (while image is not used by a vm\!)
-rwxr-xr-xcopy_qxl_to_image84
1 files changed, 84 insertions, 0 deletions
diff --git a/copy_qxl_to_image b/copy_qxl_to_image
new file mode 100755
index 0000000..3c3cfc6
--- /dev/null
+++ b/copy_qxl_to_image
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+
+import argparse
+import sys
+import os
+import subprocess
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--image', dest='image', default=None)
+parser.add_argument('--root', dest='root', default=None)
+parser.add_argument('--partition', dest='partition', default=None)
+parser.add_argument('--system32', dest='system32', choices=['Windows/System32', 'WINDOWS/system32'])
+parser.add_argument('--erase_old_driver_files', dest='erase', default=False, action='store_true')
+args, rest = parser.parse_known_args(sys.argv[1:])
+
+def no_flags_usage(rest):
+ if len(rest) != 4:
+ print p.usage
+ sys.exit(1)
+# do this via argparse??
+if not args.image:
+ no_flags_usage(rest)
+ args.image = rest[0]
+if not args.root:
+ no_flags_usage(rest)
+ args.root = rest[1]
+if not args.partition:
+ no_flags_usage(rest)
+ args.partition = rest[2]
+if not args.system32:
+ args.system32 = 'WINDOWS/system32' if (len(rest) != 4) else rest[3]
+base=os.path.dirname(args.image)
+qxldd_path = os.path.realpath(os.path.join(args.root, 'qxldd.dll'))
+if not os.path.exists(qxldd_path):
+ print "missing qxldd.dll"
+ sys.exit(1)
+qxlsys_path = os.path.realpath(os.path.join(args.root, 'qxl.sys'))
+if not os.path.exists(qxlsys_path):
+ print "missing qxl.sys"
+ sys.exit(1)
+if not os.path.exists(args.image):
+ print "provided image does not exist"
+ sys.exit(1)
+image_user = os.popen("lsof -t %s" % args.image).read().strip()
+if len(image_user) != 0:
+ print "image is being used by %s" % image_user
+ print "will not update used image"
+ sys.exit(1)
+
+def not_too_old(p):
+ if os.system("peversion %s" % p):
+ print "%s is too old" % p
+ sys.exit(1)
+
+not_too_old(qxldd_path)
+not_too_old(qxlsys_path)
+
+data = dict(system32=args.system32, partition=args.partition,
+ image=args.image,base=base, qxldd_path=qxldd_path, qxlsys_path=qxlsys_path,
+ root=args.root)
+
+# win7 version - vda2 (two ntfs partitions)
+guestfish_commands = """add %(image)s
+lcd %(base)s
+run
+mount /dev/vda%(partition)s /
+upload %(qxldd_path)s /%(system32)s/qxldd.dll
+upload %(qxlsys_path)s /%(system32)s/drivers/qxl.sys
+checksum md5 /%(system32)s/qxldd.dll
+checksum md5 /%(system32)s/drivers/qxl.sys
+""" % data
+
+def guestfish(commands):
+ gf = subprocess.Popen('guestfish', stdin=subprocess.PIPE)
+ gf.stdin.write(commands)
+ gf.stdin.close()
+ return gf.wait()
+
+print "copying qxl driver %(root)s to %(image)s with system32=%(system32)s" % data
+if guestfish(guestfish_commands):
+ print "guestfish_copy failed"
+ sys.exit(1)
+os.system("md5sum %(qxldd_path)s" % data)
+os.system("md5sum %(qxlsys_path)s" % data)