fixing up remaining steps to build an image

This commit is contained in:
Neil Williams 2016-07-01 17:27:53 +02:00 committed by Iain R. Learmonth
parent 01052831b6
commit e54cb37851
6 changed files with 34 additions and 22 deletions

15
bin/lwr
View file

@ -13,7 +13,7 @@ intended to be run from the command line.
See live-wrapper(8) for more information.
"""
# pylint: disable=wrong-import-order,missing-docstring
# pylint: disable=wrong-import-order,missing-docstring,superfluous-parens
import sys
import os
@ -32,9 +32,12 @@ from lwr.apt_udeb import AptUdebDownloader
__version__ = '0.4'
DI_BASE = 'http://ftp.debian.org/debian/dists/stretch/main/'
# FIXME: needs to be a setting to allow for local full mirrors
# DI_BASE = 'http://ftp.debian.org/debian/dists/stretch/main/'
DI_BASE = 'http://localhost/mirror/debian/dists/stretch/main/'
KERNEL = 'vmlinuz'
RAMDISK = 'initrd.gz'
# FIXME: needs to allow for architecture setting
DI_KERNEL = (DI_BASE + 'installer-amd64/current/images/cdrom/' + KERNEL)
DI_RAMDISK = (DI_BASE + 'installer-amd64/current/images/cdrom/' + RAMDISK)
# Not used yet but may be good to have
@ -69,7 +72,7 @@ def fetch_di_helpers():
os.remove(ditar[1])
# python 2
else:
ditar = tempfile.NamedTemporaryFile(delete=False)
ditar = tempfile.NamedTemporaryFile(delete=False) # pylint: disable=redefined-variable-type
curl = pycurl.Curl()
curl.setopt(curl.URL, DI_HELPERS)
curl.setopt(curl.WRITEDATA, ditar)
@ -150,7 +153,7 @@ class LiveWrapper(cliapp.Application):
sys.exit("You need to have root privileges to run this script.")
self.start_ops()
def start_ops(self):
def start_ops(self): # pylint: disable=too-many-statements
"""
This function creates the live image using the settings determined by
the arguments passed on the command line.
@ -217,13 +220,13 @@ class LiveWrapper(cliapp.Application):
if self.settings['isolinux']:
logging.info("Performing isolinux installation...")
install_isolinux(self.cdroot)
update_di_isolinux(self.di_kernel, self.di_ramdisk)
update_isolinux(self.cdroot, self.di_kernel, self.di_ramdisk)
# Install GRUB if selected
if self.settings['grub'] or self.settings['grub-loopback-only']:
logging.info("Performing GRUB installation...")
install_grub(self.cdroot, self.cdhelp)
update_di_grub(self.di_kernel, self.di_ramdisk)
update_grub(self.cdroot, self.di_kernel, self.di_ramdisk)
# Install .disk information
logging.info("Installing the disk metadata (badly)...")

View file

@ -12,8 +12,9 @@ trap cleanup 0
mount_support
disable_daemons
# FIXME: pass the specified build mirror.
prepare_apt_source 'http://mirror.bytemark.co.uk/debian' 'stable'
# prepare_apt_source 'file:///home/neil/mirror/debian' 'stable'
# MUST be available over http, file:// will not work inside the VM chroot
# prepare_apt_source 'http://mirror.bytemark.co.uk/debian' 'stable'
prepare_apt_source 'http://localhost/mirror/debian' 'stable'
chroot ${rootdir} apt-get -y install initramfs-tools live-boot live-config ${LWR_TASK_PACKAGES} ${LWR_EXTRA_PACKAGES} task-laptop task-english

View file

@ -18,6 +18,8 @@ def install_disk_info():
cdroot.
"""
os.mkdir("cdroot/.disk")
# this is not a temporary directory
if not os.path.exists("cdroot/.disk"):
os.mkdir("cdroot/.disk")
with open("cdroot/.disk/info", "w") as i:
i.write("HELLO")

View file

@ -22,8 +22,8 @@ class GrubConfig(object):
vmdebootstrap squashfs output directory.
"""
def __init__(self, cdroot):
self.versions = detect_kernels(cdroot)
def detect(self):
self.versions = detect_kernels()
def generate_cfg(self):
ret = ("if [ ${iso_path} ] ; then\nset loopback=\"" +
@ -42,17 +42,20 @@ class GrubConfig(object):
ret += " linux /d-i/%s\"\n" % kernel
ret += " initrd /d-i/%s\n" % ramdisk
ret += "}\n"
return ret
def install_grub(cdroot, cdhelp):
shutil.copytree("%s/grub" % (cdhelp,), "%s/boot/grub" % (cdroot,))
config = GrubConfig()
config.detect()
with open("%s/boot/grub/grub.cfg" % (cdroot,), "a") as cfgout:
cfgout.write(GrubConfig(cdroot).generate_cfg())
cfgout.write(config.generate_cfg())
with open("%s/boot/grub/loopback.cfg" % (cdroot,), "w") as loopout:
loopout.write("source /boot/grub/grub.cfg")
def update_grub(cdroot, kernel, ramdisk):
config = GrubConfig()
with open("%s/boot/grub/grub.cfg" % (cdroot,), "a") as cfgout:
# FIXME: spurious call to detect_kernels here
cfgout.write(GrubConfig(cdroot).generate_di_cfg(kernel, ramdisk))
cfgout.write(config.generate_di_cfg(kernel, ramdisk))

View file

@ -23,8 +23,8 @@ class ISOLINUXConfig(object):
vmdebootstrap squashfs output directory.
"""
def __init__(self, cdroot):
self.versions = detect_kernels(cdroot)
def detect(self):
self.versions = detect_kernels()
def generate_cfg(self):
ret = str()
@ -58,16 +58,19 @@ def install_isolinux(cdroot):
os.mkdir("%s/boot" % (cdroot,))
ISOLINUX_DIR = "%s/boot/isolinux" % (cdroot,)
os.mkdir(ISOLINUX_DIR)
# FIXME: cannot depend on sysvinit-common - could be the wrong arch or suite
shutil.copyfile("/usr/lib/syslinux/modules/bios/ldlinux.c32",
"%s/ldlinux.c32" % (ISOLINUX_DIR,))
shutil.copyfile("/usr/lib/ISOLINUX/isolinux.bin",
"%s/isolinux.bin" % (ISOLINUX_DIR,))
config = ISOLINUXConfig()
config.detect()
with open("%s/isolinux.cfg" % (ISOLINUX_DIR,), "w") as cfgout:
cfgout.write(ISOLINUXConfig(cdroot).generate_cfg())
cfgout.write(config.generate_cfg())
def update_isolinux(cdroot, kernel, ramdisk):
isolinux_dir = "%s/boot/isolinux" % (cdroot,)
config = ISOLINUXConfig()
with open("%s/isolinux.cfg" % (isolinux_dir,), "a") as cfgout:
# FIXME: spurious call to detect_kernels here
cfgout.write(ISOLINUXConfig(cdroot).generate_di_cfg(kernel, ramdisk))
cfgout.write(config.generate_di_cfg(kernel, ramdisk))

View file

@ -34,7 +34,7 @@ class VMDebootstrap:
self.args.extend(["--mirror", mirror])
# FIXME: apt-mirror is for what the booted image will use
# this should not be the local mirror used to build the vm
self.args.extend(["--apt-mirror", 'http://mirror.dc16.debconf.org/debian'])
self.args.extend(["--apt-mirror", 'http://localhost/mirror/debian'])
def run(self):
print(' '.join(self.args))
@ -42,9 +42,9 @@ class VMDebootstrap:
print('vmdebootstrap complete')
def detect_kernels(cdroot):
def detect_kernels():
versions = []
filenames = os.listdir("%s/live" % (cdroot,))
filenames = os.listdir("cdroot/live") # static directory for squashfs support
for filename in filenames:
if filename[0:8] == "vmlinuz-":
versions.append(filename[8:])