Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

364
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda