简体   繁体   中英

Bash - Why doesn't sfdisk work in this script?

UPDATE : As per suggestions, I have asked this question of the Superuser community. I told them you say hi ;)

https://superuser.com/questions/1193808/why-doesnt-this-sfdisk-script-work

This has been a painful process. Perhaps there's something simple I'm missing..?

I'm trying to create a script to automatically partition a disk with a gpt table and 1 partition that takes up all the space. Should be super simple and straight forward..

I found the sfdisk command which is the (supposedly) script-friendly version of fdisk.

The best I've got so far is:

sfdisk --color=always --wipe always --no-reread --no-act --label gpt /dev/sdc

There's the matter of the partition type, which is to be Linux Filesystem (is that a good choice for a data drive?). The GUID for that is 0FC63DAF-8483-4772-8E79-3D69D8477DE4

When I run the above command, I get an interactive prompt. This is a bit of a problem for my script ;)

What of the input/output format described in the man pages?

<name>: <value>, <name>: <value>, ...

It seems to be suggesting I do something like:

echo 'label: gpt' | --color=always --wipe always --no-reread --no-act /dev/sdc

but, alas, that fails harder than the above. :(

Partitioning /dev/sdc...

Disk /dev/sdc: 2.7 TiB, 3000592982016 bytes, 5860533168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes

>>> line 1: unsupported command

New situation: Leaving.

Then there's the dumpfile I caught wind of in the depths of the man pages. It seems to suggest that I can create these cursed things, cat them, and pipe to sfdisk. (Un?)fortunately, I can't hardcode most of this so the solution won't work for me:

label: gpt
label-id: 236AEC41-D407-4FE5-94FA-8550C2CA10B5
device: /dev/sdc
unit: sectors
first-lba: 2048
last-lba: 5860533134

/dev/sdc1 : start=        2048, size=  5860531087, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4,uuid=8D7D48B0-8BF5-4383-B0EC-615C0E8AF4B4

What am I doing wrong!? Thanks :)

I found a better way: sgdisk

sgdisk --clear $blkdev
sgdisk --new=0:0:0 --typecode=0:0FC63DAF-8483-4772-8E79-3D69D8477DE4 $blkdev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM