﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
651	Mindi USB Creation (Filesystem) Failing	Matthew Ross	Bruno Cornec	"I am running into issues using mindi to create bootable USB drives on RHEL/CentOS 6.x.

After writing the partition table to the USB drive (successfully), the call mkdosfs fails to write the filesystem. Output is as follows:
{{{
INFO: The USB device /dev/sdb now looks like this:

Disk /dev/sdb: 131 MB, 131072000 bytes
16 heads, 32 sectors/track, 500 cylinders
Units = cylinders of 512 * 512 = 262144 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         500      127984    b  W95 FAT32
INFO: Unmounting /dev/sdb1 just in case again
umount: /dev/sdb1: not mounted
INFO: Creating a vfat filesystem on /dev/sdb1
mkdosfs 3.0.9 (31 Jan 2010)
ERROR: Unable to create a vfat filesystem on /dev/sdb1
       Make sure your USB device is pluged (<--sp) in and partitioned (/dev/sdb1 must exist on it)
}}}

Of course nothing on the device is mounted and I have verified this occurs manually entering the commands to create the drive:
1. fdisk the drive deleting partitions and creating the one (type b)
2. kpartx -a /dev/sdb
3. mkdosfs -F 32 /dev/sdb1

What appears to happening is upon calling kpartx, device mapper seems to be getting a hold of the device  creating a node for it (/dev/mapper/sdb1 and /dev/dm-N) causing the mkdosfs command to fail.

kpartx output:
{{{
[root@##### rules.d]# kpartx -va /dev/sdb
add map sdb1 (253:0): 0 255950 linear /dev/sdb 50
}}}
dmsetup ls output:
{{{
...
sdb1    (253:0)
...
}}}
dmsetup info output:
{{{
Name:              sdb1
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      253, 0
Number of targets: 1
UUID: part1-sdb
}}}
mkdosfs output:
{{{
[root@##### rules.d]# mkdosfs -F 32 /dev/sdb1
mkdosfs 3.0.9 (31 Jan 2010)
mkdosfs: unable to open /dev/sdb1
}}}

For some reason device mapper is preventing mkdosfs from creating the filesystem. I am not really sure what is happening here or why device mapper would interfere with creating a filesystem. I suspect something is going on with udev creating this node but I will need to investigate it further.

As a work around I added the following to mindi for the time being, though at this point I am not sure if this is a distro quirk, external bug, or internal bug:
{{{
OfferToMakeBootableUSB() {
...
    kpartx -a $USBDEVICE
    # Some distro do auto mount at that point (Ubuntu)
    LogFile ""INFO: Unmounting $USBPART just in case again""
    umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
    echo -en "".""
    if [ ""`which dmsetup`"" != """" ]; then
        block_id=""`echo $USBPART | sed 's|/dev/||g'`""
        if [[ ""`dmsetup ls | awk '{print $1}' | grep $block_id`"" != """" ]]; then
            LogFile ""INFO: Removing $block_id from device mapper.""
            sleep 1
            dmsetup remove $block_id
        fi
    fi
    LogFile ""INFO: Creating a vfat filesystem on $USBPART""
    mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
...
}
}}}
Kind of a hack but it got it working for me. I did a quick search on trac for anything similar and came up empty - punch me if I missed something. I will try and get to the bottom of what is going on in the background but I wanted to spit this out there in case anyone has had similar issues."	defect	closed	normal	3.0.3	mindi	3.0.2	normal	fixed		mondotrac@…
