带Fdisk的Bash脚本

Ele*_*eli 5 linux bash

在使用Packer制作的ami使根卷变大之后,我遇到了这个bash脚本来扩展fs。有人可以在heredoc中解释fdisk选项的含义吗?

#!/bin/bash
fdisk /dev/xvda <<EEOF
d
n
p
1
1

w
EEOF
exit 0
Run Code Online (Sandbox Code Playgroud)

谢谢!

Cha*_*ffy 2

要确定这些含义,请查看 的内置帮助fdisk。详细信息可能会根据您的实施情况而有所不同;对于我来说,看起来像这样:

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
Run Code Online (Sandbox Code Playgroud)

...所以:

  • d删除一个分区(大概您的脚本是为一个版本开发的fdisk,如果只有一个分区,则不会提示删除哪个分区)。
  • n创建一个新分区。
    • p表示正在创建主分区。
    • 1表明它应该是主分区#1
    • 1表示它应该从扇区 #1 开始
    • 下面的空行接受默认的结束扇区
  • w将更改写入磁盘。