Linux 在脚本中用 ext4 分区填充磁盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12917678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fill a disk with an ext4 partition in a script
提问by Nicolas Barbey
I tried to use parted for scripted partitionning like so :
我尝试使用 parted 进行脚本分区,如下所示:
parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 -1
But it complains about -1 not being a recognized option. Still the same sub-command works in the parted prompt. So my question is how to use the same options in a script ?
但它抱怨 -1 不是公认的选项。同样的子命令在 parted 提示中仍然有效。所以我的问题是如何在脚本中使用相同的选项?
采纳答案by Nicolas Barbey
Finally found a solution :
终于找到了解决办法:
parted -s -a optimal /dev/sda mklabel gpt -- mkpart primary ext4 1 -1s
--
is very important for it to work here.
--
在这里工作非常重要。
Note the use of ‘--', to prevent the following ‘-1s' last-sector indicator from being interpreted as an invalid command-line option.
请注意“--”的使用,以防止以下“-1s”最后一个扇区指示符被解释为无效的命令行选项。
回答by shkschneider
I guess it's parted's argument parser's fault.
我想这是 parted 的参数解析器的错。
Try parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 \-1
or parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 \\-1
尝试parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 \-1
或parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 \\-1
回答by ?devrimbaris
You can also use --script option. In this case you should put your script part in single quotes.
您还可以使用 --script 选项。在这种情况下,您应该将脚本部分放在单引号中。
Example:
例子:
parted --script /dev/sda 'mkpart primary ext4 1 -1'