def setup_boot(self, devices, path): first_device, partitions = find_first_device(devices) tmp_devicemap = generate_devicemap(devices) log.info("Writing temporary device.map") write_mounted(self.mountpoint, "boot/grub/device.map", tmp_devicemap) log.info("Installing grub on first device") self.chroot(path, "grub-install", "--no-floppy", first_device)
def action(ns): if not os.path.isfile(ns.image_path): raise Exception("Missing image file: {0}".format(ns.image_path)) if ns.selections is None: ns.selections = os.path.join(ns.root, "selections", "default") if not os.path.isfile(ns.selections): raise Exception("Missing selections file: {0}".format(ns.selections)) with ns.preset.entered_system() as d: devices, logical_volumes, mountpoint = d # find first device as soon as possible apt_env = dict(APTITUDE_ENV) preinst = ns.config.get("preinst") if preinst: execute_chrooted(ns, preinst) log.info("Configuring apt") configure_base_system(ns, apt_env, mountpoint) log.info("Install selected packages") if ns.download: download_selections(ns, apt_env, mountpoint) else: install_selections(ns, apt_env, mountpoint) ns.preset.setup_boot(devices, mountpoint) log.info("Writing fstab") fstab = generate_fstab(ns) write_mounted(mountpoint, "etc/fstab", fstab) log.info("Writing real device.map") new_devicemap = generate_devicemap(ns, logical_volumes) write_mounted(mountpoint, "boot/grub/device.map", new_devicemap) manifest = ns.config.get("manifest") postinst = ns.config.get("postinst") if manifest: install_manifest(ns, manifest) if postinst: execute_chrooted(ns, postinst) chroot(ns.mountpoint, "update-initramfs", "-u") return 0
def install_selections(ns, apt_env, mountpoint): with open(ns.selections) as f: log.info("Setting selections") chroot(mountpoint, ns.dpkg, "--set-selections", env=apt_env, input_fd=f) log.info("Installing selections") write_mounted(ns.mountpoint, "usr/sbin/policy-rc.d", ["exit 101"]) chroot(mountpoint, 'chmod', '755', '/usr/sbin/policy-rc.d') chroot(mountpoint, ns.apt_get, "-y", "-u", "dselect-upgrade", env=apt_env) chroot(mountpoint, 'rm', '-f', '/usr/sbin/policy-rc.d')
def configure_base_system(ns, apt_env, mountpoint): prepackages = ns.config.get("pre-packages") if prepackages: log.info("Installing pre-required packages") install_packages(ns, mountpoint, prepackages, env=apt_env, extra=["-y", "--force-yes"]) sources = ns.config.get("sources") if sources: log.info("Writing sources.list") sourceslist = generate_sources(sources) write_mounted(mountpoint, "etc/apt/sources.list", sourceslist) keys = ns.config.get("keys", []) preferences = ns.config.get("preferences", []) if keys: insert_apt_keys(ns, mountpoint, keys) if preferences: insert_apt_preferences(ns, mountpoint, preferences) if hasattr(ns.preset, 'setup_apt'): ns.preset.setup_apt() log.info("Updating apt") chroot(mountpoint, ns.apt_get, "-y", "update", env=apt_env) packages = ns.config.get("packages") if packages: log.info("Installing required packages") install_packages(ns, mountpoint, packages, env=apt_env, extra=["-y", "--force-yes"]) log.info("Updating apt") chroot(mountpoint, ns.apt_get, "-y", "update", env=apt_env)