Bug 1000428

Summary: virt-format uses wrong partition type for vfat filesystems
Product: Red Hat Enterprise Linux 7 Reporter: Gerd Hoffmann <kraxel>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: bfan, leiwang, lkong, wshi
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.22.6-5.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-13 12:48:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Gerd Hoffmann 2013-08-23 12:39:48 UTC
Description of problem:
$subject

Version-Release number of selected component (if applicable):
libguestfs-tools-c-1.22.5-3.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. qemu-img create -f qcow2 "$file" "$size"
2. virt-format --add "$file" --format=qcow2 --partition=mbr --filesystem=vfat
3. attach image as usb disk to windows guest

Actual results:
usbstick doesn't show up in Windows Explorer

Expected results:
usbstick can be used without much fuss

Additional info:
The partition is created with type 0x83 (Linux).
When partitioning the stick using windows it will pick 0x0b (W95 FAT32),
virt-format should to the same.

While being at it: Having a --label=<text> cmd line switch (to specify a volume label for the filesystem) would be great too.  Wanna have a separate RFE bug for this?

Comment 1 Richard W.M. Jones 2013-08-23 12:52:23 UTC
Doh.  We fixed the same problem in virt-make-fs too ...

(In reply to Gerd Hoffmann from comment #0)
> While being at it: Having a --label=<text> cmd line switch (to specify a
> volume label for the filesystem) would be great too.  Wanna have a separate
> RFE bug for this?

Don't worry, I'll fix them both.

Comment 4 Lingfei Kong 2013-10-10 06:53:40 UTC
Can reproduce with libguestfs-tools-c-1.22.5-3.el7.x86_64

Steps to reproduce:
1. qemu-img create -f qcow2 test.img 100M
2. virt-format --add test.img --format=qcow2 --partition=mbr --filesystem=vfat
3. attach image as usb disk to windows guest

Result:
usbstick doesn't show up in Windows Explorer

Comment 5 Richard W.M. Jones 2013-10-10 07:50:34 UTC
(In reply to Lingfei Kong from comment #4)
> Can reproduce with libguestfs-tools-c-1.22.5-3.el7.x86_64
> 
> Steps to reproduce:
> 1. qemu-img create -f qcow2 test.img 100M
> 2. virt-format --add test.img --format=qcow2 --partition=mbr
> --filesystem=vfat
> 3. attach image as usb disk to windows guest

When attaching the image, did you ensure the format is set
to qcow2?  If you set it to raw then Windows would just see
a qcow2 header, everything would be completely broken.

> Result:
> usbstick doesn't show up in Windows Explorer

Can you run:

virt-filesystems -a test.img --all --long -h

The output should show that the MBR byte is set to 0b.
For examples see:
https://github.com/libguestfs/libguestfs/commit/d432ab2b5a965110bab542bfd397785eee9753dd

Comment 6 Lingfei Kong 2013-10-11 03:11:25 UTC
(In reply to Richard W.M. Jones from comment #5)

> When attaching the image, did you ensure the format is set
> to qcow2?  If you set it to raw then Windows would just see
> a qcow2 header, everything would be completely broken.

Yes, I specified the format as qcow2 in the steps showed in commnet #4, here is the command I used to attach the image file:
/usr/libexec/qemu-kvm -m 1024 -name "VM" -drive file=/root/win.img -usbdevice disk:format=qcow2:/test.img

> Can you run:
> 
> virt-filesystems -a test.img --all --long -h
> 
> The output should show that the MBR byte is set to 0b.

I checked the image file(showed in comment #4, it is created with command: virt-format --add test.img --format=qcow2 --partition=mbr --filesystem=vfat
) with virt-filesystems  tool, the following is the output:
[host]#virt-filesystems -a test.img --all --long -h
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  vfat  -      -    100M  -
/dev/sda1  partition   -     -      83   100M  /dev/sda
/dev/sda   device      -     -      -    100M  -

It shows the MBR byte is 83 not 0b.

Comment 7 Richard W.M. Jones 2013-10-11 11:14:26 UTC
I'm just reading back more closely.  It looks like you have
correctly reproduced the original problem with 1.22.5.

The bug should be fixed in libguestfs >= 1.22.6-5.el7.

Comment 9 Lingfei Kong 2013-12-06 08:25:04 UTC
Verified it with libguestfs-1.22.6-15.el7

Steps to verify: 
1. #qemu-img create -f qcow2 test.img 100M

2. #virt-format --add test.img --format=qcow2 --partition=mbr --filesystem=vfat

3. attach image as usb disk to windows guest
#/usr/libexec/qemu-kvm -m 1024 -name "VM" -drive file=/var/lib/libvirt/images/vm1.img -usbdevice disk:format=qcow2:/root/lkong/test.img -vnc :0

4.
 # virt-filesystems -a test.img --all --long -h
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  vfat  -      -    100M  -
/dev/sda1  partition   -     -      0b   100M  /dev/sda
/dev/sda   device      -     -      -    100M  -


Result:
1. usbstick shows up in Windows Explorer.
2. It shows the MBR byte is 0b in step 4. 

So, this bug is fixed.

Comment 10 Ludek Smid 2014-06-13 12:48:50 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.