'Build kernel initrd image.
Try to use distro specific way to build initrd image.
Parameters:
version
new kernel version
image
new kernel image file
system_map
System.map file
initrd
initrd image file to build'

@log.record
@tee_output_logdir_mark
def mkinitrd(self, version, image, system_map, initrd):

    d = distro.detect()
    if os.path.isfile(initrd):
        print ('Existing    %s    file,    will    remove    it.' % initrd)
        os.remove(initrd)
    args = self.job.config_get('kernel.mkinitrd_extra_args')
    if (not args):
        args = ''
    real_version_list = glob.glob(('/lib/modules/%s*' % version))
    rl = len(real_version_list)
    if (rl == 0):
        logging.error('No    directory    %s    found    under    /lib/modules.    Initramfscreation    will    most    likely    fail    and    your    new    kernelwill    fail    to    build', version)
    else:
        if (rl > 1):
            logging.warning('Found    more    than    one    possible    match    for    kernel    version    %s    under    /lib/modules', version)
        version = os.path.basename(real_version_list[0])
    if (d.name in ['redhat', 'fedora']):
        try:
            cmd = os_dep.command('dracut')
            full_cmd = ('%s    -f    %s    %s' % (cmd, initrd, version))
        except ValueError:
            cmd = os_dep.command('mkinitrd')
            full_cmd = ('%s    %s    %s    %s' % (cmd, args, initrd, version))
        utils.system(full_cmd)
    elif (d.name in ['sles']):
        utils.system(('mkinitrd    %s    -k    %s    -i    %s    -M    %s' % (args, image, initrd, system_map)))
    elif (d.name in ['debian', 'ubuntu']):
        if os.path.isfile('/usr/sbin/mkinitrd'):
            cmd = '/usr/sbin/mkinitrd'
        elif os.path.isfile('/usr/sbin/mkinitramfs'):
            cmd = '/usr/sbin/mkinitramfs'
        else:
            raise error.TestError('No    Debian    initrd    builder')
        utils.system(('%s    %s    -o    %s    %s' % (cmd, args, initrd, version)))
    else:
        raise error.TestError(('Unsupported    distro    %s' % d.name))
