Example #1
0
def makedev(target, devices=['generic']):
    here = os.getcwd()
    os.chdir(join(target, 'dev'))
    for dev in devices:
        echo('making device %s with MAKEDEV' % dev)
        runlog('./MAKEDEV %s' % dev)
    os.chdir(here)
Example #2
0
def extract_tarball(target, tarball):
    "this is used by the uml installer"
    opts = '-xf'
    if tarball[-7:] == '.tar.gz' or tarball[-4:] == '.tgz':
        opts = '-xzf'
    elif tarball[-8:] == '.tar.bz2':
        opts = '-xjf'
    #cmd = 'tar -C %s %s %s' % (target, opts, tarball)
    cmd = ['tar', '-C', str(target), opts, str(tarball)]
    #echo('extracting tarball with command %s' % cmd)
    runlog(['echo', 'extracting tarball with command', ' '.join(cmd)])
    return runlog(cmd)
Example #3
0
def make_filesystem(device, fstype):
    "this function is used by the uml installer"
    if fstype == 'reiserfs':
        cmd = ['mkreiserfs',  '-f',  '-q',  device]
    elif fstype == 'ext3':
        cmd = ['mkfs.ext3',  '-F',  '-q', device]
    elif fstype == 'ext2':
        cmd = ['mkfs.ext2',  '-F',  '-q', device]
    else:
        raise RuntimeError ,  'unhandled fstype %s '  % fstype
    runlog(['echo',  'make_filesystem',  'command'] + cmd)
    return runlog(cmd)
def mount_target(target, mounts, device):
    mounts = [m for m in mounts if int(m.partition)]
    if mounts[0].mnt_point != '/':
        raise RuntimeError, 'bad set of mounts', mounts
    mddev = False
    mdnum = 0
    if device == '/dev/md':
        mddev = True
        pdev = '/dev/md0'
        mdnum += 1
    else:
        pdev = '%s%d' % (device, mounts[0].partition)
    runlog('echo mounting target %s to %s' % (pdev, target))
    runlog('mount %s %s' % (pdev, target))
    mounts = mounts[1:]
    mountable = [m for m in mounts if m.fstype != 'swap']
    for mnt in mountable:
        tpath = os.path.join(target, mnt.mnt_point[1:])
        makepaths(tpath)
        if mddev:
            pdev = '/dev/md%d' % mdnum
        else:
            pdev = '%s%d' % (device, mnt.partition)
        mdnum += 1
        runlog('echo mounting target %s to %s' % (pdev, tpath))
        runlog('mount %s %s' % (pdev, tpath))
Example #5
0
def create_raid_partition(devices, pnum, mdnum, raidlevel=1):
    opts = '--create /dev/md%d' % mdnum
    opts = '%s --force -l%d -n%d' % (opts, raidlevel, len(devices))
    devices = ['%s%d' % (device, pnum) for device in devices]
    cmd = 'mdadm %s %s' % (opts, ' '.join(devices))
    yes = 'bash -c "yes | %s"' % cmd
    return runlog(yes)
Example #6
0
def extract_tarball(target, tarball):
    opts = "-xf"
    if tarball[-7:] == ".tar.gz" or tarball[-4:] == ".tgz":
        opts = "-xzf"
    elif tarball[-8:] == ".tar.bz2":
        opts = "-xjf"
    cmd = "tar -C %s %s %s" % (target, opts, tarball)
    echo("extracting tarball with command %s" % cmd)
    return runlog(cmd)
Example #7
0
def extract_tarball(target, tarball):
    opts = '-xf'
    if tarball[-7:] == '.tar.gz' or tarball[-4:] == '.tgz':
        opts = '-xzf'
    elif tarball[-8:] == '.tar.bz2':
        opts = '-xjf'
    cmd = 'tar -C %s %s %s' % (target, opts, tarball)
    echo('extracting tarball with command %s' % cmd)
    return runlog(cmd)
Example #8
0
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 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 RuntimeError,  'unhandled fstype %s '  % fstype
    echo(cmd)
    return runlog(cmd)
Example #10
0
def make_filesystems(device, fsmounts, env):
    mddev = False
    if device == '/dev/md':
        mdnum = 0
        mddev = True
    for row in fsmounts:
        if mddev:
            pdev = '/dev/md%d' % mdnum
            mdnum += 1
        else:
            pdev = device + str(row.partition)
        if row.mnt_name in env.keys():
            echo('%s held' % row.mnt_name)
        elif row.fstype == 'swap':
            runlog('echo making swap on %s' % pdev)
            runvalue = runlog('mkswap %s' % pdev)
            if runvalue:
                raise RuntimeError, 'problem making swap on %s' % pdev
        else:
            echo('making filesystem for %s' % row.mnt_name)
            make_filesystem(pdev, row.fstype)
Example #11
0
def setup_disk_fai(disk_config, logpath,
                   script='/usr/lib/paella/scripts/setup_harddisks_fai'):
    fileid, disk_config_path = tempfile.mkstemp('paella', 'diskinfo')
    disk_config_file = file(disk_config_path, 'w')
    disk_config_file.write(disk_config)
    disk_config_file.close()
    options = '-X -f %s' % disk_config_path
    env = 'env LOGDIR=%s diskvar=%s' % (logpath, os.path.join(logpath, 'diskvar'))

    # use this to keep script running on machines
    # that don't reread the partition table properly
    os.environ['sfdisk'] = '--no-reread'
    
    command = '%s %s %s' % (env, script, options)
    return runlog(command)
Example #12
0
def remove_debs(target):
    archives = "var/cache/apt/archives"
    debs = os.path.join(target, archives, "*.deb")
    pdebs = os.path.join(target, archives, "partial", "*.deb")
    return runlog("rm %s %s -f" % (debs, pdebs))
Example #13
0
def remove_debs(target):
    archives = 'var/cache/apt/archives'
    debs = os.path.join(target, archives, '*.deb')
    pdebs = os.path.join(target, archives, 'partial', '*.deb')
    return runlog('rm %s %s -f' % (debs, pdebs))
Example #14
0
def mount_target_proc(target, umount=False):
    tproc = os.path.join(target, 'proc')
    cmd = 'mount --bind /proc %s' % tproc
    if umount:
        cmd = 'umount -l %s' % tproc
    return runlog(cmd)
Example #15
0
def mount_tmpfs(target='/tmp'):
    #os.system('mount -t tmpfs tmpfs %s' % target)
    cmd = ['mount', '-t', 'tmpfs', 'tmpfs', str(target)]
    runlog(cmd)