1

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 ?)

thjso
  • 11
  • 4

2 Answers2

1

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.

user9517
  • 114,104
  • 20
  • 206
  • 289
  • 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 '19 at 06:48
0

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.

thjso
  • 11
  • 4