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
  • Please get into the habit of saying "$RAW_FILE" or "${RAW_FILE}" instead of ${RAW_FILE}.
    – Scott
    Jun 20 at 20:03
  • No I'll write whatever is written shell script. Jun 21 at 17:29

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.



-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. [...]




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:


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.

  • I got confused with EXT4 which the shell script mentioned some place. Couldn't find 0x0C there. Anyways, well explained answer.
    – mrigendra
    Jun 20 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?
    – Scott
    Jun 20 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 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.