def _bootstrap_with_tarball(self, suite): self.check_target_exists() suite_path = path(self.defenv.get('installer', 'suite_storage')) filename = '%s.tar.gz' % suite basefile = suite_path / filename taropts = '-xzf' # we normally expect a tar.gz # but we'll check for a plain tar also if not basefile.exists(): filename = '%s.tar' % suite basefile = suite_path / filename taropts = '-xf' if not basefile.exists(): # We don't really want to ruin an install # by not having a tarball, so we log a warning # and proceed with a debootstrap. msg = "base tarball not found, reverting to debootstrap" self.log.warn(msg) self._bootstrap_with_debootstrap(suite) else: #cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile) cmd = ['tar', '-C', str(self.target), taropts, str(basefile)] # if cmd returns nonzero, runlog will raise an error runlog(cmd) # we need to do certain things after extraction # that debootstrap does for us, # like copy /etc/resolv.conf to the target. # these things should be done in the # ready_base_for_install process self._bootstrapped = True
def install_grub_package(self, grub="grub"): # cmd = self.chroot_precommand + self.aptinstall + [grub] apt_command = install_packages_command( [grub], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag="paella-bootloader" ) cmd = self.chroot_precommand + apt_command runlog(cmd)
def _determine_disks_for_grub(self, bootdevice): if not bootdevice.startswith('/dev/md'): msg = "This method is only to be used when the " msg += "boot device is set to /dev/md*" self.log.error(msg) raise RuntimeError, msg device_map = self.target / 'boot/grub/device.map' if not device_map.isfile(): #raise RuntimeError , 'We need the device.map from grub' cmd = self.chroot_precommand + ['grub-mkdevicemap', '-n'] runlog(cmd) self.log.info('device.map should be created now.') if not device_map.isfile(): msg = 'Failed to make device.map' self.log.error(msg) raise RuntimeError, msg else: self.log.info('device.map has been found') lines = [line for line in file(device_map) if line.startswith('(hd0)')] if len(lines) != 1: msg = "Unable to find (hd0) in device.map" self.log.error(msg) raise RuntimeError, msg line = lines[0] grubdev, bootdevice = line.split() self.log.info('going to use %s as the boot device for grub' % bootdevice) return bootdevice
def mount_target(self): print "in mount_target" fstab_filename = self.disklogpath / "fstab" if not fstab_filename.isfile(): msg = "couldn't find fstab at %s" % fstab_filename self.log.error(msg) raise RuntimeError, msg fstab_lines = [line.split() for line in fstab_filename.open() if not line.startswith("#")] # print fstab_lines # start mounting for line in fstab_lines: # print line device = line[0] mtpt = line[1] fstype = line[2] # print 'device, mtpt, fstype', device, mtpt, fstype if mtpt.startswith("/"): target_path = self.target / mtpt[1:] if not target_path.isdir(): target_path.mkdir() # in case we're mounting /tmp as tmpfs # or similar if fstype not in ["tmpfs"]: cmd = ["mount", "-t", fstype, device, target_path] # print ' '.join(cmd) runlog(cmd) else: self.log.info("not mounting %s with %s fstype" % (mtpt, fstype))
def mount_target(self): print "in mount_target" fstab_filename = self.disklogpath / 'fstab' if not fstab_filename.isfile(): msg = "couldn't find fstab at %s" % fstab_filename self.log.error(msg) raise RuntimeError, msg fstab_lines = [ line.split() for line in fstab_filename.open() if not line.startswith('#') ] #print fstab_lines # start mounting for line in fstab_lines: #print line device = line[0] mtpt = line[1] fstype = line[2] #print 'device, mtpt, fstype', device, mtpt, fstype if mtpt.startswith('/'): target_path = self.target / mtpt[1:] if not target_path.isdir(): target_path.mkdir() # in case we're mounting /tmp as tmpfs # or similar if fstype not in ['tmpfs']: cmd = ['mount', '-t', fstype, device, target_path] #print ' '.join(cmd) runlog(cmd) else: self.log.info('not mounting %s with %s fstype' % (mtpt, fstype))
def install_packages_for_extra_modules(self, modules): """Install the packages required to handle these modules.""" #cmd = self.chroot_precommand + self.aptinstall packages = [] for module in modules: if module == 'dm-mod': append_unique('lvm2', packages) append_unique('dmsetup', packages) if module.startswith('raid'): append_unique('mdadm', packages) #cmd += packages if packages: msg = "Installing these extra packages: %s" % ', '.join(packages) self.log.info(msg) apt_command = install_packages_command( packages, self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag='paella-kernel-extras') cmd = self.chroot_precommand + apt_command runlog(cmd) else: msg = 'No extra packages required for the kernel' self.log.info(msg)
def install_kernel_package(self): self.log.info('called install_kernel_package') kernel = self.machine.current.kernel cmd = self.chroot_precommand + self.aptinstall + [kernel] self.log.info('install cmd is: %s' % ' '.join(cmd)) kimgconf = self.target / 'etc' / 'kernel-img.conf' kimgconf_old = path('%s.paella-orig' % kimgconf) kimgconflines = ['do_bootloader = No', 'do_initrd = Yes', 'warn_initrd = No' ] if kimgconf.exists(): self.log.info('/etc/kernel-img.conf already exists') k = '/etc/kernel-img.conf' msg ='renaming %s to %s.paella-orig' % (k, k) self.log.info(msg) if kimgconf_old.exists(): raise RuntimeError, '%s already exists, aborting install.' % kimgconf_old os.rename(kimgconf, kimgconf_old) kimgconf.write_lines(kimgconflines) runlog(cmd) self.log.info('Kernel installation is complete.') if kimgconf_old.exists(): self.log.info('Restoring /etc/kernel-img.conf') os.remove(kimgconf) os.rename(kimgconf_old, kimgconf)
def _bootstrap_with_tarball(self, suite): self.check_target_exists() suite_path = path(self.defenv.get('installer', 'suite_storage')) arch = get_architecture() filename = '%s-%s.tar.gz' % (suite, arch) basefile = suite_path / filename taropts = '-xzf' # we normally expect a tar.gz # but we'll check for a plain tar also if not basefile.exists(): filename = '%s-%s.tar' % (suite, arch) basefile = suite_path / filename taropts = '-xf' if not basefile.exists(): # We don't really want to ruin an install # by not having a tarball, so we log a warning # and proceed with a debootstrap. msg = "base tarball not found, reverting to debootstrap" self.log.warn(msg) self._bootstrap_with_debootstrap(suite) else: #cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile) cmd = ['tar', '-C', str(self.target), taropts, str(basefile)] # if cmd returns nonzero, runlog will raise an error runlog(cmd)
def _bootstrap_with_debootstrap(self, suite): self.check_target_exists() mirror = self.defenv.get('installer', 'http_mirror') # debug stuff cmd = debootstrap(suite, self.target, mirror) # if cmd returns nonzero, runlog will raise an error runlog(cmd)
def install_kernel_package(self): self.log.info('called install_kernel_package') extra_modules = self.determine_extra_modules_from_diskconfig() if extra_modules: self.log.info('Checking if extra packages are required before kernel install.') self.install_packages_for_extra_modules(extra_modules) kernel = self.machine.get_kernel() cmd = self.chroot_precommand + self.aptinstall + [kernel] self.log.info('install cmd is: %s' % ' '.join(cmd)) kimgconf = self.target / 'etc' / 'kernel-img.conf' kimgconf_old = path('%s.paella-orig' % kimgconf) kimgconflines = ['do_bootloader = No', 'do_initrd = Yes', 'warn_initrd = No' ] if kimgconf.exists(): self.log.info('/etc/kernel-img.conf already exists') k = '/etc/kernel-img.conf' msg ='renaming %s to %s.paella-orig' % (k, k) self.log.info(msg) if kimgconf_old.exists(): raise RuntimeError , '%s already exists, aborting install.' % kimgconf_old os.rename(kimgconf, kimgconf_old) kimgconf.write_lines(kimgconflines) runlog(cmd) self.log.info('Kernel installation is complete.') if kimgconf_old.exists(): self.log.info('Restoring /etc/kernel-img.conf') os.remove(kimgconf) os.rename(kimgconf_old, kimgconf)
def _determine_disks_for_grub(self, bootdevice): if not bootdevice.startswith("/dev/md"): msg = "This method is only to be used when the " msg += "boot device is set to /dev/md*" self.log.error(msg) raise RuntimeError, msg device_map = self.target / "boot/grub/device.map" if not device_map.isfile(): # raise RuntimeError , 'We need the device.map from grub' cmd = self.chroot_precommand + ["grub-mkdevicemap", "-n"] runlog(cmd) self.log.info("device.map should be created now.") if not device_map.isfile(): msg = "Failed to make device.map" self.log.error(msg) raise RuntimeError, msg else: self.log.info("device.map has been found") lines = [line for line in file(device_map) if line.startswith("(hd0)")] if len(lines) != 1: msg = "Unable to find (hd0) in device.map" self.log.error(msg) raise RuntimeError, msg line = lines[0] grubdev, bootdevice = line.split() self.log.info("going to use %s as the boot device for grub" % bootdevice) return bootdevice
def update_initrd_with_extra_modules(self, modules): self.add_extra_modules_to_initrd(extra_modules) msg = 'adding these extra modules to initrd: %s' % ', '.join(extra_modules) self.log.info(msg) cmd = self.chroot_precommand + ['update-initramfs', '-u'] if 'DEBUG' in os.environ: cmd.append('-v') runlog(cmd)
def install_grub(self, device="/dev/hda", floppy=False): if not device.startswith("/dev"): device = "/dev/%s" % device opts = ["--recheck"] if not floppy: opts.append("--no-floppy") bin = "/usr/sbin/grub-install" runlog(self.chroot_precommand + [bin] + opts + [device])
def run_process_script(self, procname, script): if procname == 'chroot': retval = runlog(script) else: retval = runlog([script]) if retval: msg = "script for process %s exited with error code %d" % (procname, retval) raise RunLogError, msg
def install_grub(self, device='/dev/hda', floppy=False): if not device.startswith('/dev'): device = '/dev/%s' % device opts = ['--recheck'] if not floppy: opts.append('--no-floppy') bin = '/usr/sbin/grub-install' runlog(self.chroot_precommand + [bin] + opts + [device])
def update_initrd_with_extra_modules(self, modules): self.add_extra_modules_to_initrd(extra_modules) msg = "adding these extra modules to initrd: %s" % ", ".join(extra_modules) self.log.info(msg) cmd = self.chroot_precommand + ["update-initramfs", "-u"] if "DEBUG" in os.environ: cmd.append("-v") runlog(cmd)
def install_grub_package(self, grub='grub'): #cmd = self.chroot_precommand + self.aptinstall + [grub] apt_command = install_packages_command([grub], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag='paella-bootloader') cmd = self.chroot_precommand + apt_command runlog(cmd)
def update_initrd_with_extra_modules(self, modules): self.add_extra_modules_to_initrd(extra_modules) msg = 'adding these extra modules to initrd: %s' % ', '.join( extra_modules) self.log.info(msg) cmd = self.chroot_precommand + ['update-initramfs', '-u'] if 'DEBUG' in os.environ: cmd.append('-v') runlog(cmd)
def make_device_entries(self): "this is a default process" if self.defenv.is_it_true('installer', 'use_devices_tarball'): runlog('echo extracting devices tarball') self._extract_devices_tarball() else: runlog('echo using MAKEDEV to make generic devices') self.make_generic_devices() self.make_disk_devices()
def run_process_script(self, procname, script): if procname == 'chroot': retval = runlog(script) else: retval = runlog([script]) if retval: msg = "script for process %s exited with error code %d" % ( procname, retval) raise RunLogError, msg
def _mount_target_virtfs(self, fs): fstype = dict(proc='proc', sys='sysfs', devpts='devpts') target = self.target / fs if fs == 'devpts': target = self.target / 'dev' / 'pts' if not target.isdir(): target.mkdir() #cmd = 'mount -t %s none %s' % (fstype[fs], target) cmd = ['mount', '-t', fstype[fs], 'none', str(target)] runlog(cmd)
def install_grub(self, device='/dev/hda', floppy=False): if not device.startswith('/dev'): device = '/dev/%s' % device opts = ['--recheck'] if not floppy: opts.append('--no-floppy') if device.startswith('/dev/md'): self.log.warn('The boot device appears to be a raid array.') self.log.info('Trying to determine the mbr for installing grub') device = self._determine_disks_for_grub(device) bin = '/usr/sbin/grub-install' runlog(self.chroot_precommand + [bin] + opts + [device])
def install_grub(self, device="/dev/hda", floppy=False): if not device.startswith("/dev"): device = "/dev/%s" % device opts = ["--recheck"] if not floppy: opts.append("--no-floppy") if device.startswith("/dev/md"): self.log.warn("The boot device appears to be a raid array.") self.log.info("Trying to determine the mbr for installing grub") device = self._determine_disks_for_grub(device) bin = "/usr/sbin/grub-install" runlog(self.chroot_precommand + [bin] + opts + [device])
def install_packages_for_extra_modules(self, modules): """Install the packages required to handle these modules.""" cmd = self.chroot_precommand + self.aptinstall packages = [] for module in modules: if module == 'dm-mod': append_unique('lvm2', packages) append_unique('dmsetup', packages) if module.startswith('raid'): append_unique('mdadm', packages) msg = "Installing these extra packages: %s" % ', '.join(packages) self.log.info(msg) cmd += packages runlog(cmd)
def _bootstrap_with_tarball(self, suite): suite_path = path(self.defenv.get('installer', 'suite_storage')) filename = '%s.tar.gz' % suite basefile = suite_path / filename taropts = '-xzf' if not basefile.exists(): filename = '%s.tar' % suite basefile = suite_path / filename taropts = '-xf' cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile) # if cmd returns nonzero, runlog will raise an error runlog(cmd) # we need to do certain things here that debootstrap # does for us, like copy /etc/resolv.conf self._bootstrapped = True
def chroot(self, command, failure_suppressed=False): # we need to remove this if/else when we're sure # we don't need it anymore if type(command) is list: cmd = ["chroot", str(self.target)] + command else: cmd = "chroot %s %s" % (self.target, command) return runlog(cmd, failure_suppressed=failure_suppressed)
def _umount_target_virtfs(self, fs): # work around binfmt-support /proc locking # found this idea while messing around in live-helper target = self.target / fs if fs == 'proc': binfmt_misc = self.target / 'proc/sys/fs/binfmt_misc' status = binfmt_misc / 'status' if status.exists(): self.log.info('Unmounting /proc/sys/fs/binfmt_misc in chroot') #cmd = 'umount %s' % binfmt cmd = ['umount', str(binfmt_misc)] runlog(cmd) if fs == 'devpts': target = self.target / 'dev' / 'pts' #cmd = 'umount %s' % target cmd = ['umount', str(target)] runlog(cmd)
def chroot(self, command, failure_suppressed=False): # we need to remove this if/else when we're sure # we don't need it anymore if type(command) is list: cmd = ['chroot', str(self.target)] + command else: cmd = 'chroot %s %s' % (self.target, command) return runlog(cmd, failure_suppressed=failure_suppressed)
def install_kernel_package(self): self.log.info('called install_kernel_package') extra_modules = self.determine_extra_modules_from_diskconfig() if extra_modules: self.log.info( 'Checking if extra packages are required before kernel install.' ) self.install_packages_for_extra_modules(extra_modules) else: msg = "There doesn't seem to be a need for extra modules on this machine." self.log.info(msg) kernel = self.machine.get_kernel() if kernel == 'default': self.log.info("Using default kernel") kernel = self._determine_default_kernel() self.log.info("Default kernel for this machine is %s" % kernel) #cmd = self.chroot_precommand + self.aptinstall + [kernel] apt_command = install_packages_command([kernel], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag='paella-kernel') cmd = self.chroot_precommand + apt_command self.log.info('install cmd is: %s' % ' '.join(cmd)) kimgconf = self.target / 'etc' / 'kernel-img.conf' kimgconf_old = path('%s.paella-orig' % kimgconf) kimgconflines = [ 'do_bootloader = No', 'do_initrd = Yes', 'warn_initrd = No' ] if kimgconf.exists(): self.log.info('/etc/kernel-img.conf already exists') k = '/etc/kernel-img.conf' msg = 'renaming %s to %s.paella-orig' % (k, k) self.log.info(msg) if kimgconf_old.exists(): msg = '%s already exists, aborting install.' % kimgconf_old self.log.error(msg) raise RuntimeError, msg os.rename(kimgconf, kimgconf_old) kimgconf.write_lines(kimgconflines) runlog(cmd) self.log.info('Kernel installation is complete.') if kimgconf_old.exists(): self.log.info('Restoring /etc/kernel-img.conf') os.remove(kimgconf) os.rename(kimgconf_old, kimgconf)
def debootstrap_target(self): suite = self.installer.suite debmirror = self.installer.debmirror cmd = debootstrap(suite, self.target, debmirror) info = self.installer.log.info info('running debootstrap with cmd %s' % cmd) runvalue = runlog(debootstrap(self.installer.suite, self.target, self.installer.debmirror)) if runvalue: raise InstallError, 'problems bootstrapping with %s' % cmd
def _setup_storage_fai(self): diskconfig = self.machine.get_diskconfig_content() self.diskconfig = diskconfig # FIXME: disklist is hardcoded here disklist = None if disklist is None: disklist = [] cmd = ['/usr/lib/fai/disk-info'] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) retval = proc.wait() if retval: raise RuntimeError, 'disk-info returned %d' % retval for line in proc.stdout: disklist.append(line.split()[0]) print disklist #os.environ['DEBUG'] = 'true' cmd = setup_storage_fai(disklist, diskconfig, self.disklogpath) runlog(cmd) print "done", self.disklogpath
def unmount_device(self, device): # mounted = os.system('umount %s' % device) # this is how the command should look # mounted = runlog(['umount', device]) # LOOK FOR WHERE THIS IS CALLED # why assign the return to mounted if I wasn't going # to return it? # passing str to runlog to find where this # is called. mounted = runlog("umount %s" % device)
def unmount_device(self, device): #mounted = os.system('umount %s' % device) # this is how the command should look #mounted = runlog(['umount', device]) # LOOK FOR WHERE THIS IS CALLED # why assign the return to mounted if I wasn't going # to return it? # passing str to runlog to find where this # is called. mounted = runlog('umount %s' % device)
def install_kernel_package(self): self.log.info('called install_kernel_package') extra_modules = self.determine_extra_modules_from_diskconfig() if extra_modules: self.log.info('Checking if extra packages are required before kernel install.') self.install_packages_for_extra_modules(extra_modules) else: msg = "There doesn't seem to be a need for extra modules on this machine." self.log.info(msg) kernel = self.machine.get_kernel() if kernel == 'default': self.log.info("Using default kernel") kernel = self._determine_default_kernel() self.log.info("Default kernel for this machine is %s" % kernel) #cmd = self.chroot_precommand + self.aptinstall + [kernel] apt_command = install_packages_command([kernel], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag='paella-kernel') cmd = self.chroot_precommand + apt_command self.log.info('install cmd is: %s' % ' '.join(cmd)) kimgconf = self.target / 'etc' / 'kernel-img.conf' kimgconf_old = path('%s.paella-orig' % kimgconf) kimgconflines = ['do_bootloader = No', 'do_initrd = Yes', 'warn_initrd = No' ] if kimgconf.exists(): self.log.info('/etc/kernel-img.conf already exists') k = '/etc/kernel-img.conf' msg ='renaming %s to %s.paella-orig' % (k, k) self.log.info(msg) if kimgconf_old.exists(): msg = '%s already exists, aborting install.' % kimgconf_old self.log.error(msg) raise RuntimeError , msg os.rename(kimgconf, kimgconf_old) kimgconf.write_lines(kimgconflines) runlog(cmd) self.log.info('Kernel installation is complete.') if kimgconf_old.exists(): self.log.info('Restoring /etc/kernel-img.conf') os.remove(kimgconf) os.rename(kimgconf_old, kimgconf)
def _setup_storage_fai(self): diskconfig = self.machine.get_diskconfig_content() self.diskconfig = diskconfig # FIXME: disklist is hardcoded here disklist = None if disklist is None: disklist = [] cmd = ['/usr/lib/fai/disk-info'] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) retval = proc.wait() if retval: raise RuntimeError , 'disk-info returned %d' % retval for line in proc.stdout: disklist.append(line.split()[0]) print disklist #os.environ['DEBUG'] = 'true' cmd = setup_storage_fai(disklist, diskconfig, self.disklogpath) runlog(cmd) print "done", self.disklogpath
def debootstrap_target(self): suite = self.installer.suite debmirror = self.installer.debmirror cmd = debootstrap(suite, self.target, debmirror) info = self.installer.log.info info('running debootstrap with cmd %s' % cmd) runvalue = runlog( debootstrap(self.installer.suite, self.target, self.installer.debmirror)) if runvalue: raise InstallError, 'problems bootstrapping with %s' % cmd
def _umount_target_virtfs(self, fs): self.log.info('running umount for %s' % fs) # work around binfmt-support /proc locking # found this idea while messing around in live-helper target = self.target / fs if fs == 'proc': binfmt_misc = self.target / 'proc/sys/fs/binfmt_misc' status = binfmt_misc / 'status' if status.exists(): self.log.info('Unmounting /proc/sys/fs/binfmt_misc in chroot') #cmd = 'umount %s' % binfmt cmd = ['umount', str(binfmt_misc)] runlog(cmd) # hack to stop mdadm on target mdstat = self.target / 'proc/mdstat' if mdstat.isfile(): mdadm_initscript = self.target / 'etc/init.d/mdadm' if mdadm_initscript.isfile(): self.log.info("Stopping mdadm from running on target.") cmd = ['chroot', self.target, '/etc/init.d/mdadm', 'stop'] runlog(cmd) if fs == 'devpts': target = self.target / 'dev' / 'pts' #cmd = 'umount %s' % target cmd = ['umount', str(target)] runlog(cmd)
def install_kernel_package(self): self.log.info("called install_kernel_package") extra_modules = self.determine_extra_modules_from_diskconfig() if extra_modules: self.log.info("Checking if extra packages are required before kernel install.") self.install_packages_for_extra_modules(extra_modules) else: msg = "There doesn't seem to be a need for extra modules on this machine." self.log.info(msg) kernel = self.machine.get_kernel() if kernel == "default": self.log.info("Using default kernel") kernel = self._determine_default_kernel() self.log.info("Default kernel for this machine is %s" % kernel) # cmd = self.chroot_precommand + self.aptinstall + [kernel] apt_command = install_packages_command( [kernel], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag="paella-kernel" ) cmd = self.chroot_precommand + apt_command self.log.info("install cmd is: %s" % " ".join(cmd)) kimgconf = self.target / "etc" / "kernel-img.conf" kimgconf_old = path("%s.paella-orig" % kimgconf) kimgconflines = ["do_bootloader = No", "do_initrd = Yes", "warn_initrd = No"] if kimgconf.exists(): self.log.info("/etc/kernel-img.conf already exists") k = "/etc/kernel-img.conf" msg = "renaming %s to %s.paella-orig" % (k, k) self.log.info(msg) if kimgconf_old.exists(): msg = "%s already exists, aborting install." % kimgconf_old self.log.error(msg) raise RuntimeError, msg os.rename(kimgconf, kimgconf_old) kimgconf.write_lines(kimgconflines) runlog(cmd) self.log.info("Kernel installation is complete.") if kimgconf_old.exists(): self.log.info("Restoring /etc/kernel-img.conf") os.remove(kimgconf) os.rename(kimgconf_old, kimgconf)
def install_packages_for_extra_modules(self, modules): """Install the packages required to handle these modules.""" # cmd = self.chroot_precommand + self.aptinstall packages = [] for module in modules: if module == "dm-mod": append_unique("lvm2", packages) append_unique("dmsetup", packages) if module.startswith("raid"): append_unique("mdadm", packages) # cmd += packages if packages: msg = "Installing these extra packages: %s" % ", ".join(packages) self.log.info(msg) apt_command = install_packages_command( packages, self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag="paella-kernel-extras" ) cmd = self.chroot_precommand + apt_command runlog(cmd) else: msg = "No extra packages required for the kernel" self.log.info(msg)
def ready_base_for_install(self): self._check_bootstrap() fstab = '#unconfigured for chroot install\n' ready_base_for_install(self.target, self.conn, self.suite, fstab) self._mount_target_proc() self._check_target_proc() cmd = self.command('apt-get', '-y update', chroot=True) runvalue = runlog(cmd) if runvalue: raise InstallError, 'problem updating the apt lists.' if os.environ.has_key('FAKE_START_STOP_DAEMON'): make_fake_start_stop_daemon(self.target) self._base_ready = True
def install_packages_for_extra_modules(self, modules): """Install the packages required to handle these modules.""" #cmd = self.chroot_precommand + self.aptinstall packages = [] for module in modules: if module == 'dm-mod': append_unique('lvm2', packages) append_unique('dmsetup', packages) if module.startswith('raid'): append_unique('mdadm', packages) #cmd += packages if packages: msg = "Installing these extra packages: %s" % ', '.join(packages) self.log.info(msg) apt_command = install_packages_command(packages, self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag='paella-kernel-extras') cmd = self.chroot_precommand + apt_command runlog(cmd) else: msg = 'No extra packages required for the kernel' self.log.info(msg)
def install_kernel_package(self): self.log.info("called install_kernel_package") kernel = self.machine.current.kernel cmd = self.chroot_precommand + self.aptinstall + [kernel] self.log.info("install cmd is: %s" % " ".join(cmd)) kimgconf = self.target / "etc" / "kernel-img.conf" kimgconf_old = path("%s.paella-orig" % kimgconf) kimgconflines = ["do_bootloader = No", "do_initrd = Yes", "warn_initrd = No"] if kimgconf.exists(): self.log.info("/etc/kernel-img.conf already exists") k = "/etc/kernel-img.conf" msg = "renaming %s to %s.paella-orig" % (k, k) self.log.info(msg) if kimgconf_old.exists(): raise RuntimeError, "%s already exists, aborting install." % kimgconf_old os.rename(kimgconf, kimgconf_old) kimgconf.write_lines(kimgconflines) runlog(cmd) self.log.info("Kernel installation is complete.") if kimgconf_old.exists(): self.log.info("Restoring /etc/kernel-img.conf") os.remove(kimgconf) os.rename(kimgconf_old, kimgconf)
def umount_dev(self): umount_devpts = ["umount", "/dev/pts"] runlog(self.chroot_precommand + umount_devpts) umount_cmd = ["umount", self.targetdev] try: runlog(umount_cmd) except RunLogError: self.log.error("There was a problem with unmounting /dev in target") self.log.info("attempting to do a lazy umount") umount_cmd = ["umount", "-l", self.targetdev] runlog(umount_cmd)
def umount_dev(self): umount_devpts = ['umount', '/dev/pts'] runlog(self.chroot_precommand + umount_devpts) umount_cmd = ['umount', self.targetdev] try: runlog(umount_cmd) except RunLogError: self.log.error( "There was a problem with unmounting /dev in target") self.log.info("attempting to do a lazy umount") umount_cmd = ['umount', '-l', self.targetdev] runlog(umount_cmd)
def set_debconf_selections(self, template): trait = self.trait self.log.info('Setting debconf selections for trait %s' % trait) self.traittemplate.set_template(template.template) tmpl = self.traittemplate.template.template self._update_templatedata() sub = self.traittemplate.template.sub() if tmpl == sub: msg = "static debconf selections, no substitutions for trait %s" % trait else: msg = "debconf selections contain substitutions for trait %s" % trait self.log.info(msg) config_path = self.target / 'root/paella_debconf' self._check_debconf_destroyed(config_path) config_path.write_text(sub + '\n') cmd = [ 'chroot', self.target, 'debconf-set-selections', '-v', '/root/paella_debconf' ] try: retval = runlog(cmd) except RunLogError: self.log.info('there was a problem with debconf-set-selections') self.log.info('command was %s' % ' '.join(cmd)) # make sure that we raise an error if this is not the # first run of debconf-set-selections if self.debconf_problem: msg = "We already had a problem with set_debconf_selections" self.log.error(msg) raise RuntimeError, msg self.debconf_problem = True # we're going to keep these files # instead of rm'ing them, until I feel # better about this code. Besides, the # format of the files has to be just so # or debconf has problems, so this is a # good way to figure out what happened. if False: os.remove(config_path) self._check_debconf_destroyed(config_path) os.rename(config_path, '%s-%s' % (config_path, trait))
def update_grub(self): runlog(self.chroot_precommand + ['update-grub'])
def install_grub_package(self, grub='grub'): cmd = self.chroot_precommand + self.aptinstall + [grub] runlog(cmd)
def umount_dev(self): umount_devpts = ['umount', '/dev/pts'] runlog(self.chroot_precommand + umount_devpts) umount_cmd = ['umount', self.targetdev] runlog(umount_cmd)
def bind_mount_dev(self): mount_cmd = ['mount', '-o', 'bind', '/dev', self.targetdev] mount_devpts = ['mount', '-t', 'devpts', 'devpts', '/dev/pts'] runlog(mount_cmd) runlog(self.chroot_precommand + mount_devpts)