I came across this bash script to expand the fs after making the root volume larger on an ami made with Packer. Can someone please explain the meaning of the fdisk options in the heredoc?
#!/bin/bash
fdisk /dev/xvda <<EEOF
d
n
p
1
1
w
EEOF
exit 0
Thank you!
To determine what these mean, look at the built-in help from fdisk
. Details may differ based on your implementation; for mine, that looks like this:
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
...so:
d
deletes a partition (presumably your script was developed for a version of fdisk
where if there's only one partition, there's no prompt over which to delete).n
creates a new partition.
p
indicates that it's a primary partition being created.1
indicates that it should be primary partition #11
indicates that it should start at sector #1w
writes changes to disk.Try this and adjust for your conditions:
#!/bin/bash
HEREDOC_VAR_1='p q '
echo $HEREDOC_VAR_1
HEREDOC_VAR_2='n q '
echo $HEREDOC_VAR_2
echo "$HEREDOC_VAR_1" | fdisk /dev/xvda
echo "$HEREDOC_VAR_2" | fdisk /dev/xvda
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With