SFDISK(8)

๐ŸŽ€ SFDISK(8) ๐ŸŽ€

okay bestie, so this is sfdisk, from the System Administration corner of the manual (section 8, iykyk โ€” that's where the sysadmin baddies live). It's giving partition-table royalty. Let's get into it. ๐Ÿ’…


โœจ NAME โœจ

sfdisk โ€” display or manipulate a disk partition table


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

sfdisk [options] device [-N partition-number]

sfdisk [options] command

๐Ÿ’– DESCRIPTION ๐Ÿ’–

sfdisk is a script-oriented tool for partitioning any block device, no cap. And the way it decides how to behave? If you run it on a terminal (meaning stdin refers to a terminal), it justโ€ฆ goes interactive on you. Slay.

Since version 2.26 sfdisk supports MBR (DOS), GPT, SUN and SGI disk labels โ€” but it no longer provides any functionality for CHS (Cylinder-Head-Sector) addressing. And honestly? CHS has never been important for Linux, and that whole addressing concept does not make any sense for new devices. It's giving obsolete. Periodt.

sfdisk protects the first disk sector when create a new disk label. The option --wipe always disables this protection. Note that fdisk(8) and cfdisk(8) completely erase this area by default โ€” so yeah, sfdisk is the careful one here. ๐Ÿซถ

sfdisk (since version 2.26) aligns the start and end of partitions to block-device I/O limits when relative sizes are specified, when the default values are used, or when multiplicative suffixes (e.g., MiB) are used for sizes. Heads up though: it is possible that partition size will be optimized (reduced or enlarged) due to alignment if the start offset is specified exactly in sectors and partition size relative or by multiplicative suffixes.

The recommended way is not to specify start offsets at all and specify partition size in MiB, GiB (or so). In this case sfdisk aligns all partitions to block-device I/O limits (or when I/O limits are too small then to megabyte boundary to keep disk layout portable). If this default behaviour is unwanted (usually for very small partitions) then specify offsets and sizes in sectors. In this case sfdisk entirely follows specified numbers without any optimization. No vibes-based rounding, just your numbers exactly as typed. โœจ

sfdisk does not create the standard system partitions for SGI and SUN disk labels like fdisk(8) does. It is necessary to explicitly create all partitions including whole-disk system partitions. You're on your own for those, bestie โ€” main character energy means doing it yourself. ๐Ÿ’ช

sfdisk uses BLKRRPART (reread partition table) ioctl to make sure that the device is not used by system or other tools (see also --no-reread). It's possible that this feature or another sfdisk activity races with systemd-udevd(8). The recommended way how to avoid possible collisions is to use the --lock option. The exclusive lock will cause systemd-udevd to skip the event handling on the device. ๐Ÿ‘‘

The sfdisk prompt is only a hint for users and a displayed partition number does not mean that the same partition table entry will be created (if -N not specified), especially for tables with gaps. Don't trust the prompt with your whole heart, okay? It's a hint, not a promise. ๐Ÿ˜ญ


๐ŸŒˆ COMMANDS ๐ŸŒˆ

okay so these are mutually exclusive โ€” pick one, don't be greedy. ๐Ÿ’…


  • [-N, --partno partition-number] device โ€” The default sfdisk command is to read the specification for the desired partitioning of device from standard input, and then create a partition table according to the specification. See below for the description of the input format. If standard input is a terminal, then sfdisk starts an interactive session.

If the option -N or --partno is specified, then the changes are applied to the partition addressed by partition-number. The unspecified fields of the partition are not modified.

Note that it's possible to address an unused partition with -N. For example, an MBR always contains 4 partitions, but the number of used partitions may be smaller. In this case sfdisk follows the default values from the partition table and does not use built-in defaults for the unused partition given with -N. See also --append.

  • -A, --activate device [partition-number...] โ€” Switch on the bootable flag for the specified partitions and switch off the bootable flag on all unspecified partitions. The special placeholder - may be used instead of the partition numbers to switch off the bootable flag on all partitions.

The activation command is supported for MBR and PMBR only. If a GPT label is detected, then sfdisk prints warning and automatically enters PMBR. Surprise plot twist, but it's a polite one. ๐Ÿ™ˆ

If no partition-number is specified, then list the partitions with an enabled flag.

  • --backup-pt-sectors device โ€” Back up the current partition table sectors in binary format and exit. See the BACKING UP THE PARTITION TABLE section. ๐Ÿ“ฆ
  • --delete device [partition-number...] โ€” Delete all or the specified partitions. bye bye ๐Ÿ’€
  • -d, --dump device โ€” Dump the partitions of a device in a format that is usable as input to sfdisk. See the BACKING UP THE PARTITION TABLE section.
  • -g, --show-geometry [device...] โ€” List the geometry of all or the specified devices. For backward compatibility the deprecated option --show-pt-geometry have the same meaning as this one.
  • -J, --json device โ€” Dump the partitions of a device in JSON format. Note that sfdisk is not able to use JSON as input format. It's a one-way street, bestie. ๐Ÿšซ
  • -l, --list [device...] โ€” List the partitions of all or the specified devices. This command can be used together with --verify.
  • -F, --list-free [device...] โ€” List the free unpartitioned areas on all or the specified devices. Gaps found. ๐Ÿ•ต๏ธ
  • --part-attrs device partition-number [attributes] โ€” Change the GPT partition attribute bits. If attributes is not specified, then print the current partition settings. The attributes argument is a comma- or space-delimited list of bits numbers or bit names. For example, the string "RequiredPartition,50,51" sets three bits. The currently supported attribute bits are:
    • Bit 0 (RequiredPartition) โ€” If this bit is set, the partition is required for the platform to function. The creator of the partition indicates that deletion or modification of the contents can result in loss of platform features or failure for the platform to boot or operate. The system cannot function normally if this partition is removed, and it should be considered part of the hardware of the system. Like, genuinely do not touch this one.
    • Bit 1 (NoBlockIOProtocol) โ€” EFI firmware should ignore the content of the partition and not try to read from it.
    • Bit 2 (LegacyBIOSBootable) โ€” The partition may be bootable by legacy BIOS firmware.
    • Bits 3-47 โ€” Undefined and must be zero. Reserved for expansion by future versions of the UEFI specification.
    • Bits 48-63 โ€” Reserved for GUID specific use. The use of these bits will vary depending on the partition type. For example Microsoft uses bit 60 to indicate read-only, 61 for shadow copy of another partition, 62 for hidden partitions and 63 to disable automount.
  • --part-label device partition-number [label] โ€” Change the GPT partition name (label). If label is not specified, then print the current partition label. ๐Ÿท๏ธ
  • --part-type device partition-number [type] โ€” Change the partition type. If type is not specified, then print the current partition type.

The type argument is hexadecimal for MBR, GUID for GPT, type alias (e.g. "linux") or type shortcut (e.g. 'L'). For backward compatibility the options -c and --id have the same meaning as this one.

  • --part-uuid device partition-number [uuid] โ€” Change the GPT partition UUID. If uuid is not specified, then print the current partition UUID.
  • --disk-id device [id] โ€” Change the disk identifier. If id is not specified, then print the current identifier. The identifier is UUID for GPT or unsigned integer for MBR.
  • --discard-free device โ€” Discard any unused (unpartitioned) sectors on the device. Use the --list-free option to get a list of the free regions. See also blkdiscard(8).
โš ๏ธ Warning โš ๏ธ All data in the discarded regions on the device will be lost! Do not use this option if you are unsure.

Note that the 'T' command in fdisk provides a dialog to specify which unused area should be discarded. However, sfdisk always discards all unpartitioned regions (except for the areas where it is not possible to create partitions, such as the beginning of the device). It does not do dialogs, it does the whole thing. ๐Ÿ”ฅ

  • -r, --reorder device โ€” Renumber the partitions, ordering them by their start offset.
  • -s, --show-size [device...] โ€” List the sizes of all or the specified devices in units of 1024 byte size. This command is DEPRECATED in favour of blockdev(8). It's giving legacy, bestie. ๐Ÿซ 
  • -T, --list-types โ€” Print all supported types for the current disk label or the label specified by --label.
  • -V, --verify [device...] โ€” Test whether the partition table and partitions seem correct. vibe check ๐Ÿ’…
  • --relocate oper device โ€” Relocate partition table header. This command is currently supported for GPT header only. The argument oper can be:
    • gpt-bak-std โ€” Move GPT backup header to the standard location at the end of the device.
    • gpt-bak-mini โ€” Move GPT backup header behind the last partition. Note that UEFI standard requires the backup header at the end of the device and partitioning tools can automatically relocate the header to follow the standard.

โœจ OPTIONS โœจ

okay bestie, this is the big one โ€” every single flag sfdisk will let you throw at it. no skipping, no skimming, we're doing all of them ๐Ÿ’…


  • -a, --append โ€” don't make a brand new partition table, just append the partitions you asked for onto whatever's already there. tiny heads up tho: an unused partition can get re-used in this mode even if it's not the last one in the table ๐Ÿ‘€ so if you need to aim at one specific entry, go look at -N instead.
  • -b, --backup โ€” backs up the current partition table sectors before you start partitioning, so you have a lil safety net ๐Ÿซถ. default file name is ~/sfdisk-<device>-<offset>.bak, and if you want a different name you want option -O, --backup-file. more deets live in the BACKING UP THE PARTITION TABLE section.
  • --bytes โ€” prints SIZE in raw bytes instead of that human-readable format. no vibes, just numbers.
  • --color[=when] โ€” colorizes the output ๐ŸŒˆ. the optional when arg can be auto, never or always, and if you just don't say anything it defaults to auto. colors can be disabled โ€” for the current built-in default, check the --help output. also see the COLORS section.
  • -f, --force โ€” disables all consistency checking. all of it. zero checks. live your truth (carefully).
  • --Linux โ€” deprecated and ignored, bestie, it literally does nothing ๐Ÿ™ˆ. partitioning that's compatible with Linux (and other modern operating systems) is just the default now.
  • --lock[=mode] โ€” grabs an exclusive BSD lock on the device or file you're operating on ๐Ÿ”’. the optional mode arg can be yes (1), no (0), or nonblock. omit mode and it defaults to yes. this option overrides the environment variable $LOCK_BLOCK_DEVICE. the default is to not use any lock at all, but honestly using one is recommended so you don't collide with systemd-udevd(8) or other tools.
  • -n, --no-act โ€” does literally everything except actually writing to the device. dress rehearsal only โœจ.
  • --no-reread โ€” don't check through the re-read-partition-table ioctl whether the device is in use.
  • --no-tell-kernel โ€” doesn't tell the kernel about partition changes ๐Ÿ™Š. this one's recommended together with --no-reread if you're modifying a partition on a disk that's in use. the modified partition should not be used (e.g., mounted).
  • -O, --backup-file path โ€” overrides the default backup file name. heads up: the device name and offset are always appended to the file name no matter what you pick.
  • --move-data[=path] โ€” moves data after a partition relocation, like when you're moving the beginning of a partition somewhere else on the disk ๐Ÿšš. the partition size has to stay the same, and the new and old locations may overlap. this option requires option -N so it only gets processed on one specific partition.

the optional path is the log file name. that log file contains info about all read/write operations on the partition data. the magic word "@default" as a path forces sfdisk to use ~/sfdisk-<devname>.move for the log. the log is optional since v2.35.

note that this operation is risky and not atomic. don't forget to backup your data! ๐Ÿ˜ญ

see also --move-use-fsync.

in the example below, the first command creates a 100MiB free area before the first partition and moves the data it contains (e.g., a filesystem), the next command creates a new partition from the free space (at offset 2048), and the last command reorders partitions to match disk order (the original sdc1 will become sdc2).

echo '+100M,' | sfdisk --move-data /dev/sdc -N 1

echo '2048,' | sfdisk /dev/sdc --append

sfdisk /dev/sdc --reorder
  • --move-use-fsync โ€” uses the fsync(2) system call after each write when moving data to a new location via --move-data ๐Ÿ’พ.
  • -o, --output list โ€” picks which output columns get printed. use --help to get a list of all supported columns. the default list of columns may be extended if list is given in the format +list (e.g., -o +UUID).
  • -q, --quiet โ€” suppresses extra info messages ๐Ÿคซ.
  • --sector-size sectorsize โ€” sets the sector size of the disk. valid values are 512, 1024, 2048, and 4096. the kernel is already aware of the sector size for regular block devices, so only use this on very old kernels, when working with disk images, or to override the kernel's default sector size. since util-linux-2.17, fdisk distinguishes between logical and physical sector size โ€” and this option changes both of them to the specified sectorsize.
  • -u, --unit S โ€” deprecated option, bestie, it's giving legacy ๐Ÿ˜ฌ. only the sector unit is supported. this option is not supported when using the --show-size command.
  • -X, --label type โ€” sets the disk-label type (e.g., dos, gpt, ...). if you don't give this option, sfdisk defaults to the type of the existing label โ€” but if there's no label on the device yet, then the type defaults to dos. that default may be overridden by the "label: <name>" script-header line. and no, --label does not force sfdisk to create an empty disk label (peep the EMPTY DISK LABEL section below ๐Ÿ‘‡).
  • -Y, --label-nested type โ€” forces editing of a nested disk label. the primary disk label has to exist already. this lets you edit, for example, a hybrid/protective MBR on devices with GPT ๐Ÿงš.
  • -w, --wipe when โ€” wipes filesystem, RAID and partition-table signatures from the device so you don't get possible collisions ๐Ÿงน. the when arg can be auto, never or always. when this option isn't given, the default is auto, in which case signatures are wiped only when in interactive mode โ€” except the old partition-table signatures, which are always wiped before creating a new partition table if when isn't never. also, auto mode does not wipe the first sector (boot sector); you need always mode to wipe that area. in all cases, detected signatures are reported by warning messages before a new partition table is created. see also the wipefs(8) command.
  • -W, --wipe-partitions when โ€” wipes filesystem, RAID and partition-table signatures from a newly created partition so you don't get possible collisions ๐Ÿงฝ. the when arg can be auto, never or always. when this option isn't given, the default is auto, in which case signatures are wiped only when in interactive mode and after confirmation by the user. in all cases, detected signatures are reported by warning messages after a new partition is created. see also the wipefs(8) command.
  • -h, --help โ€” displays the help text and exits ๐Ÿ‘‹.
  • -v, --version โ€” displays the version and exits ๐Ÿ‘‘.

โœจ INPUT FORMATS โœจ

ok so sfdisk is not a one-format girlie ๐Ÿ’… she takes two input formats plus these little generic header lines that float at the top. Let's go through them one by one bestie, no skipping, I promise.

๐ŸŒธ Header lines ๐ŸŒธ

these are optional and they're just general info that applies to the whole partition table, not to any single partition. the format is literally:

<name>: <value>

and the headers that are currently recognized are:

  • unit โ€” pick your partitioning unit. the only supported unit is sectors. that's it, that's the whole menu.
  • label โ€” pick your partition table type. like dos or gpt. iconic choices honestly.
  • label-id โ€” the partition table identifier. it should be a hexadecimal number (with a 0x prefix) for MBR, and a UUID for GPT.
  • first-lba โ€” the first usable sector for GPT partitions. ๐Ÿซถ heads up though: this header gets ignored if the script and the device sector size differ. in that case sfdisk just uses the label-specific default.
  • last-lba โ€” the last usable sector for GPT partitions. also ignored if the script and device sector size differ, and again sfdisk falls back to the label-specific default. and one more: this one gets ignored if --force is specified, which is literally the whole point โ€” it makes the script usable on disks with different sizes.
  • table-length โ€” the maximal number of GPT partitions.
  • grain โ€” the minimal size in bytes used to calculate partition alignment. the default is 1MiB and it is strongly recommended to just use the default. like, do not touch this variable if you're not sure. fr fr. ๐Ÿ™ˆ
  • sector-size โ€” the sector size used in the input. sfdisk always internally uses the device sector size that the kernel hands over for the block device, or the one the user gave on the command line (peep --sector-size). starting with version 2.39, sfdisk recalculates sizes from the input if the sector-size header and the device sector size are different. slay.
โš ๏ธ note that it is only possible to use header lines before the first partition is specified in the input. once a partition shows up, that door is closed bestie.

๐Ÿ’– Unnamed-fields format ๐Ÿ’–

start size type bootable

where every single line fills in one partition descriptor. one line = one partition, cute and simple.

fields are separated by whitespace, comma (recommended, obviously), or semicolon, possibly followed by whitespace. initial and trailing whitespace is ignored, we're not judging. numbers can be octal, decimal or hexadecimal, and decimal is the default. when a field is absent, empty, or specified as -, a default value is used. but when the -N option (change a single partition) is given, the default for each field is its previous value. periodt.

the default value of start is the first non-assigned sector aligned according to the device I/O limits. the default start offset for the first partition is 1 MiB. if the offset is followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then the number is interpreted as an offset in bytes. since v2.38, when the -N option (change a single partition) is given, a + can be used to enlarge the partition by moving the start of the partition, if there is free space before the partition. โœจ

the default value of size means "as much as possible", i.e. until the next partition or the end-of-device. a numerical argument is by default interpreted as a number of sectors, however if the size is followed by one of the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted as the size of the partition in bytes, and it's then aligned according to the device I/O limits. a + can be used instead of a number to enlarge the partition as much as possible. note that + is equivalent to the default behaviour for a new partition; existing partitions will be resized as required.

the partition type is given in hex for MBR (DOS) where the 0x prefix is optional; a GUID string for GPT; a shortcut or an alias. it's recommended to use two letters for MBR hex codes to avoid collision between the deprecated shortcut E and the 0E MBR hex code. for backward compatibility, sfdisk tries to interpret type as a shortcut as a first possibility in partitioning scripts, although in other places (e.g. --part-type command) it tries shortcuts as the last possibility. messy? yes. that's just how it is bestie. ๐Ÿ’€

since v2.36 libfdisk supports partition type aliases as an extension to shortcuts. the alias is a simple human readable word (e.g. "linux").

since v2.37 libfdisk supports partition type names on input, ignoring the case of the characters and all non-alphanumeric and non-digit characters in the name (e.g. "Linux /usr x86" is the same as "linux usr-x86"). honestly? so forgiving of them.

Supported shortcuts and aliases:

  • L โ€” alias 'linux'. Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.
  • S โ€” alias 'swap'. swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT.
  • Ex โ€” alias 'extended'. MBR extended partition; means 05 for MBR. the original shortcut 'E' is deprecated due to collision with the 0x0E MBR partition type. ๐Ÿ‘€
  • H โ€” alias 'home'. home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT.
  • U โ€” alias 'uefi'. EFI System partition, means EF for MBR and C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT.
  • R โ€” alias 'raid'. Linux RAID; means FD for MBR and A19D880F-05FC-4D3B-A006-743F0F84911E for GPT.
  • V โ€” alias 'lvm'. LVM; means 8E for MBR and E6D6D379-F507-44C2-A23C-238F2A3DF928 for GPT.

the default type value is linux.

the shortcut 'X' for Linux extended partition (85) is deprecated in favour of 'Ex'.

bootable is specified as [*|-], with as default not-bootable. and honestly the value of this field is irrelevant for Linux โ€” when Linux runs it has been booted already ๐Ÿ’… โ€” but it might play a role for certain boot loaders and for other operating systems.


๐Ÿฆ‹ Named-fields format ๐Ÿฆ‹

this format is more readable, more robust, more extensible, and it lets you specify extra info (e.g., a UUID). it is recommended to use this format to keep your scripts more readable. main character format energy, truly.

[device :] name[=value], ...

the device field is optional. sfdisk extracts the partition number from the device name. it allows specifying the partitions in random order. this functionality is mostly used by --dump. don't use it if you are not sure. ๐Ÿซถ

the value can be between quotation marks (e.g., name="This is partition name"). the fields start= and size= support + and - in the same way as the Unnamed-fields format.

the currently supported fields are:

  • start=number โ€” the first non-assigned sector, aligned according to device I/O limits. the default start offset for the first partition is 1 MiB. if the offset is followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then the number is interpreted as an offset in bytes.
  • size=number โ€” the partition size in sectors. the number may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), and then it's interpreted as size in bytes, and the size is aligned according to device I/O limits.
  • bootable โ€” mark the partition as bootable.
  • attrs=string โ€” partition attributes, usually GPT partition attribute bits. see --part-attrs for more details about the GPT-bits string format.
  • uuid=string โ€” GPT partition UUID.
  • name=string โ€” GPT partition name.
  • type=code โ€” a hexadecimal number (without 0x) for an MBR partition, a GUID for a GPT partition, a shortcut as for the unnamed-fields format, or a type name (e.g. type="Linux /usr (x86)"). see above the section about the unnamed-fields format for more details. for backward compatibility, the Id= field has the same meaning.

๐ŸŽ€ EMPTY DISK LABEL ๐ŸŽ€

sfdisk does not create a partition table without partitions by default, nope. the lines with partitions are expected in the script by default. the empty partition table has to be explicitly requested by a "label: <name>" script header line without any partitions lines. for example:

echo 'label: gpt' | sfdisk /dev/sdb

that creates an empty GPT partition table. cute! note that the --append disables this feature though. ๐Ÿ˜ญ


๐Ÿ’œ BACKING UP THE PARTITION TABLE ๐Ÿ’œ

it is recommended to save the layout of your devices. like, please bestie, do it. sfdisk supports two ways.

โญ Dump in sfdisk compatible format โญ

use the --dump command to save a description of the device layout to a text file. the dump format is suitable for later sfdisk input. for example:

sfdisk --dump /dev/sda > sda.dump

and this can later be restored by:

sfdisk /dev/sda < sda.dump

note that sfdisk completely restores partition types and partition UUIDs. this could potentially become problematic if you duplicate the same layout to different disks, as it may result in duplicate UUIDs within your system. ๐Ÿ‘€ so watch out.

๐ŸŒˆ Full binary backup ๐ŸŒˆ

if you want to do a full binary backup of all sectors where the partition table is stored, then use the --backup-pt-sectors command. it writes the sectors to ~/sfdisk-<device>-<offset>.bak files. the default name of the backup file can be changed with the --backup-file option. the backup files contain only raw data from the device. for example:

sfdisk --backup-pt-sectors /dev/sda

the GPT header can later be restored by:

dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda
seek=$((0x00000200)) bs=1 conv=notrunc

it's also possible to use the --backup option to create the same backup immediately after startup for other sfdisk commands. for example, backing up the partition table before deleting all partitions from the partition table:

sfdisk --backup --delete /dev/sda

the same concept of backup files is used by wipefs(8). โœจ

โš ๏ธ note that sfdisk since version 2.26 no longer provides the -I option to restore sectors. dd(1) provides all necessary functionality. so that's a thing of the past, bestie.

๐ŸŒธ COLORS ๐ŸŒธ

the output colorization is implemented by terminal-colors.d(5) functionality. implicit coloring can be disabled by an empty file

/etc/terminal-colors.d/sfdisk.disable

for the sfdisk command, or for all tools by

/etc/terminal-colors.d/disable

since version 2.41, the $NO_COLOR environment variable is also supported to disable output colorization, unless it's explicitly enabled by a command-line option.

the user-specific $XDG_CONFIG_HOME/terminal-colors.d or $HOME/.config/terminal-colors.d overrides the global setting.

note that the output colorization may be enabled by default, and in this case the terminal-colors.d directories do not have to exist yet. she's ready to serve regardless. ๐Ÿ’…

the logical color names supported by sfdisk are:

  • header โ€” the header of the output tables.
  • warn โ€” the warning messages.
  • welcome โ€” the welcome message.

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

ok bestie these are the little environment variables that change how sfdisk talks to you. set them in your shell before you run anything and it's giving custom build โœจ

  • SFDISK_DEBUG=all โ€” turns on debug output for sfdisk itself. yes literally all of it ๐Ÿ’…
  • LIBFDISK_DEBUG=all โ€” turns on debug output for libfdisk.
  • LIBBLKID_DEBUG=all โ€” turns on debug output for libblkid.
  • LIBSMARTCOLS_DEBUG=all โ€” turns on debug output for libsmartcols.
  • LIBSMARTCOLS_DEBUG_PADDING=on โ€” use visible padding characters, so you can actually see the whitespace instead of being gaslit by it ๐Ÿ™ˆ
  • LIBSMARTCOLS_JSON=compact|lines โ€” controls the JSON output format when you're using --json. the supported values are compact for JSON output with minimal whitespace, and lines for JSON Lines format (one JSON object per line). if it's unset, or set to literally any other value, you get pretty-printed JSON instead. periodt.
  • LOCK_BLOCK_DEVICE=<mode> โ€” use exclusive BSD lock. the mode is "1" or "0". see --lock for more details ๐Ÿ‘‘

๐Ÿ“ NOTES ๐Ÿ“

ok so history lesson, and it's lowkey important:

since version 2.26, sfdisk no longer provides the -R or --re-read option to force the kernel to reread the partition table. like, it's gone gone. use blockdev --rereadpt instead. that's the move ๐Ÿซถ

also since version 2.26, sfdisk does not provide the --DOS, --IBM, --DOS-extended, --unhide, --show-extended, --cylinders, --heads, --sectors, --inside-outer, --not-inside-outer options. all of those? retired. archived. not coming back ๐Ÿ’€


โœจ EXAMPLES โœจ

these are the ones you're gonna actually screenshot and keep, ngl. every single one is here, exactly as it should be:

sfdisk --list --label-nested=mbr /dev/sda : print protective MBR on a device with a GPT disk label. cute little peek under the hood ๐Ÿ’–

echo -e ',10M,L\n,10M,L\n,+,\n' | sfdisk /dev/sdc : create three Linux partitions, with the default start, the size of the first two partitions is 10MiB, and the last partition fills all available space on the device. the + is the "take the rest bestie" energy ๐Ÿ”ฅ

echo -e ',10M,L\n,10M,L\n,+,\n' | sfdisk /dev/sdc

echo -e 'size=10M, type=L\n size=10M, type=L\n size=+\n' | sfdisk /dev/sdc : the same as the previous example, but in named-fields format. same result, different outfit ๐Ÿ’…

echo -e 'size=10M, type=L\n size=10M, type=L\n size=+\n' | sfdisk /dev/sdc

echo -e 'type=swap' | sfdisk -N 3 /dev/sdc : set the type of the 3rd partition to 'swap'. one line, one job, slayed โœจ

echo -e 'type=swap' | sfdisk -N 3 /dev/sdc

sfdisk --part-type /dev/sdc 3 swap : the same as the previous example, but without script use. no piping required, we're going direct ๐ŸŒธ

sfdisk --part-type /dev/sdc 3 swap

sfdisk --delete /dev/sdc 2 : delete the 2nd partition. bye girl ๐Ÿ‘‹

sfdisk --delete /dev/sdc 2

echo "+,+" | sfdisk -N 3 --move-data /dev/sdc : enlarge the 3rd partition in both directions โ€” move the start to use the free space before the partition, and enlarge the size to use all the free space after the partition, and move the partition data too. glow-up in two directions, main character energy fr fr ๐Ÿ‘‘

echo "+,+" | sfdisk -N 3 --move-data /dev/sdc

๐Ÿ’– AUTHORS ๐Ÿ’–

  • Karel Zak <kzak@redhat.com>

the current sfdisk implementation is based on the original sfdisk from Andries E. Brouwer. standing on the shoulders of legends, we love to see it ๐Ÿซถ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

the whole friend group, all iconic, all valid ๐ŸŒˆ


๐Ÿ› REPORTING BUGS ๐Ÿ›

found a bug? don't suffer in silence bestie. for bug reports, use the issue tracker at <https://github.com/util-linux/util-linux/issues>. they wanna hear it, no cap ๐Ÿ’œ


๐Ÿ“ฆ AVAILABILITY ๐Ÿ“ฆ

the sfdisk command is part of the util-linux package, which can be downloaded from the Linux Kernel Archive at <https://www.kernel.org/pub/linux/utils/util-linux/>. go get your girl ๐Ÿ’…


and that's a wrap on SFDISK(8) ๐ŸŽ€ this page is from util-linux 2.42.4, dated 2026-09-21 โ€” so if you're reading a different version, go check that manpage too, iykyk. stay partitioned, stay safe, and back up before you touch anything fr fr ๐Ÿ’–โœจ
๐Ÿ“ฆ where this page comes from
  • arch rolling: util-linux 2.42.4-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ISC AND LGPL-2.1-or-later AND LicenseRef-PublicDomain
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms