I'm launching a virtual machine with QEMU/KVM. After resizing the qcow2 disk image via

qemu-img resize Test.qcow2 +500M

And looking at the instance disk via:

fdisk -l

inside the instance, I can see the following warning message:

GPT PMBR size mismatch (17752063 != 19800063) will be corrected by w(rite).

I would like to write a script that automatically resize the partition to take up the maximal space available following the disk resize and then resize the file system. It looks like I need to fix this previous warning message first.

I successfully fixed that interactively via the parted utility, but I would like to do this in an automated way, something like:

  1. Fix the GPT PMBR size mismatch.
  2. Extend the partition.
  3. Extend the filesystem.

The parted utility has a --script flag but it doesn't help here since when this option is active, the parted utility simply skips the fix part and only output the partition table.

Number 2. and 3. are working fine. How can I automate number 1 (i.e. without prompting for any end user interaction ?)


The parted(8) man page sas that parted has a

-s, --script
  never prompts for user intervention

command line option. I would guess that you can use it with a script containing the relevant parted commands to do what you want.

  • I invoked parted /dev/vda print and then waited for the prompt to ask me whether or not I want to fix the table. If I issue the --script flag, the command does not ask me whether or not I want to fix the PMBR (it indeed shows that there is a problem, but that's it) and directly print me the partition table instead. Issuing parted --script /dev/vda print Fix doesn't work either. – thjso Jun 14 at 6:48

Yo guys I found a way using sgdisk. From sgdisk manual:

-e, --move-second-header
Move backup GPT data structures to the end of the disk. Use this option if you've added disks to a RAID array, thus creating a virtual disk with space that follows the backup GPT data structures. This command moves the backup GPT data structures to the end of the disk, where they belong.

So I just need to put:

sgdisk -e /dev/vda

in my bash script and it seems to work as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.