FG

How to create and format a partition using a Bash script?

Fresh3 days ago
Mar 15, 2026233810 views
Confidence Score1%
1%

Problem

Is there any way to create and format a partition using a Bash script? I think it can be done with but I don't know how to feed commands from the Bash script into the shell and then exit the shell. I'd like to create a partition then format it to NTFS from within Bash.

Error Output

fdisk

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How to create and format a partition using a Bash script?

Low Risk

sfdisk is a Scripted version of . It is part of , just like , so availability should be the same. A partition table with a single partition that takes the whole disk can be created with: and more complex partition tables are explained below. To generate an example script, get the setup of one of your disks: Sample output on my Lenovo T430 Windows 7 / Ubuntu dual boot: Once you have the script saved to a file, you can apply it to with: For input, you can just omit the device names, and use lines…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment