Description of problem: Using virt-builder to create debian-6 VM fails with following: [root@hp-ms-01-c14 ~]# virt-builder debian-6 -o /dev/fedora_hp-ms-01-c14/debian-6 [ 0.8] Downloading: http://libguestfs.org/download/builder/debian-6.xz ######################################################################## 100.0% [ 88.8] Planning how to build this image [ 88.8] Uncompressing [ 116.7] Resizing (using virt-resize) to expand the disk to 10.0G virt-resize: error: libguestfs error: part_set_mbr_id: sfdisk --part-type: You cannot change a partition into an extended one or vice versa. Delete it first. sfdisk: /dev/sdb: partition 2: failed to set partition type If reporting bugs, run virt-resize with debugging enabled and include the complete output: virt-resize -v -x [...] Version-Release number of selected component (if applicable): libguestfs-tools-c-1.29.50-1.fc22.x86_64 How reproducible: 100% (with downloaded debian image) Partitions in the image: [root@hp-ms-01-c14 f22]# fdisk /dev/mapper/fedora_hp--ms--01--c14-debian--6 Welcome to fdisk (util-linux 2.26.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/mapper/fedora_hp--ms--01--c14-debian--6: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 65536 bytes / 65536 bytes Disklabel type: dos Disk identifier: 0x00083915 Device Boot Start End Sectors Size Id Type /dev/mapper/fedora_hp--ms--01--c14-debian--6p1 * 2048 20522623 20520576 9.8G 83 Linux /dev/mapper/fedora_hp--ms--01--c14-debian--6p2 20522624 20969089 446466 218M f W95 Ext'd (LBA) /dev/mapper/fedora_hp--ms--01--c14-debian--6p5 20522626 20969089 446464 218M 82 Linux swap / Solaris fsck'ing the partition everything seems sane: [root@hp-ms-01-c14 f22]# fsck /dev/mapper/fedora_hp--ms--01--c14-debian--6p1 fsck from util-linux 2.26.2 e2fsck 1.42.12 (29-Aug-2014) /dev/mapper/fedora_hp--ms--01--c14-debian--6p1 has gone 625 days without being checked, check forced. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/fedora_hp--ms--01--c14-debian--6p1: 24410/248000 files (0.9% non-contiguous), 171566/992000 blocks
This works for me on Fedora 22, so I guess it must have something to do with the version of sfdisk on Debian vs Fedora (the program was substantially rewritten upstream recently). I have: util-linux-2.26.2-1.fc22.x86_64 What version of sfdisk/util-linux do you have?
Sorry, I now see you're actually using Fedora host (not Debian as I thought for some reason). What version of util-linux is it anyway?
Same here: util-linux-2.26.2-1.fc22.x86_64 The difference may be I was extracting to an existing thin-LV so the image was resized. Trying virt-builder with `--size 10G` option: it fails: [root@hp-ms-01-c14 ~]# virt-builder debian-6 -o /tmp/test-debian-6 --size 10G [ 0.8] Downloading: http://libguestfs.org/download/builder/debian-6.xz [ 1.9] Planning how to build this image [ 1.9] Uncompressing [ 29.7] Resizing (using virt-resize) to expand the disk to 10.0G virt-resize: error: libguestfs error: part_set_mbr_id: sfdisk --part-type: You cannot change a partition into an extended one or vice versa. Delete it first. sfdisk: /dev/sdb: partition 2: failed to set partition type If reporting bugs, run virt-resize with debugging enabled and include the complete output: virt-resize -v -x [...] Attaching output of the same command with -x -v.
Created attachment 1057539 [details] virt-builder output
Oh I see, I can reproduce it also using the --size 10G parameter. This seems to be a bug in sfdisk as far as I can tell. Here is a reproducer: $ rm -f disk.img $ truncate -s 4G disk.img $ fdisk disk.img Welcome to fdisk (util-linux 2.26.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x81a5bda3. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): e Partition number (1-4, default 1): First sector (2048-8388607, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-8388607, default 8388607): Created a new partition 1 of type 'Extended' and of size 4 GiB. Command (m for help): p Disk disk.img: 4 GiB, 4294967296 bytes, 8388608 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x81a5bda3 Device Boot Start End Sectors Size Id Type disk.img1 2048 8388607 8386560 4G 5 Extended Command (m for help): w The partition table has been altered. Syncing disks. ### Notice that the MBR type byte is 05: $ virt-filesystems -a disk.img --all --long -h Name Type VFS Label MBR Size Parent /dev/sda1 filesystem unknown - - 1.0K - /dev/sda1 partition - - 05 1.0K /dev/sda /dev/sda device - - - 4.0G - ### Now try setting the MBR type byte to 05. $ sfdisk --part-type /dev/sda 1 5 You cannot change a partition into an extended one or vice versa. Delete it first. sfdisk: /dev/sda: partition 1: failed to set partition type
Bleah; the sfdisk command there was obviously wrong. However it still fails when I use the correct command: $ sfdisk --part-type disk.img 1 5 You cannot change a partition into an extended one or vice versa. Delete it first. sfdisk: disk.img: partition 1: failed to set partition type
Fixed by upstream commit df15fb3d053716d03055df755911d66814054b4b. Thanks for your report! Note that with the bugfix you still cannot change type of the extended partition which is already used by nested logical partition(s), but your use-case works as expected: # sfdisk -ql /dev/sdc Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 22527 20480 10M 83 Linux /dev/sdc2 22528 1023999 1001472 489M 83 Linux # sfdisk /dev/sdc --part-type 2 5 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. # sfdisk -ql /dev/sdc Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 22527 20480 10M 83 Linux /dev/sdc2 22528 1023999 1001472 489M 5 Extended The bugfix will be definitely in v2.27 (f23), is it necessary to backport it also to f22?
It would be nice to have it in F22, but don't sweat it if it's a difficult backport.
Thanks guys!
util-linux-2.26.2-3.fc22 has been submitted as an update for Fedora 22. https://admin.fedoraproject.org/updates/util-linux-2.26.2-3.fc22
Package util-linux-2.26.2-3.fc22: * should fix your issue, * was pushed to the Fedora 22 testing repository, * should be available at your local mirror within two days. Update it with: # su -c 'yum update --enablerepo=updates-testing util-linux-2.26.2-3.fc22' as soon as you are able to. Please go to the following url: https://admin.fedoraproject.org/updates/FEDORA-2015-13513/util-linux-2.26.2-3.fc22 then log in and leave karma (feedback).
util-linux-2.26.2-3.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.
*** Bug 1265078 has been marked as a duplicate of this bug. ***