Пример #1
0
 def mount_each(tgt_root_dev, tgt_other_dev, tgt_other_type, tgt_other_mpoint):
     if tgt_other_dev and tgt_root_dev != tgt_other_dev:
         mnt_point = os.path.join(CF.D.TGTSYS_ROOT, tgt_other_mpoint.lstrip('/'))
         dev_tgt_other = MiDevice(tgt_other_dev, tgt_other_type, mnt_point)
         
         if not dev_tgt_other.do_mount(): #### NOTE: carefully handle this device's mount.
             logger.e('Mount device %s Failed, install operate can not continue' % dev_tgt_other.get_dev())
             self.umount_tgt_device()
             return False
         else:
             self.mounted_devs.append(dev_tgt_other)
         return True
     else:
         logger.e('Can not run to here!! The root file system had been mounted before!!')
         return False
Пример #2
0
def win_probe(mia, operid, hdpartlist):
    mia.set_step(operid, 0, -1)
    result = []
    all_drives = hdpartlist
    for (device, fstype, new_device) in all_drives:
        dolog('Search %s for Windows files\n' % device)
        if fstype not in CF.D.FSTYPE_MAP or \
               CF.D.FSTYPE_MAP[fstype][0] not in ('vfat', 'ntfs', 'ntfs-3g'):
            continue
        dev = MiDevice(device, fstype)
        notfind = True
        for absolute_path, reltive_dir in dev.iter_searchfiles(['bootmgr', 'ntldr', 'io.sys'], ['']):
            if os.path.basename(absolute_path) == 'bootmgr':
                result.append((new_device, 'vista/7'))
            elif os.path.basename(absolute_path) == 'ntldr':
                result.append((new_device, 'winnt'))
            elif os.path.basename(absolute_path) == 'io.sys':
                result.append((new_device, 'win98'))
            notfind = False
            
        if notfind:
            result.append((new_device, 'win'))
    return result
Пример #3
0
def win_probe(mia, operid, hdpartlist):
    mia.set_step(operid, 0, -1)
    result = []
    all_drives = hdpartlist
    for (device, fstype, new_device) in all_drives:
        dolog('Search %s for Windows files\n' % device)
        if fstype not in CF.D.FSTYPE_MAP or \
               CF.D.FSTYPE_MAP[fstype][0] not in ('vfat', 'ntfs', 'ntfs-3g'):
            continue
        dev = MiDevice(device, fstype)
        notfind = True
        for absolute_path, reltive_dir in dev.iter_searchfiles(
            ['bootmgr', 'ntldr', 'io.sys'], ['']):
            if os.path.basename(absolute_path) == 'bootmgr':
                result.append((new_device, 'vista/7'))
            elif os.path.basename(absolute_path) == 'ntldr':
                result.append((new_device, 'winnt'))
            elif os.path.basename(absolute_path) == 'io.sys':
                result.append((new_device, 'win98'))
            notfind = False

        if notfind:
            result.append((new_device, 'win'))
    return result
Пример #4
0
def probe_all_disc(mia, operid, device, devfstype, bootiso_relpath, pkgarr_reldir, disc_first_pkgs):
    '''
        probe the package from all disk
        bootiso_relpath is the first iso path relative path of device /
        pkgarr_reldir is the relative directory path of pkgarr.py of device / OR iso dir /
    '''
    logger.i('probe_all_disc(%s, %s, %s, %s, %s)\n' % \
          (device, devfstype, bootiso_relpath, pkgarr_reldir, disc_first_pkgs))
    
    midev = MiDevice(device, devfstype)
    bootiso_fn = CF.D.ISOFN_FMT % (CF.D.DISTNAME, CF.D.DISTVER, 1)
    # If probe in iso ,but bootiso_fn is not match error occur
    if bootiso_relpath and not os.path.basename(bootiso_relpath) == bootiso_fn:
        logger.e('probe_all_disc iso format is wrong: bootiso_relpath: %s bootiso_fn: %s' % (bootiso_relpath, bootiso_fn))
        return None
    probe_ret = None
    result = []
    for disc_no in range(len(disc_first_pkgs)):
        pkg_probe_path = [  '../packages',
                            'packages',
                            '../packages-%d' % (disc_no + 1),
                            'packages-%d' % (disc_no + 1)]
        if bootiso_relpath:
            # deal with iso case
            iso_fn = CF.D.ISOFN_FMT % (CF.D.DISTNAME, CF.D.DISTVER, disc_no + 1)
            iso_relpath = os.path.join(os.path.dirname(bootiso_relpath), iso_fn)
            pkgarr_reldirs = [ os.path.join(pkgarr_reldir, p) for p in pkg_probe_path ]
            for f, reldir in midev.iter_searchfiles([iso_relpath], ['']): # from disk
                midev_iso = MiDevice(f, 'iso9660')
                for pkgpath, relative_dir in midev_iso.iter_searchfiles([disc_first_pkgs[disc_no]], pkgarr_reldirs): # from iso
                    probe_ret = ( os.path.join(os.path.dirname(bootiso_relpath), iso_fn), 
                        os.path.normpath(os.path.join(relative_dir, pkgpath)) )
        else:
            # deal with harddisk case
            pkgs = [ os.path.join(p, disc_first_pkgs[disc_no]) for p in pkg_probe_path ]
            for f, reldir in midev.iter_searchfiles(pkgs, [pkgarr_reldir]):
                probe_ret = ('', os.path.normpath(os.path.join(reldir, f)))
        if probe_ret:
            result.append(probe_ret)

    dolog('probe_all_disc return result is : %s\n' % str(result))
    return  result
Пример #5
0
    cdrom_dev = getdev.get_dev_info(getdev.CLASS_CDROM)
    for k, v in cdrom_dev.items():
        v['fstype'] = 'iso9660'  # fill cdrom file type, because it is None for default.

    all_drives.update(all_parts)
    all_drives.update(cdrom_dev)
    logger.i('all_drives: %s' % all_drives)
    pos_id = -1
    for k, value in all_drives.items():
        devpath = value['devpath']
        fstype = value['fstype']
        if not CF.D.FSTYPE_MAP.has_key(fstype):
            continue
        if CF.D.FSTYPE_MAP[fstype][0] == '':
            continue
        midev = MiDevice(devpath, CF.D.FSTYPE_MAP[fstype][0])
        logger.d('Search %s pkgarr(%s) in dirs %s' %
                 (CF.D.BOOTCDFN, CF.D.PKGARR_FILE,
                  repr(CF.D.PKGARR_SER_HDPATH + CF.D.PKGARR_SER_CDPATH)))
        for f, reldir in midev.iter_searchfiles(
            [CF.D.PKGARR_FILE, CF.D.BOOTCDFN],
                CF.D.PKGARR_SER_HDPATH + CF.D.PKGARR_SER_CDPATH):
            if f.endswith('.iso'):
                midev_iso = MiDevice(f, 'iso9660')
                for pkgarr, relative_dir in midev_iso.iter_searchfiles(
                    [CF.D.PKGARR_FILE], CF.D.PKGARR_SER_CDPATH):
                    pos_id += 1
                    r = probe_position(pkgarr, 100 + pos_id, devpath,
                                       CF.D.FSTYPE_MAP[fstype][0],
                                       relative_dir, CF.D.BOOTCDFN)
                    if r:
Пример #6
0
 cdrom_dev = getdev.get_dev_info(getdev.CLASS_CDROM)
 for k, v in cdrom_dev.items():
     v['fstype'] = 'iso9660'   # fill cdrom file type, because it is None for default.
 
 all_drives.update(all_parts)
 all_drives.update(cdrom_dev)
 logger.i('all_drives: %s' % all_drives)
 pos_id = -1
 for k, value in all_drives.items():
     devpath = value['devpath']
     fstype = value['fstype']
     if not CF.D.FSTYPE_MAP.has_key(fstype):
         continue
     if CF.D.FSTYPE_MAP[fstype][0] == '':
         continue
     midev = MiDevice(devpath, CF.D.FSTYPE_MAP[fstype][0])
     logger.d('Search %s pkgarr(%s) in dirs %s' % (CF.D.BOOTCDFN, CF.D.PKGARR_FILE, repr(CF.D.PKGARR_SER_HDPATH+CF.D.PKGARR_SER_CDPATH)))
     for f, reldir in midev.iter_searchfiles([CF.D.PKGARR_FILE, CF.D.BOOTCDFN], CF.D.PKGARR_SER_HDPATH+CF.D.PKGARR_SER_CDPATH):
         if f.endswith('.iso'):
             midev_iso = MiDevice(f, 'iso9660')
             for pkgarr, relative_dir in midev_iso.iter_searchfiles([CF.D.PKGARR_FILE], CF.D.PKGARR_SER_CDPATH):
                 pos_id += 1
                 r = probe_position(pkgarr, 100 + pos_id,
                     devpath, CF.D.FSTYPE_MAP[fstype][0], relative_dir, CF.D.BOOTCDFN)
                 if r:
                     r[-1] = os.path.join(reldir, r[-1]) #### revise iso relative path
                     result.append(r)
         else:
             pos_id += 1
             r = probe_position(f, pos_id,
                 devpath, fstype, reldir, '')
Пример #7
0
    def mount_tgt_device(self):
        tgt_root_dev, tgt_root_type = self.get_devinfo_by_mpoint('/')
        
        tgt_swap_dev, tgt_swap_type = self.get_devinfo_by_mpoint('USE')
        if tgt_swap_dev and os.path.exists(tgt_swap_dev):
            os.system('swapon %s' % tgt_swap_dev)

        #### mount root device
        mnt_point = CF.D.TGTSYS_ROOT
        dev_tgt_root = MiDevice(tgt_root_dev, tgt_root_type, mnt_point)
        if not dev_tgt_root.do_mount(): #### NOTE: carefully handle this device's mount.
            logger.e('Mount device %s Failed, install operate can not continue' % dev_tgt_root.get_dev())
            return False
        else:
            self.mounted_devs.append(dev_tgt_root)
        def mount_each(tgt_root_dev, tgt_other_dev, tgt_other_type, tgt_other_mpoint):
            if tgt_other_dev and tgt_root_dev != tgt_other_dev:
                mnt_point = os.path.join(CF.D.TGTSYS_ROOT, tgt_other_mpoint.lstrip('/'))
                dev_tgt_other = MiDevice(tgt_other_dev, tgt_other_type, mnt_point)
                
                if not dev_tgt_other.do_mount(): #### NOTE: carefully handle this device's mount.
                    logger.e('Mount device %s Failed, install operate can not continue' % dev_tgt_other.get_dev())
                    self.umount_tgt_device()
                    return False
                else:
                    self.mounted_devs.append(dev_tgt_other)
                return True
            else:
                logger.e('Can not run to here!! The root file system had been mounted before!!')
                return False
                    
        for mpoint, dev_, type_ in self.tgtsys_devinfo:
            if mpoint not in ('/', 'USE'):
                if not mount_each(tgt_root_dev, dev_, type_, mpoint):
                    return False
        
        # mount -t proc proc myroot/proc/
        mnt_point = os.path.join(CF.D.TGTSYS_ROOT, 'proc')
        ret, msg = mount_dev('proc', 'proc', mntdir=mnt_point,flags=None)
        if not ret:
            logger.e("Error: mount proc on target failed '%s'" % msg)
            return False
        self.mounted_devs.append(mnt_point)

        # mount -t sysfs sys myroot/sys/
        mnt_point = os.path.join(CF.D.TGTSYS_ROOT, 'sys')
        ret, msg = mount_dev('sysfs', 'sys', mntdir=mnt_point,flags=None)
        if not ret:
            logger.e("Error: mount sys on target failed '%s'" % msg)
            return False
        self.mounted_devs.append(mnt_point)

        # mount -o bind /dev myroot/dev/
        mnt_point = os.path.join(CF.D.TGTSYS_ROOT, 'dev')
        ret, msg = mount_dev(None, '/dev', mntdir=mnt_point,flags='bind')
        if not ret:
            logger.e("Error: mount /dev on target failed '%s'" % msg)
            return False
        self.mounted_devs.append(mnt_point)
        
        res = run_bash('mount')
        logger.d(''''Mount target system partition finished, check the mount output please:)
%s
%s
        ''' % ('\n'.join(res['out']), '\n'.join(res['err'])))
        return True
Пример #8
0
def install_disc_prep(mia, operid, dev, fstype, bootiso_relpath, reldir):
    '''
        Install each disc prepare work.
        We should mount each iso to prepare packages source(for disc).
    '''
    global dev_hd # the harddisk device where save packages.
    global dev_iso # the iso where save pkgs.
    global dev_mnt_dir # the current hd or iso mount dir
    dolog('instpkg_disc_prep(%s, %s, %s, %s)\n' % \
          (dev, fstype, bootiso_relpath, reldir))
    ############################## Mount Start #####################################
    dev_hd = MiDevice(dev, fstype)
    if not dev_hd.do_mount(): #### NOTE: carefully handle this device's mount.
        msg = 'Mount device %s Failed, install operate can not continue' % dev_hd.get_dev()
        logger.e(msg)
        return msg
    dev_mnt_dir = dev_hd.get_mountdir()    
    if bootiso_relpath:
        # an iso file on harddisk
        dev_iso = MiDevice(dev_hd.get_file_path(bootiso_relpath), 'iso9660')
        if not dev_iso.do_mount(): #### NOTE: carefully handle this device's mount.
            dev_hd.do_umount(); dev_hd = None
            msg = 'Mount device %s Failed, install operate can not continue!!!' % dev_iso.get_dev()
            logger.e(msg)
            dev_iso = None
            return msg
        dev_mnt_dir = dev_iso.get_mountdir()
    
    ############################## Mount Finished #####################################
    return  0