Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
Bash script with fdisk

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!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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 #1
    • 1 indicates that it should start at sector #1
    • the following blank line accepts the default end sector
  • w writes changes to disk.
over 4 years ago · Santiago Trujillo Report

0

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
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!