]> scripts.mit.edu Git - xen.git/commitdiff
Support for automatically downloading kernel/initramfs, and broken Kickstart support.
authorEdward Z. Yang <ezyang@mit.edu>
Mon, 20 Sep 2010 05:04:47 +0000 (01:04 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Mon, 20 Sep 2010 05:04:47 +0000 (01:04 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
scripts-server
scripts.ks [new file with mode: 0644]

index 9b3b4ea023bcc278c2934d8be186672365daea6d..d3a827ab78d3cbda838240f13f21f7e92c0c7325 100644 (file)
@@ -27,16 +27,76 @@ vm = machines[machine_name]
 
 mac5 = vm[vm_mac5]
 
+def maybe_download_isolinux(install):
+  """
+  Download the release image if it isn't already in /root.
+  """
+  import subprocess
+  import os.path
+
+  install_dir = "/root/%s-install" % install
+  if os.path.exists(install_dir): return
+  print "Downloading %s..." % install_dir
+  fedora_release = install[1:],
+  download_dir = "ftp://mirrors.mit.edu/fedora/linux/releases/%s/Fedora/x86_64/os" % fedora_release
+  os.mkdir(install_dir)
+  subprocess.check_call(["wget", "-r", "-nd", download_dir], cwd=install_dir)
+
+def make_ramdisk(base_image, machine_name, install):
+  """
+  Create a ramdisk containing our kickstart file in /root/kickstart.ks
+  """
+  import socket
+  import tempfile
+  import subprocess
+  import os
+  import os.path
+  import gzip
+  import StringIO
+  import string
+  import shutil
+
+  # some calculations
+  hostname = machine_name + ".mit.edu"
+  ip = socket.gethostbyname(hostname)
+
+  # create the playground
+  tmpdir = tempfile.mkdtemp()
+  rootdir = os.path.join(tmpdir, "root")
+
+  # add the kickstart file
+  os.mkdir(rootdir)
+  ks_orig = open("/etc/xen/scripts.ks").read()
+  ks = string.Template(ks_orig).substitute(
+    local_mirror = "ftp://mirrors.mit.edu",
+    official_mirror = "http://download3.fedora.redhat.com/pub",
+    arch = "x86_64",
+    fedora_release = install[1:],
+    hostname = hostname,
+    ip = ip,
+    )
+  open(os.path.join(rootdir, "scripts.ks"), 'w').write(ks)
+
+  # generate the final image
+  (tmpfd, tmpname) = tempfile.mkstemp(suffix=".img")
+  tmp = os.fdopen(tmpfd, 'w')
+  tmp.write(gzip.open(base_image).read())
+  tmp.close()
+  find = subprocess.Popen(["find", ".", "-depth", "-print"],
+            stdout=subprocess.PIPE, cwd=tmpdir)
+  cpio = subprocess.Popen(["cpio", "-v", "--append", "-o", "--file", tmpname, "-H", "newc"],
+            stdin=find.stdout, cwd=tmpdir)
+  cpio.communicate()
+  find.wait()
+
+  print "Using initramfs at %s" % tmpname
+  return tmpname
+
 if 'install' in locals():
-  # Get these files from a Fedora mirror, from a path like
-  # pub/fedora/linux/releases/test/11-Preview/Fedora/x86_64/os/isolinux/
-  # You can use ftp://mirrors.mit.edu and wget -R to easily grab the
-  # entire contents of the directory.  To do the network install, use
-  # a URL like ftp://mirrors.mit.edu/fedora/linux/releases/13/Fedora/x86_64/os
-  # I'm not sure what you're supposed to do for IPv6
   kernel = "/root/%s-install/vmlinuz" % install
-  ramdisk = "/root/%s-install/initrd.img" % install
-  extra = "selinux=0"
+  extra = "selinux=0 ks=file:/root/scripts.ks"
+  maybe_download_isolinux(install)
+  ramdisk = make_ramdisk("/root/%s-install/initrd.img" % install, machine_name, install)
 elif 'type' in locals() and type == 'hvm':
   kernel = "/usr/lib/xen/boot/hvmloader"
   builder = "hvm"
diff --git a/scripts.ks b/scripts.ks
new file mode 100644 (file)
index 0000000..de5dd73
--- /dev/null
@@ -0,0 +1,41 @@
+# Kickstart file for scripts.mit.edu
+
+# Parameters:
+#   local_mirror    = ${local_mirror}
+#   official_mirror = ${official_mirror}
+#   fedora_release  = ${fedora_release}
+#   arch            = ${arch}
+#   hostname        = ${hostname}
+#   ip              = ${ip}
+
+install
+url --url=${local_mirror}/fedora/linux/releases/${fedora_release}/Fedora/${arch}/os
+lang en_US.UTF-8
+keyboard us
+network --device eth0 --bootproto static --ip ${ip} --netmask 255.255.0.0 --gateway 18.181.0.1 --nameserver 18.71.0.151 --hostname ${hostname}
+
+timezone --utc America/New_York
+selinux --disabled
+authconfig --enableshadow --passalgo=sha512 --enablefingerprint
+firewall --disabled
+
+clearpart --none --drives=xvda,xvde --initlabel
+ignoredisk --only-use=xvde,xvda
+part / --fstype=ext3 --grow --asprimary --size=1
+part swap --grow --size=1
+
+bootloader --location=mbr --driveorder=xvda,xvde --append="console=hvc0 rhgb quiet"
+repo --name="Fedora ${fedora_release} - ${arch}"  --baseurl=${official_mirror}/fedora/linux/releases/${fedora_release}/Everything/${arch}/os/
+
+user --name=scripts-build
+
+%packages
+subversion
+make
+redhat-lsb
+autofs
+vim
+emacs
+@core
+@online-docs
+%end