title: How to script automatic task with parted (update gpt table)
body: <p>I would like to script the extension of a existing partition on my Debian 9.9. </p>
  
  <p>I can do it simply with the interactive mode of parted but i would like to automatize it. In the example below I just need to manually write 'Fix' but i want to script it.</p>
  
  <pre><code>root@localhost:~# parted -l
  Model: Linux device-mapper (linear) (dm)
  Disk /dev/mapper/backup: 38.9GB
  Sector size (logical/physical): 512B/512B
  Partition Table: loop
  Disk Flags: 
  
  Number  Start  End     Size    File system  Flags
   1      0.00B  38.9GB  38.9GB  xfs
  
  
  Model: Linux device-mapper (linear) (dm)
  Disk /dev/mapper/data: 38.9GB
  Sector size (logical/physical): 512B/512B
  Partition Table: loop
  Disk Flags: 
  
  Number  Start  End     Size    File system  Flags
   1      0.00B  38.9GB  38.9GB  xfs
  
  
  Warning: Not all of the space available to /dev/vda appears to be used, you can
  fix the GPT to use all of the space (an extra 20971520 blocks) or continue with
  the current setting? 
  Fix/Ignore?                    
  </code></pre>
  
  <p>I would like to know which command is executed when I type 'Fix'. From what i understood it may be just a reload of the GPT table, so I have try to execute the command partprobe:</p>
  
  <pre><code>root@localhost:~# partprobe 
  Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current setting? 
  root@localhost:~# 
  </code></pre>
  
  <p>But here no options are proposed. I have taken a look in the help of parted and there is a 'script mode', i have tried the following but it didn't work:</p>
  
  <pre><code>root@localhost:~# parted -s /dev/vda print Fix
  Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current setting? 
  Model: Virtio Block Device (virtblk)
  Disk /dev/vda: 118GB
  Sector size (logical/physical): 512B/512B
  Partition Table: gpt
  Disk Flags: 
  
  Number  Start   End     Size    File system  Name  Flags
   1      17.4kB  1018kB  1000kB                     bios_grub
   2      1018kB  451MB   450MB   ext3
   3      451MB   10.5GB  10.0GB  xfs
   8      29.6GB  107GB   77.8GB
  
  Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
  Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
  interactive mode.
  
  OPTIONs:
    -h, --help                      displays this help message
    -l, --list                      lists partition layout on all block devices
    -m, --machine                   displays machine parseable output
    -s, --script                    never prompts for user intervention
    -v, --version                   displays the version
    -a, --align=[none|cyl|min|opt]  alignment for new partitions
  
  COMMANDs:
    align-check TYPE N                        check partition N for TYPE(min|opt) alignment
    help [COMMAND]                           print general help, or help on COMMAND
  [...]
  </code></pre>
  
  <p>I have also tried this bash script:</p>
  
  <pre><code>#!/bin/bash
  (echo Fix; echo print list; echo quit) | parted /dev/vda print free
  </code></pre>
  
  <p>But it did not worked, i have also tried this but it didn't help nether:</p>
  
  <pre><code>**root@localhost:~# cat /tmp/2.sh** 
  
  select /dev/vda
  print 
  Fix
  </code></pre>
  
  <p>And then pipe it into parted:</p>
  
  <pre><code>parted &lt; /tmp/2.sh
  </code></pre>