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 defaultsfdiskcommand 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, thensfdiskstarts 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,--activatedevice [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-sectorsdeviceโ Back up the current partition table sectors in binary format and exit. See the BACKING UP THE PARTITION TABLE section. ๐ฆ--deletedevice [partition-number...]โ Delete all or the specified partitions. bye bye ๐-d,--dumpdeviceโ Dump the partitions of a device in a format that is usable as input tosfdisk. 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-geometryhave the same meaning as this one.-J,--jsondeviceโ Dump the partitions of a device in JSON format. Note thatsfdiskis 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-attrsdevice 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-labeldevice partition-number [label]โ Change the GPT partition name (label). If label is not specified, then print the current partition label. ๐ท๏ธ--part-typedevice 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-uuiddevice partition-number [uuid]โ Change the GPT partition UUID. If uuid is not specified, then print the current partition UUID.--disk-iddevice [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-freedeviceโ Discard any unused (unpartitioned) sectors on the device. Use the--list-freeoption to get a list of the free regions. See alsoblkdiscard(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,--reorderdeviceโ 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 ofblockdev(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 ๐--relocateoper 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-Ninstead.-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 beauto,neveroralways, and if you just don't say anything it defaults toauto. colors can be disabled โ for the current built-in default, check the--helpoutput. 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 beyes(1),no(0), ornonblock. omit mode and it defaults toyes. 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 withsystemd-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-rereadif 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-Nso 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 thefsync(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--helpto 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 are512,1024,2048, and4096. 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-sizecommand.-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 todos. that default may be overridden by the"label: <name>"script-header line. and no,--labeldoes 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 beauto,neveroralways. when this option isn't given, the default isauto, 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'tnever. also,automode does not wipe the first sector (boot sector); you needalwaysmode to wipe that area. in all cases, detected signatures are reported by warning messages before a new partition table is created. see also thewipefs(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 beauto,neveroralways. when this option isn't given, the default isauto, 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 thewipefs(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 issectors. that's it, that's the whole menu.labelโ pick your partition table type. likedosorgpt. iconic choices honestly.label-idโ the partition table identifier. it should be a hexadecimal number (with a0xprefix) 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--forceis 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 is1MiBand 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 thesector-sizeheader 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; means83for MBR and0FC63DAF-8483-4772-8E79-3D69D8477DE4for GPT.Sโ alias'swap'. swap area; means82for MBR and0657FD6D-A4AB-43C4-84E5-0933C84B4F4Ffor GPT.Exโ alias'extended'. MBR extended partition; means05for MBR. the original shortcut'E'is deprecated due to collision with the0x0EMBR partition type. ๐Hโ alias'home'. home partition; means933AC7E1-2EB4-4F13-B844-0E14E2AEF915for GPT.Uโ alias'uefi'. EFI System partition, meansEFfor MBR andC12A7328-F81F-11D2-BA4B-00A0C93EC93Bfor GPT.Rโ alias'raid'. Linux RAID; meansFDfor MBR andA19D880F-05FC-4D3B-A006-743F0F84911Efor GPT.Vโ alias'lvm'. LVM; means8Efor MBR andE6D6D379-F507-44C2-A23C-238F2A3DF928for 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 is1 MiB. if the offset is followed by the multiplicative suffixes (KiB,MiB,GiB,TiB,PiB,EiB,ZiBandYiB), 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,ZiBandYiB), 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-attrsfor more details about the GPT-bits string format.uuid=stringโ GPT partition UUID.name=stringโ GPT partition name.type=codeโ a hexadecimal number (without0x) 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, theId=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-Ioption 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 arecompactfor JSON output with minimal whitespace, andlinesfor 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--lockfor 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