Bug 1660457 - The partition can not work after block_resize (shrink disk): GPT PMBR size mismatch
Summary: The partition can not work after block_resize (shrink disk): GPT PMBR size mi...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: qemu-kvm
Version: 8.0
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: 8.0
Assignee: Ademar Reis
QA Contact: Xueqiang Wei
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-18 11:26 UTC by Xueqiang Wei
Modified: 2020-01-10 10:24 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-01-18 17:00:33 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Xueqiang Wei 2018-12-18 11:26:00 UTC
Description of problem:

shrink disk and then reboot guest, the partition on disk disappeared.

# fdisk -l
GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.



Version-Release number of selected component (if applicable):

Host:
kernel-4.18.0-50.el8.x86_64
qemu-kvm-3.1.0-1.module+el8+2538+1516be75

Guest:
kernel-4.18.0-50.el8.x86_64



How reproducible:
5/5


Steps to Reproduce:
1. create a 15G data image.
# qemu-img create -f qcow2 /home/kvm_autotest_root/images/data.qcow2 15G

2. start guest with this image as data image (blockdev+q35)
/usr/libexec/qemu-kvm \
    -S  \
    -name 'avocado-vt-vm1'  \
    -sandbox off  \
    -machine q35  \
    -nodefaults \
    -device VGA,bus=pcie.0,addr=0x1 \
    -device pcie-root-port,id=pcie_root_port_0,slot=2,chassis=2,addr=0x2,bus=pcie.0 \
    -device pcie-root-port,id=pcie_root_port_1,slot=3,chassis=3,addr=0x3,bus=pcie.0 \
    -device pcie-root-port,id=pcie_root_port_2,slot=4,chassis=4,addr=0x4,bus=pcie.0  \
    -chardev socket,id=qmp_id_qmpmonitor1,path=/var/tmp/avocado_w2u90exl/monitor-qmpmonitor1-20181127-024837-wdAVx2FL,server,nowait \
    -mon chardev=qmp_id_qmpmonitor1,mode=control  \
    -chardev socket,id=qmp_id_catch_monitor,path=/var/tmp/avocado_w2u90exl/monitor-catch_monitor-20181127-024837-wdAVx2FL,server,nowait \
    -mon chardev=qmp_id_catch_monitor,mode=control \
    -device pvpanic,ioport=0x505,id=idulvcka  \
    -chardev socket,id=serial_id_serial0,path=/var/tmp/avocado_w2u90exl/serial-serial0-20181127-024837-wdAVx2FL,server,nowait \
    -device isa-serial,chardev=serial_id_serial0  \
    -chardev socket,id=seabioslog_id_20181127-024837-wdAVx2FL,path=/var/tmp/avocado_w2u90exl/seabios-20181127-024837-wdAVx2FL,server,nowait \
    -device isa-debugcon,chardev=seabioslog_id_20181127-024837-wdAVx2FL,iobase=0x402 \
    -device pcie-root-port,id=pcie.0-root-port-5,slot=5,chassis=5,addr=0x5,bus=pcie.0 \
    -device qemu-xhci,id=usb1,bus=pcie.0-root-port-5,addr=0x0 \
    -device pcie-root-port,id=pcie.0-root-port-6,slot=6,chassis=6,addr=0x6,bus=pcie.0 \
    -device virtio-scsi-pci,id=virtio_scsi_pci0,bus=pcie.0-root-port-6,addr=0x0 \
    -blockdev driver=file,cache.direct=off,cache.no-flush=on,filename=/home/kvm_autotest_root/images/rhel80-64-virtio-scsi.qcow2,node-name=my_file \
    -blockdev driver=qcow2,node-name=my,file=my_file \
    -device scsi-hd,drive=my,bus=virtio_scsi_pci0.0 \
    -device pcie-root-port,id=pcie.0-root-port-7,slot=7,chassis=7,addr=0x7,bus=pcie.0 \
    -device virtio-net-pci,mac=9a:34:35:36:37:38,id=idyb3F88,vectors=4,netdev=idTAFS0s,bus=pcie.0-root-port-7,addr=0x0  \
    -netdev tap,id=idTAFS0s,vhost=on \
    -m 8G  \
    -smp 12,maxcpus=12,cores=6,threads=1,sockets=2  \
    -cpu 'SandyBridge',+kvm_pv_unhalt \
    -blockdev driver=raw,file.driver=file,cache.direct=off,cache.no-flush=on,file.filename=/home/kvm_autotest_root/iso/windows/winutils.iso,node-name=drive2,read-only=on \
    -device scsi-cd,drive=drive2,id=data-disk1,bus=virtio_scsi_pci0.0 \
    -blockdev driver=raw,file.driver=file,cache.direct=off,cache.no-flush=on,file.filename=/home/kvm_autotest_root/iso/windows/virtio-win-prewhql-0.1-162.iso,node-name=drive3,read-only=on \
    -device scsi-cd,drive=drive3,id=data-disk2,bus=virtio_scsi_pci0.0 \
    -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=1  \
    -vnc :0  \
    -rtc base=localtime,clock=host,driftfix=slew  \
    -boot order=cdn,once=c,menu=off,strict=off \
    -enable-kvm \
    -monitor stdio \
    -qmp tcp:0:4444,server,nowait \
    -device pcie-root-port,id=pcie.0-root-port-9,slot=9,chassis=9,addr=0x9,bus=pcie.0 \
    -device pcie-root-port,id=pcie.0-root-port-8,slot=8,chassis=8,addr=0x8,bus=pcie.0 \
    -device virtio-scsi-pci,id=virtio_scsi_pci1,bus=pcie.0-root-port-9,addr=0x0 \
    -blockdev driver=file,cache.direct=off,cache.no-flush=on,filename=/home/kvm_autotest_root/images/data.qcow2,node-name=data_disk \
    -blockdev driver=qcow2,node-name=disk1,file=data_disk \
    -device scsi-hd,drive=disk1,bus=virtio_scsi_pci1.0,id=data_disk \


3. create partition (GPT + ext4) on disk.

Guest:
# fdisk -l
Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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

# parted /dev/sdb 
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Error: /dev/sdb: unrecognised disk label
Model: QEMU QEMU HARDDISK (scsi)                                          
Disk /dev/sdb: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
(parted) mklabel gpt                                                      
(parted) mkpart primary 0 15G
Warning: The resulting partition is not properly aligned for best performance:
34s % 2048s != 0s
Ignore/Cancel? Ignore                                                     
(parted) print                                                            
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  15.0GB  15.0GB               primary

(parted) quit                                                             
Information: You may need to update /etc/fstab.

# partprobe /dev/sdb

# mkfs.ext4 /dev/sdb1 
mke2fs 1.44.3 (10-July-2018)
Discarding device blocks: done                            
Creating filesystem with 3662105 4k blocks and 915712 inodes
Filesystem UUID: 9e8372e3-9202-4d04-b844-ef3619725f76
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done


# fdisk -l
Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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: gpt
Disk identifier: 59898C6E-3E37-4020-B643-834FABBE96CA

Device     Start      End  Sectors Size Type
/dev/sdb1     34 29296875 29296842  14G Linux filesystem


4. copy a file to the partition and record md5 value.
# mkdir /mnt/test
# mount /dev/sdb1 /mnt/test/
# cp test.log /mnt/test/
# md5sum /mnt/test/test.log 
e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log

5. block_resize to 20G

# telnet localhost 4444
{"execute":"qmp_capabilities"}
{"execute":"block_resize","arguments":{"node-name":"disk1","size":21474836480}}

6. check md5 of the file

# md5sum /mnt/test/test.log 
e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log


7. check the disk in guest.
# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0   20G  0 disk 
├─sda1                       8:1    0    1G  0 part /boot
└─sda2                       8:2    0   19G  0 part 
  ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
  └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
sdb                          8:16   0   20G  0 disk 
└─sdb1                       8:17   0   14G  0 part /mnt/test
sr0                         11:0    1  2.2G  0 rom  
sr1                         11:1    1  541M  0 rom

# fdisk -l
GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: gpt
Disk identifier: 309DECD5-7180-473F-9E56-3E5F9ACBA826

Device     Start      End  Sectors Size Type
/dev/sdb1     34 29296875 29296842  14G Linux filesystem


8. reboot guest and then check disk again.

# reboot

# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0   20G  0 disk 
├─sda1                       8:1    0    1G  0 part /boot
└─sda2                       8:2    0   19G  0 part 
  ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
  └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
sdb                          8:16   0   20G  0 disk 
└─sdb1                       8:17   0   14G  0 part 
sr0                         11:0    1  2.2G  0 rom  
sr1                         11:1    1  541M  0 rom

# fdisk -l
GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: gpt
Disk identifier: 52F81F6B-F026-4D9D-9AF9-D5111E6D3AF9

Device     Start      End  Sectors Size Type
/dev/sdb1     34 29296875 29296842  14G Linux filesystem


9. check md5 of the file

# mount /dev/sdb1 /mnt/test/
# md5sum /mnt/test/test.log 
e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log


10. block_resize to 10G

{"execute":"block_resize","arguments":{"node-name":"disk1","size":10737418240}}


11. check md5 of the file
# md5sum /mnt/test/test.log 
e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log


12. check disk in guest
# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0   20G  0 disk 
├─sda1                       8:1    0    1G  0 part /boot
└─sda2                       8:2    0   19G  0 part 
  ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
  └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
sdb                          8:16   0   10G  0 disk 
└─sdb1                       8:17   0   14G  0 part /mnt/test
sr0                         11:0    1  2.2G  0 rom  
sr1                         11:1    1  541M  0 rom


# fdisk -l
GPT PMBR size mismatch (31457279 != 20971519) will be corrected by write.
Disk /dev/sdb: 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): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1           1 20971519 20971519  10G ee GPT


13. reboot guest and then check disk again.

# reboot

# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0   20G  0 disk 
├─sda1                       8:1    0    1G  0 part /boot
└─sda2                       8:2    0   19G  0 part 
  ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
  └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
sdb                          8:16   0   10G  0 disk 
sr0                         11:0    1  2.2G  0 rom  
sr1                         11:1    1  541M  0 rom

# fdisk -l
GPT PMBR size mismatch (31457279 != 20971519) will be corrected by write.
Disk /dev/sdb: 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): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1           1 20971519 20971519  10G ee GPT

# mount /dev/sdb1 /mnt/test/
mount: /mnt/test: special device /dev/sdb1 does not exist.

# ls /dev/sdb*
/dev/sdb



Actual results:

after step 13, the partition on disk disappeared.
# mount /dev/sdb1 /mnt/test/
mount: /mnt/test: special device /dev/sdb1 does not exist.

# ls /dev/sdb*
/dev/sdb



Expected results:
the partition on disk works well after reboot.



Additional info:

Create partition with msdos + ext4 and retest it, the partition on disk does not disappear after reboot, but it also can not work.

# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0   20G  0 disk 
├─sda1                       8:1    0    1G  0 part /boot
└─sda2                       8:2    0   19G  0 part 
  ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
  └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
sdb                          8:16   0   10G  0 disk 
└─sdb1                       8:17   0   10G  0 part 
sr0                         11:0    1  2.2G  0 rom  
sr1                         11:1    1  541M  0 rom

# fdisk -l
Disk /dev/sdb: 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): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbb2209ab

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1           1 29296875 29296875  14G 83 Linux

# mount /dev/sdb1 /mnt/test/
mount: /mnt/test: wrong fs type, bad option, bad superblock on /dev/sdb1, missing codepage or helper program, or other error.

# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Error: Can't have a partition outside the disk!




Tested with Windows 2019, both GPT+NTFS and MBR+NTFS work well.

Comment 1 Xueqiang Wei 2018-12-18 11:29:07 UTC
Tested on RHEL.7.6, also hit this issue.

kernel-3.10.0-957.el7.x86_64
qemu-kvm-rhev-2.12.0-20.el7

Comment 2 Gu Nini 2018-12-19 01:07:16 UTC
I met the problem on qemu-kvm-3.1.0-1.module+el8+2538+1516be75.ppc64le even without a partition, i.e. just create a file system with mkfs.ext4 or mkfs.xfs on the data disk /dev/sdb, then mount it 'mount /dev/sdb /mnt'; and after shrink the image with 'block_resize', continuing write to the data disk(shrink image) will show the files system could not be used any more with meta data corrupted.

Comment 3 Ademar Reis 2018-12-19 22:37:32 UTC
(In reply to Xueqiang Wei from comment #0)
> Description of problem:
> 
> shrink disk and then reboot guest, the partition on disk disappeared.
> 
> # fdisk -l
> GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
> The backup GPT table is not on the end of the device. This problem will be
> corrected by write.
> 
> 
> 
> Version-Release number of selected component (if applicable):
> 
> Host:
> kernel-4.18.0-50.el8.x86_64
> qemu-kvm-3.1.0-1.module+el8+2538+1516be75
> 
> Guest:
> kernel-4.18.0-50.el8.x86_64
> 
> 
> 
> How reproducible:
> 5/5
> 
> 
> Steps to Reproduce:
> 1. create a 15G data image.
> # qemu-img create -f qcow2 /home/kvm_autotest_root/images/data.qcow2 15G
> 
> 2. start guest with this image as data image (blockdev+q35)
> /usr/libexec/qemu-kvm \
>     -S  \
>     -name 'avocado-vt-vm1'  \
>     -sandbox off  \
>     -machine q35  \
>     -nodefaults \
>     -device VGA,bus=pcie.0,addr=0x1 \
>     -device
> pcie-root-port,id=pcie_root_port_0,slot=2,chassis=2,addr=0x2,bus=pcie.0 \
>     -device
> pcie-root-port,id=pcie_root_port_1,slot=3,chassis=3,addr=0x3,bus=pcie.0 \
>     -device
> pcie-root-port,id=pcie_root_port_2,slot=4,chassis=4,addr=0x4,bus=pcie.0  \
>     -chardev
> socket,id=qmp_id_qmpmonitor1,path=/var/tmp/avocado_w2u90exl/monitor-
> qmpmonitor1-20181127-024837-wdAVx2FL,server,nowait \
>     -mon chardev=qmp_id_qmpmonitor1,mode=control  \
>     -chardev
> socket,id=qmp_id_catch_monitor,path=/var/tmp/avocado_w2u90exl/monitor-
> catch_monitor-20181127-024837-wdAVx2FL,server,nowait \
>     -mon chardev=qmp_id_catch_monitor,mode=control \
>     -device pvpanic,ioport=0x505,id=idulvcka  \
>     -chardev
> socket,id=serial_id_serial0,path=/var/tmp/avocado_w2u90exl/serial-serial0-
> 20181127-024837-wdAVx2FL,server,nowait \
>     -device isa-serial,chardev=serial_id_serial0  \
>     -chardev
> socket,id=seabioslog_id_20181127-024837-wdAVx2FL,path=/var/tmp/
> avocado_w2u90exl/seabios-20181127-024837-wdAVx2FL,server,nowait \
>     -device
> isa-debugcon,chardev=seabioslog_id_20181127-024837-wdAVx2FL,iobase=0x402 \
>     -device
> pcie-root-port,id=pcie.0-root-port-5,slot=5,chassis=5,addr=0x5,bus=pcie.0 \
>     -device qemu-xhci,id=usb1,bus=pcie.0-root-port-5,addr=0x0 \
>     -device
> pcie-root-port,id=pcie.0-root-port-6,slot=6,chassis=6,addr=0x6,bus=pcie.0 \
>     -device
> virtio-scsi-pci,id=virtio_scsi_pci0,bus=pcie.0-root-port-6,addr=0x0 \
>     -blockdev
> driver=file,cache.direct=off,cache.no-flush=on,filename=/home/
> kvm_autotest_root/images/rhel80-64-virtio-scsi.qcow2,node-name=my_file \
>     -blockdev driver=qcow2,node-name=my,file=my_file \
>     -device scsi-hd,drive=my,bus=virtio_scsi_pci0.0 \
>     -device
> pcie-root-port,id=pcie.0-root-port-7,slot=7,chassis=7,addr=0x7,bus=pcie.0 \
>     -device
> virtio-net-pci,mac=9a:34:35:36:37:38,id=idyb3F88,vectors=4,netdev=idTAFS0s,
> bus=pcie.0-root-port-7,addr=0x0  \
>     -netdev tap,id=idTAFS0s,vhost=on \
>     -m 8G  \
>     -smp 12,maxcpus=12,cores=6,threads=1,sockets=2  \
>     -cpu 'SandyBridge',+kvm_pv_unhalt \
>     -blockdev
> driver=raw,file.driver=file,cache.direct=off,cache.no-flush=on,file.
> filename=/home/kvm_autotest_root/iso/windows/winutils.iso,node-name=drive2,
> read-only=on \
>     -device scsi-cd,drive=drive2,id=data-disk1,bus=virtio_scsi_pci0.0 \
>     -blockdev
> driver=raw,file.driver=file,cache.direct=off,cache.no-flush=on,file.
> filename=/home/kvm_autotest_root/iso/windows/virtio-win-prewhql-0.1-162.iso,
> node-name=drive3,read-only=on \
>     -device scsi-cd,drive=drive3,id=data-disk2,bus=virtio_scsi_pci0.0 \
>     -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=1  \
>     -vnc :0  \
>     -rtc base=localtime,clock=host,driftfix=slew  \
>     -boot order=cdn,once=c,menu=off,strict=off \
>     -enable-kvm \
>     -monitor stdio \
>     -qmp tcp:0:4444,server,nowait \
>     -device
> pcie-root-port,id=pcie.0-root-port-9,slot=9,chassis=9,addr=0x9,bus=pcie.0 \
>     -device
> pcie-root-port,id=pcie.0-root-port-8,slot=8,chassis=8,addr=0x8,bus=pcie.0 \
>     -device
> virtio-scsi-pci,id=virtio_scsi_pci1,bus=pcie.0-root-port-9,addr=0x0 \
>     -blockdev
> driver=file,cache.direct=off,cache.no-flush=on,filename=/home/
> kvm_autotest_root/images/data.qcow2,node-name=data_disk \
>     -blockdev driver=qcow2,node-name=disk1,file=data_disk \
>     -device scsi-hd,drive=disk1,bus=virtio_scsi_pci1.0,id=data_disk \
> 
> 
> 3. create partition (GPT + ext4) on disk.
> 
> Guest:
> # fdisk -l
> Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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
> 
> # parted /dev/sdb 
> GNU Parted 3.2
> Using /dev/sdb
> Welcome to GNU Parted! Type 'help' to view a list of commands.
> (parted) print                                                            
> Error: /dev/sdb: unrecognised disk label
> Model: QEMU QEMU HARDDISK (scsi)                                          
> Disk /dev/sdb: 16.1GB
> Sector size (logical/physical): 512B/512B
> Partition Table: unknown
> Disk Flags: 
> (parted) mklabel gpt                                                      
> (parted) mkpart primary 0 15G
> Warning: The resulting partition is not properly aligned for best
> performance:
> 34s % 2048s != 0s
> Ignore/Cancel? Ignore                                                     
> (parted) print                                                            
> Model: QEMU QEMU HARDDISK (scsi)
> Disk /dev/sdb: 16.1GB
> Sector size (logical/physical): 512B/512B
> Partition Table: gpt
> Disk Flags: 
> 
> Number  Start   End     Size    File system  Name     Flags
>  1      17.4kB  15.0GB  15.0GB               primary
> 
> (parted) quit                                                             
> Information: You may need to update /etc/fstab.
> 
> # partprobe /dev/sdb
> 
> # mkfs.ext4 /dev/sdb1 
> mke2fs 1.44.3 (10-July-2018)
> Discarding device blocks: done                            
> Creating filesystem with 3662105 4k blocks and 915712 inodes
> Filesystem UUID: 9e8372e3-9202-4d04-b844-ef3619725f76
> Superblock backups stored on blocks: 
> 	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
> 
> Allocating group tables: done                            
> Writing inode tables: done                            
> Creating journal (16384 blocks): done
> Writing superblocks and filesystem accounting information: done
> 
> 
> # fdisk -l
> Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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: gpt
> Disk identifier: 59898C6E-3E37-4020-B643-834FABBE96CA
> 
> Device     Start      End  Sectors Size Type
> /dev/sdb1     34 29296875 29296842  14G Linux filesystem
> 
> 
> 4. copy a file to the partition and record md5 value.
> # mkdir /mnt/test
> # mount /dev/sdb1 /mnt/test/
> # cp test.log /mnt/test/
> # md5sum /mnt/test/test.log 
> e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log
> 
> 5. block_resize to 20G
> 
> # telnet localhost 4444
> {"execute":"qmp_capabilities"}
> {"execute":"block_resize","arguments":{"node-name":"disk1","size":
> 21474836480}}
> 
> 6. check md5 of the file
> 
> # md5sum /mnt/test/test.log 
> e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log
> 
> 
> 7. check the disk in guest.
> # lsblk
> NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
> sda                          8:0    0   20G  0 disk 
> ├─sda1                       8:1    0    1G  0 part /boot
> └─sda2                       8:2    0   19G  0 part 
>   ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
>   └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
> sdb                          8:16   0   20G  0 disk 
> └─sdb1                       8:17   0   14G  0 part /mnt/test
> sr0                         11:0    1  2.2G  0 rom  
> sr1                         11:1    1  541M  0 rom
> 
> # fdisk -l
> GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
> The backup GPT table is not on the end of the device. This problem will be
> corrected by write.
> Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: gpt
> Disk identifier: 309DECD5-7180-473F-9E56-3E5F9ACBA826
> 
> Device     Start      End  Sectors Size Type
> /dev/sdb1     34 29296875 29296842  14G Linux filesystem
> 
> 
> 8. reboot guest and then check disk again.
> 
> # reboot
> 
> # lsblk
> NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
> sda                          8:0    0   20G  0 disk 
> ├─sda1                       8:1    0    1G  0 part /boot
> └─sda2                       8:2    0   19G  0 part 
>   ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
>   └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
> sdb                          8:16   0   20G  0 disk 
> └─sdb1                       8:17   0   14G  0 part 
> sr0                         11:0    1  2.2G  0 rom  
> sr1                         11:1    1  541M  0 rom
> 
> # fdisk -l
> GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
> The backup GPT table is not on the end of the device. This problem will be
> corrected by write.
> Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: gpt
> Disk identifier: 52F81F6B-F026-4D9D-9AF9-D5111E6D3AF9
> 
> Device     Start      End  Sectors Size Type
> /dev/sdb1     34 29296875 29296842  14G Linux filesystem
> 
> 
> 9. check md5 of the file
> 
> # mount /dev/sdb1 /mnt/test/
> # md5sum /mnt/test/test.log 
> e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log
> 
> 
> 10. block_resize to 10G
> 
> {"execute":"block_resize","arguments":{"node-name":"disk1","size":
> 10737418240}}

This step will corrupt the partition and the file-system in the guest, so the test result is expected.

Users are not supposed to shrink the underlying image (or phisical disk) if there's a file-system or partition that uses the part of the disk that is being "deleted". You need to use something like resize2fs inside the guest, then recreate the partition before changing the image size via QEMU.

For some documentation, please see https://access.redhat.com/articles/1196333

Comment 4 Xueqiang Wei 2018-12-20 02:38:03 UTC
(In reply to Ademar Reis from comment #3)
> (In reply to Xueqiang Wei from comment #0)
> > Description of problem:
> > 
> > shrink disk and then reboot guest, the partition on disk disappeared.
> > 
> > # fdisk -l
> > GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
> > The backup GPT table is not on the end of the device. This problem will be
> > corrected by write.
> > 
> > 
> > 
> > Version-Release number of selected component (if applicable):
> > 
> > Host:
> > kernel-4.18.0-50.el8.x86_64
> > qemu-kvm-3.1.0-1.module+el8+2538+1516be75
> > 
> > Guest:
> > kernel-4.18.0-50.el8.x86_64
> > 
> > 
> > 
> > How reproducible:
> > 5/5
> > 
> > 
> > Steps to Reproduce:
> > 1. create a 15G data image.
> > # qemu-img create -f qcow2 /home/kvm_autotest_root/images/data.qcow2 15G
> > 
> > 2. start guest with this image as data image (blockdev+q35)
> > /usr/libexec/qemu-kvm \
> >     -S  \
> >     -name 'avocado-vt-vm1'  \
> >     -sandbox off  \
> >     -machine q35  \
> >     -nodefaults \
> >     -device VGA,bus=pcie.0,addr=0x1 \
> >     -device
> > pcie-root-port,id=pcie_root_port_0,slot=2,chassis=2,addr=0x2,bus=pcie.0 \
> >     -device
> > pcie-root-port,id=pcie_root_port_1,slot=3,chassis=3,addr=0x3,bus=pcie.0 \
> >     -device
> > pcie-root-port,id=pcie_root_port_2,slot=4,chassis=4,addr=0x4,bus=pcie.0  \
> >     -chardev
> > socket,id=qmp_id_qmpmonitor1,path=/var/tmp/avocado_w2u90exl/monitor-
> > qmpmonitor1-20181127-024837-wdAVx2FL,server,nowait \
> >     -mon chardev=qmp_id_qmpmonitor1,mode=control  \
> >     -chardev
> > socket,id=qmp_id_catch_monitor,path=/var/tmp/avocado_w2u90exl/monitor-
> > catch_monitor-20181127-024837-wdAVx2FL,server,nowait \
> >     -mon chardev=qmp_id_catch_monitor,mode=control \
> >     -device pvpanic,ioport=0x505,id=idulvcka  \
> >     -chardev
> > socket,id=serial_id_serial0,path=/var/tmp/avocado_w2u90exl/serial-serial0-
> > 20181127-024837-wdAVx2FL,server,nowait \
> >     -device isa-serial,chardev=serial_id_serial0  \
> >     -chardev
> > socket,id=seabioslog_id_20181127-024837-wdAVx2FL,path=/var/tmp/
> > avocado_w2u90exl/seabios-20181127-024837-wdAVx2FL,server,nowait \
> >     -device
> > isa-debugcon,chardev=seabioslog_id_20181127-024837-wdAVx2FL,iobase=0x402 \
> >     -device
> > pcie-root-port,id=pcie.0-root-port-5,slot=5,chassis=5,addr=0x5,bus=pcie.0 \
> >     -device qemu-xhci,id=usb1,bus=pcie.0-root-port-5,addr=0x0 \
> >     -device
> > pcie-root-port,id=pcie.0-root-port-6,slot=6,chassis=6,addr=0x6,bus=pcie.0 \
> >     -device
> > virtio-scsi-pci,id=virtio_scsi_pci0,bus=pcie.0-root-port-6,addr=0x0 \
> >     -blockdev
> > driver=file,cache.direct=off,cache.no-flush=on,filename=/home/
> > kvm_autotest_root/images/rhel80-64-virtio-scsi.qcow2,node-name=my_file \
> >     -blockdev driver=qcow2,node-name=my,file=my_file \
> >     -device scsi-hd,drive=my,bus=virtio_scsi_pci0.0 \
> >     -device
> > pcie-root-port,id=pcie.0-root-port-7,slot=7,chassis=7,addr=0x7,bus=pcie.0 \
> >     -device
> > virtio-net-pci,mac=9a:34:35:36:37:38,id=idyb3F88,vectors=4,netdev=idTAFS0s,
> > bus=pcie.0-root-port-7,addr=0x0  \
> >     -netdev tap,id=idTAFS0s,vhost=on \
> >     -m 8G  \
> >     -smp 12,maxcpus=12,cores=6,threads=1,sockets=2  \
> >     -cpu 'SandyBridge',+kvm_pv_unhalt \
> >     -blockdev
> > driver=raw,file.driver=file,cache.direct=off,cache.no-flush=on,file.
> > filename=/home/kvm_autotest_root/iso/windows/winutils.iso,node-name=drive2,
> > read-only=on \
> >     -device scsi-cd,drive=drive2,id=data-disk1,bus=virtio_scsi_pci0.0 \
> >     -blockdev
> > driver=raw,file.driver=file,cache.direct=off,cache.no-flush=on,file.
> > filename=/home/kvm_autotest_root/iso/windows/virtio-win-prewhql-0.1-162.iso,
> > node-name=drive3,read-only=on \
> >     -device scsi-cd,drive=drive3,id=data-disk2,bus=virtio_scsi_pci0.0 \
> >     -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=1  \
> >     -vnc :0  \
> >     -rtc base=localtime,clock=host,driftfix=slew  \
> >     -boot order=cdn,once=c,menu=off,strict=off \
> >     -enable-kvm \
> >     -monitor stdio \
> >     -qmp tcp:0:4444,server,nowait \
> >     -device
> > pcie-root-port,id=pcie.0-root-port-9,slot=9,chassis=9,addr=0x9,bus=pcie.0 \
> >     -device
> > pcie-root-port,id=pcie.0-root-port-8,slot=8,chassis=8,addr=0x8,bus=pcie.0 \
> >     -device
> > virtio-scsi-pci,id=virtio_scsi_pci1,bus=pcie.0-root-port-9,addr=0x0 \
> >     -blockdev
> > driver=file,cache.direct=off,cache.no-flush=on,filename=/home/
> > kvm_autotest_root/images/data.qcow2,node-name=data_disk \
> >     -blockdev driver=qcow2,node-name=disk1,file=data_disk \
> >     -device scsi-hd,drive=disk1,bus=virtio_scsi_pci1.0,id=data_disk \
> > 
> > 
> > 3. create partition (GPT + ext4) on disk.
> > 
> > Guest:
> > # fdisk -l
> > Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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
> > 
> > # parted /dev/sdb 
> > GNU Parted 3.2
> > Using /dev/sdb
> > Welcome to GNU Parted! Type 'help' to view a list of commands.
> > (parted) print                                                            
> > Error: /dev/sdb: unrecognised disk label
> > Model: QEMU QEMU HARDDISK (scsi)                                          
> > Disk /dev/sdb: 16.1GB
> > Sector size (logical/physical): 512B/512B
> > Partition Table: unknown
> > Disk Flags: 
> > (parted) mklabel gpt                                                      
> > (parted) mkpart primary 0 15G
> > Warning: The resulting partition is not properly aligned for best
> > performance:
> > 34s % 2048s != 0s
> > Ignore/Cancel? Ignore                                                     
> > (parted) print                                                            
> > Model: QEMU QEMU HARDDISK (scsi)
> > Disk /dev/sdb: 16.1GB
> > Sector size (logical/physical): 512B/512B
> > Partition Table: gpt
> > Disk Flags: 
> > 
> > Number  Start   End     Size    File system  Name     Flags
> >  1      17.4kB  15.0GB  15.0GB               primary
> > 
> > (parted) quit                                                             
> > Information: You may need to update /etc/fstab.
> > 
> > # partprobe /dev/sdb
> > 
> > # mkfs.ext4 /dev/sdb1 
> > mke2fs 1.44.3 (10-July-2018)
> > Discarding device blocks: done                            
> > Creating filesystem with 3662105 4k blocks and 915712 inodes
> > Filesystem UUID: 9e8372e3-9202-4d04-b844-ef3619725f76
> > Superblock backups stored on blocks: 
> > 	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
> > 
> > Allocating group tables: done                            
> > Writing inode tables: done                            
> > Creating journal (16384 blocks): done
> > Writing superblocks and filesystem accounting information: done
> > 
> > 
> > # fdisk -l
> > Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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: gpt
> > Disk identifier: 59898C6E-3E37-4020-B643-834FABBE96CA
> > 
> > Device     Start      End  Sectors Size Type
> > /dev/sdb1     34 29296875 29296842  14G Linux filesystem
> > 
> > 
> > 4. copy a file to the partition and record md5 value.
> > # mkdir /mnt/test
> > # mount /dev/sdb1 /mnt/test/
> > # cp test.log /mnt/test/
> > # md5sum /mnt/test/test.log 
> > e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log
> > 
> > 5. block_resize to 20G
> > 
> > # telnet localhost 4444
> > {"execute":"qmp_capabilities"}
> > {"execute":"block_resize","arguments":{"node-name":"disk1","size":
> > 21474836480}}
> > 
> > 6. check md5 of the file
> > 
> > # md5sum /mnt/test/test.log 
> > e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log
> > 
> > 
> > 7. check the disk in guest.
> > # lsblk
> > NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
> > sda                          8:0    0   20G  0 disk 
> > ├─sda1                       8:1    0    1G  0 part /boot
> > └─sda2                       8:2    0   19G  0 part 
> >   ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
> >   └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
> > sdb                          8:16   0   20G  0 disk 
> > └─sdb1                       8:17   0   14G  0 part /mnt/test
> > sr0                         11:0    1  2.2G  0 rom  
> > sr1                         11:1    1  541M  0 rom
> > 
> > # fdisk -l
> > GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
> > The backup GPT table is not on the end of the device. This problem will be
> > corrected by write.
> > Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: gpt
> > Disk identifier: 309DECD5-7180-473F-9E56-3E5F9ACBA826
> > 
> > Device     Start      End  Sectors Size Type
> > /dev/sdb1     34 29296875 29296842  14G Linux filesystem
> > 
> > 
> > 8. reboot guest and then check disk again.
> > 
> > # reboot
> > 
> > # lsblk
> > NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
> > sda                          8:0    0   20G  0 disk 
> > ├─sda1                       8:1    0    1G  0 part /boot
> > └─sda2                       8:2    0   19G  0 part 
> >   ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
> >   └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
> > sdb                          8:16   0   20G  0 disk 
> > └─sdb1                       8:17   0   14G  0 part 
> > sr0                         11:0    1  2.2G  0 rom  
> > sr1                         11:1    1  541M  0 rom
> > 
> > # fdisk -l
> > GPT PMBR size mismatch (31457279 != 41943039) will be corrected by write.
> > The backup GPT table is not on the end of the device. This problem will be
> > corrected by write.
> > Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: gpt
> > Disk identifier: 52F81F6B-F026-4D9D-9AF9-D5111E6D3AF9
> > 
> > Device     Start      End  Sectors Size Type
> > /dev/sdb1     34 29296875 29296842  14G Linux filesystem
> > 
> > 
> > 9. check md5 of the file
> > 
> > # mount /dev/sdb1 /mnt/test/
> > # md5sum /mnt/test/test.log 
> > e2a18ba3dc475065045db4a0b67c7ee4  /mnt/test/test.log
> > 
> > 
> > 10. block_resize to 10G
> > 
> > {"execute":"block_resize","arguments":{"node-name":"disk1","size":
> > 10737418240}}
> 
> This step will corrupt the partition and the file-system in the guest, so
> the test result is expected.
> 
> Users are not supposed to shrink the underlying image (or phisical disk) if
> there's a file-system or partition that uses the part of the disk that is
> being "deleted". You need to use something like resize2fs inside the guest,
> then recreate the partition before changing the image size via QEMU.
> 
> For some documentation, please see https://access.redhat.com/articles/1196333


Thank you, I will update test case.

Comment 5 Xueqiang Wei 2018-12-25 12:03:06 UTC
According to Comment 3, retested and also hit this issue. So reopen this bug. If I was wrong, please correct me. Thank you very much.


Details:

Host:
kernel-4.18.0-50.el8.x86_64
qemu-kvm-3.1.0-2.module+el8+2606+2c716ad7

Guest:
kernel-4.18.0-50.el8.x86_64


Note: partition works well after shrank with msdos and ext4 , but can not work with gpt and ext4. 

1. create partition by parted tool

# parted /dev/sdb 
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Error: /dev/sdb: unrecognised disk label
Model: QEMU QEMU HARDDISK (scsi)                                          
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
(parted) mklabel msdos
(parted) mkpart primary 1.024M 21.5G
(parted) print                                                            
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  21.5GB  21.5GB  primary               lba
(parted) quit

# partprobe /dev/sdb
# mkfs.ext4 /dev/sdb1
# mount /dev/sdb1 /mnt/test/
# cp test.log /mnt/test/


2. check file-system

# umount /dev/sdb1

run fsck on the unmounted file system.

#  e2fsck -f /dev/sdb1
e2fsck 1.44.3 (10-July-2018)
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/sdb1: 12/1310720 files (0.0% non-contiguous), 126323/5242624 blocks


3. shrink the file system with the resize2fs

# resize2fs /dev/sdb1 10G
resize2fs 1.44.3 (10-July-2018)
Resizing the filesystem on /dev/sdb1 to 2621440 (4k) blocks.
The filesystem on /dev/sdb1 is now 2621440 (4k) blocks long.


4. delete and recreate the partition the file system is on to the required amount.

# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  21.5GB  21.5GB  primary  ext4

(parted) rm 1                                                             
(parted) mkpart primary 1.024M 10738.44224M
(parted) print                                                            
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.7GB  10.7GB  primary               lba

(parted) quit
Information: You may need to update /etc/fstab.

# partprobe /dev/sdb
                              
# e2fsck -f /dev/sdb1 
e2fsck 1.44.3 (10-July-2018)
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/sdb1: 12/655360 files (0.0% non-contiguous), 83138/2621440 blocks

# mount /dev/sdb1 /mnt/test/
# ls /mnt/test/
lost+found  test.log
# umount /dev/sdb1


5. shrink disk to 10G

{"execute":"block_resize","arguments":{"node-name":"disk1","size":10742661120}}


6. check file system again.

# lsblk
NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                          8:0    0   60G  0 disk 
├─sda1                       8:1    0    1G  0 part /boot
└─sda2                       8:2    0 54.9G  0 part 
  ├─rhel_vm--198--140-root 253:0    0   17G  0 lvm  /
  └─rhel_vm--198--140-swap 253:1    0    2G  0 lvm  [SWAP]
sdb                          8:16   0   10G  0 disk 
└─sdb1                       8:17   0   10G  0 part 
sr0                         11:0    1  2.2G  0 rom  
sr1                         11:1    1  541M  0 rom  

# e2fsck -f /dev/sdb1 
e2fsck 1.44.3 (10-July-2018)
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/sdb1: 12/655360 files (0.0% non-contiguous), 83138/2621440 blocks


7. reboot guest and check partition works well

# mount /dev/sdb1 /mnt/test/
# ls /mnt/test/
lost+found  test.log





If partition created with GPT and Ext4, after step 7:


# mount /dev/sdb1 /mnt/test/
mount: /mnt/test: special device /dev/sdb1 does not exist.

# parted /dev/sdb 
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: Invalid argument during seek for read on /dev/sdb
Retry/Ignore/Cancel? Retry
Error: Invalid argument during seek for read on /dev/sdb
Retry/Ignore/Cancel? Cancel                                               
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
(parted) quit                                                             


# fdisk -l
GPT PMBR size mismatch (41943039 != 20981759) will be corrected by write.
Disk /dev/sdb: 10 GiB, 10742661120 bytes, 20981760 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: 0x00000000

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1           1 20981759 20981759  10G ee GPT

Comment 6 Ademar Reis 2019-01-18 17:00:33 UTC
(In reply to Xueqiang Wei from comment #5)
> According to Comment 3, retested and also hit this issue. So reopen this
> bug. If I was wrong, please correct me. Thank you very much.
> 
> 
> Details:
> 
> Host:
> kernel-4.18.0-50.el8.x86_64
> qemu-kvm-3.1.0-2.module+el8+2606+2c716ad7
> 
> Guest:
> kernel-4.18.0-50.el8.x86_64
> 
> 
> Note: partition works well after shrank with msdos and ext4 , but can not
> work with gpt and ext4. 

Turns out that GPT partitions store something at the end of the disk, so you need one extra step.

The idea remains the same: one can't shrink the underlying disk without making the guest fully aware of the change. For the extra step necessary and some explanation, please see this page:
https://superuser.com/questions/660309/live-resize-of-a-gpt-partition-on-linux

Closing it again, because one step is missing in the test and therefore it's invalid.


Note You need to log in before you can comment on or make changes to this bug.