1

In this command what is happening? I tried to know but what are these numbers and parameters 2048,,0x0C,-?

sfdisk -u S -L -q ${RAW_FILE} 2>/dev/null << EOF
2048,,0x0C,-
EOF
3

2 Answers 2

1

sfdisk has a manual page that you even find online. It tells you this:

start size type bootable

Also, when a field is empty, the default value is assumed. So, echo , | sfdisk /dev/sdx creates a single, non-bootable Linux filesystem type (0x83) partition that spans the entire disk.

In your case, the partition starts at sector 2048, i.e. 1Mb, and ends at the end of the disk. The partition is of type 0xC, which means FAT filesystem.

1
1

ExplainShell.com:

-u, --unit letter

    Interpret the input and show the output in the units specified by letter.  This letter can be one of S, C, B or M, meaning Sectors, Cylinders, Blocks and Megabytes, respectively. The default is cylinders, at least when the geometry is known.

-L, --Linux

    Do not complain about things irrelevant for Linux.

-q, --quiet

    Suppress warning messages.

Essentially "use sectors as a unit and don't complain".

As for the input format, man sfdisk:

sfdisk has four (main) uses: list the size of a partition, list the partitions on a device, check the partitions on a device, and - very dangerous - repartition a device. [...]

List sizes
sfdisk -s partition gives the size of partition in blocks.

Your command doesn't use -s. Mode 2:

List partitions
The second type of invocation: sfdisk -l device will list the partitions on the specified device.

Your command doesn't use -l. Mode 3:

Check partitions
The third type of invocation: sfdisk -V device will apply various consistency checks to the partition tables on device.

Your command doesn't use -V, so we're left with the 4th mode:

Create partitions
The fourth type of invocation: sfdisk device will cause sfdisk to read the specification or the desired partitioning of device from standard input, and then to change the partition tables on that disk. [...]

BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST

[...]

INPUT FORMAT

sfdisk reads lines of the form

<start> <size> <id> <bootable> <c,h,s> <c,h,s>

where each line fills one partition descriptor.

Fields are separated by whitespace, or comma or semicolon possibly followed by whitespace; [...] When a field is absent or empty, a default value is used. [...]

Bootable is specified as [*|-], with as default not-bootable. [...]

The default value of size is as much as possible (until next partition or end-of-disk).

So your input:

2048,,0x0C,-

Will create a partition offset 2048 sectors, as large as possible, with ID 0C hexadecimal (FAT32) and with the bootable flag not set.

Exact offset will depend on sector size of the target drive. With the more common 512-byte sectors it will be 1 MiB.

The partition will not be automatically formatted as FAT32. It will only be marked as intended to be FAT32-formatted.


TL;DR: It's all in the manual.

3
  • I got confused with EXT4 which the shell script mentioned some place. Couldn't find 0x0C there. Anyways, well explained answer.
    – user424318
    Jun 20, 2021 at 13:09
  • I can’t find any documentation on this that doesn’t suck (I would suggest that [* | -], with an explanation, would be clearer than “[*|-]”), but my intuition would be that - in the fourth field (“bootable” flag) means non- bootable, and berndbausch’s answer says the same thing.  Are you sure that - means “with the bootable flag set”?  P.S.  I know the documentation says that “M” means Megabytes.  Do you happen to know (through experience, or through reading source code) whether that is correct, or is it Mebibytes? Jun 20, 2021 at 20:03
  • @Scott You're correct, - means not bootable. Corrected, thank you. Regarding the M unit, I've tried to check it on the latest GRML (the only ISO I have at hand at the moment) but in its version of sfdisk the -u option is deprecated and accepts only S.
    – gronostaj
    Jun 20, 2021 at 21:23

You must log in to answer this question.