Here's an example that an automated tool uses to resize a partition online, in one run:
sgdisk -d 1 -n 1:2048:0 -c 1: -u
1:E485F29F-A1F4-4953-9DD8-799EAEA0119B -t 1:0700 /dev/xvda
Here's list of options to sgdisk command:
- -d 1 delete's first partition
- -n 1:2048:0 says create new partition "number 1", with starting sector 2048. End sector = "0" which means "use all available space for this partition
- -u sets unique guid for that partition (this is specific for GPT partitions); you could use 'R' for GUID to be set to a random value. You could also get current partitions's id through
gdisk /dev/xvda; p output to reuse the same uid
- -t 1:0700 basically means first partition is of typecode '0700'.
/dev/xvda was the disk which we repartitioned.
So it deletes and creates a new partition on its place right away.
PS. A few notes on typecode '0700'. From man SGDISK(8)
Change a single partition's type code. You enter the type code using either a two-byte hexadecimal number, as
described earlier, or a fully-specified GUID value, such as
Found best explanation for what '0700' means here - http://www.rodsbooks.com/gdisk/walkthrough.html
"But wait," you say, "I thought the disk had a FAT partition!" Indeed
it does. Windows uses a single GUID code for all its data partitions,
be they FAT or NTFS. In the past, the same code has been used in Linux
for its data partitions. (More on this shortly....) Thus, in this case
several different MBR codes are all translated into a single GPT GUID
code. GPT fdisk uses, somewhat arbitrarily, the 0x0700 code (or more
precisely, EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) for all of these.
In my case I believe that was a Linux ext4 partition, but partition's typecode doesn't mean filesystem type, so '0700' looks more like a catchall type for sgdisk. At least in cases I've seen.
PPS. You may need to run
partprobe for kernel to become aware of the partitioning change without rebooting system.