def ready_target(self): self._check_target() makepaths(self.target) device = self.machine.array_hack(self.machine.current.machine_type) clause = Eq("filesystem", self.machine.current.filesystem) clause &= Gt("partition", "0") table = "filesystem_mounts natural join mounts" mounts = self.cursor.select(table=table, clause=clause, order="mnt_point") if mounts[0].mnt_point != "/": raise Error, "bad set of mounts", mounts mddev = False mdnum = 0 if device == "/dev/md": mddev = True pdev = "/dev/md0" mdnum += 1 else: pdev = self._pdev(device, mounts[0].partition) print "mounting target", pdev, self.target clause &= Neq("mnt_point", "/") mounts = self.cursor.select(table=table, clause=clause, order="ord") runlog("mount %s %s" % (pdev, self.target)) for mnt in mounts: tpath = os.path.join(self.target, mnt.mnt_point[1:]) makepaths(tpath) if mddev: pdev = "/dev/md%d" % mdnum else: pdev = self._pdev(device, mnt.partition) mdnum += 1 runlog("mount %s %s" % (pdev, tpath)) self._mounted = True
def ready_target(self): self._check_target() makepaths(self.target) device = self.machine.array_hack(self.machine.current.machine_type) clause = Eq('filesystem', self.machine.current.filesystem) clause &= Gt('partition', '0') table = 'filesystem_mounts natural join mounts' mounts = self.cursor.select(table=table, clause=clause, order='mnt_point') if mounts[0].mnt_point != '/': raise Error, 'bad set of mounts', mounts mddev = False mdnum = 0 if device == '/dev/md': mddev = True pdev = '/dev/md0' mdnum += 1 else: pdev = self._pdev(device, mounts[0].partition) print 'mounting target', pdev, self.target clause &= Neq('mnt_point', '/') mounts = self.cursor.select(table=table, clause=clause, order='ord') runlog('mount %s %s' % (pdev, self.target)) for mnt in mounts: tpath = os.path.join(self.target, mnt.mnt_point[1:]) makepaths(tpath) if mddev: pdev = '/dev/md%d' % mdnum else: pdev = self._pdev(device, mnt.partition) mdnum += 1 runlog('mount %s %s' % (pdev, tpath)) self._mounted = True
def make_filesystem(device, fstype): if fstype == 'reiserfs': cmd = 'mkreiserfs -f -q %s' % device elif fstype == 'ext3': cmd = 'mkfs.ext3 -F -q %s' % device elif fstype == 'ext2': cmd = 'mkfs.ext2 -F -q %s' % device else: raise Error, 'unhandled fstype %s ' % fstype echo(cmd) runlog(cmd, keeprunning=True)
def extract_tarball(target, tarball): here = os.getcwd() print 'extracting with tar' os.chdir(target) if tarball[-2:] == 'gz': opts = 'xzf' elif tarball[-3:] == 'bz2': opts = 'xjf' else: opts = 'xf' runlog('tar %s %s' % (opts, tarball)) os.chdir(here)
def run(self, name, command, args='', proc=False, destroylog=False, chroot=True, keeprunning=False): if not chroot and proc: raise Error, 'bad options, cannot mount proc with no_chroot' if proc: cmd = self.with_proc(command, args=args) else: cmd = self.command(command, args=args, chroot=chroot) runvalue = runlog(cmd, destroylog=destroylog, keeprunning=keeprunning)
def ready_target(self): self._check_target() makepaths(self.target) device = self.machine.array_hack(self.machine.current.machine_type) clause = Eq('filesystem', self.machine.current.filesystem) clause &= Gt('partition', '0') table = 'filesystem_mounts natural join mounts' mounts = self.cursor.select(table=table, clause=clause, order='mnt_point') if mounts[0].mnt_point != '/': raise Error, 'bad set of mounts', mounts pdev = self._pdev(device, mounts[0].partition) print 'mounting target', pdev, self.target runlog('mount %s %s' % (pdev, self.target)) for mnt in mounts[1:]: tpath = os.path.join(self.target, mnt.mnt_point[1:]) makepaths(tpath) pdev = self._pdev(device, mnt.partition) runlog('mount %s %s' % (pdev, tpath)) self._mounted = True
def install_kernel(package, target): script = "#!/bin/bash\n" script += 'umount /proc\n' script += 'umount /proc\n' script += 'mount -t proc proc /proc\n' script += 'touch /boot/vmlinuz-fake\n' script += 'ln -s boot/vmlinuz-fake vmlinuz\n' script += 'apt-get -y install %s\n' % package script += 'echo "kernel %s installed"\n' % package script += 'umount /proc\n' script += '\n' sname = 'install_kernel.sh' full_path = os.path.join(target, sname) sfile = file(full_path, 'w') sfile.write(script) sfile.close() runlog('chmod a+x %s' % full_path) runlog('chroot %s ./%s' % (target, sname)) os.remove(full_path)
def run(self, name, command, args='', proc=False, destroylog=False, chroot=True, keeprunning=False): if not chroot and proc: raise Error, 'bad options, cannot mount proc with no_chroot' if proc: cmd = self.with_proc(command, args=args) else: cmd = self.command(command, args=args, chroot=chroot) runvalue = runlog(cmd, destroylog=destroylog, keeprunning=keeprunning) return runvalue
def bootstrap_target(self): self._check_mounted() self._check_installer() runlog(debootstrap(self.suite, self.target, self.debmirror)) self._bootstrapped = True
def remove_debs(target): archives = 'var/cache/apt/archives' debs = os.path.join(target, archives, '*.deb') pdebs = os.path.join(target, archives, 'partial', '*.deb') runlog('rm %s %s -f' % (debs, pdebs))