I updated my OS to Ubuntu GNOME 15.10 but now I have a huge issue : sfdisk doesn't work!

I really need it to build partitions on my SD cards for an embedded Linux but it seems that the options changed. How to do to keep it working?

Here is the script I use :


unset LANG

umount ${CARD_DEV}* >& /dev/null

if [ -b "$CARD_DEV" ] ; then
    echo "*************** Formatting SD card... ***************"
    dd if=/dev/zero of=$CARD_DEV bs=1024 count=1024
    SIZE=`fdisk -l $CARD_DEV | grep Disk | awk '{print $5}'`
    echo DISK SIZE - $SIZE bytes
    CYLINDERS=`echo $SIZE/255/63/512 | bc`
        echo 1,9,0x0C,*
        echo 10,,,-
    } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $CARD_DEV
    mkfs.vfat -F 32 -n "boot" ${CARD_DEV}1
    mke2fs -j -L "filesystem" ${CARD_DEV}2

And I get :

sfdisk: invalid option -- 'D'

 sfdisk [options] <dev> [[-N] <part>]
 sfdisk [options] <command>

Display or manipulate a disk partition table.

 -A, --activate <dev> [<part> ...] list or set bootable MBR partitions
 -d, --dump <dev>                  dump partition table (usable for later input)
 -g, --show-geometry [<dev> ...]   list geometry of all or specified devices
 -l, --list [<dev> ...]            list partitions of each device
 -s, --show-size [<dev> ...]       list sizes of all or specified devices
 -T, --list-types                  print the recognized types (see -X)
 -V, --verify                      test whether partitions seem correct

 --part-label <dev> <part> [<str>] print or change partition label
 --part-type <dev> <part> [<type>] print or change partition type
 --part-uuid <dev> <part> [<uuid>] print or change partition uuid
 --part-attrs <dev> <part> [<str>] print or change partition attributes

 <dev>                     device (usually disk) path
 <part>                    partition number
 <type>                    partition type, GUID for GPT, hex for MBR

 -a, --append              append partitions to existing partition table
 -b, --backup              backup partition table sectors (see -O)
     --bytes               print SIZE in bytes rather than in human readable format
 -f, --force               disable all consistency checking
     --color[=<when>]      colorize output (auto, always or never)
                             colors disabled by default
 -N, --partno <num>        specify partition number
 -n, --no-act              do everything except write to device
     --no-reread           do not check whether the device is in use
 -O, --backup-file <path>  override default backup file name
 -o, --output <list>       output columns
 -q, --quiet               suppress extra info messages
 -X, --label <name>        specify label type (dos, gpt, ...)
 -Y, --label-nested <name> specify nested label type (dos, bsd)

 -L, --Linux               deprecated, only for backward compatibility
 -u, --unit S              deprecated, only sector unit is supported

 -h, --help     display this help and exit
 -v, --version  output version information and exit

Available columns (for -o):
 gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID
 dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S
 bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize
 sgi: Device Start End Sectors Cylinders Size Type Id Attrs
 sun: Device Start End Sectors Cylinders Size Type Id Flags

For more details see sfdisk(8).


sfdisk from util-linux 2.26.2
  • And what are the error messages? – Jodka Lemon Nov 10 '15 at 14:29
  • sfdisk: invalid option -- 'D' – didil Nov 10 '15 at 14:30
  • 2
    The man page says Since version 2.26 sfdisk ... no longer provides any functionality for CHS (Cylinder- Head-Sector) addressing. CHS has never been important for Linux, and this addressing concept does not make any sense for new devices. – Mark Plotnick Nov 10 '15 at 15:42
  • OK this what I feared. I do not know the alternatives to fix it quickly. The man page isn't up to date. – didil Nov 10 '15 at 15:54

Sounds like good news to me. Less code is better code.


# exit if any command fails
set -e


if [ ! -b "$CARD_DEV" ] ; then
    echo $CARD_DEV is not a block device
    exit 1

# so hopefully this will abort e.g. if we're about to blow away the root filesystem
for mounted in $(findmnt -o source | grep "^$CARD_DEV") ; do
    umount "$mounted"

echo "*************** Formatting SD card... ***************"
wipefs --all $CARD_DEV
    echo "$((1 * 63 * 255)), $((9 * 63 * 255)), 0x0C, *"
    echo "$((10 * 63 * 255)), , , -"
} | sfdisk $CARD_DEV
mkfs.vfat -F 32 -n "boot" ${CARD_DEV}1
mke2fs -j -L "filesystem" ${CARD_DEV}2
  • I ran this script verbatim and got the following error: mkfs.fat 3.0.28 (2015-05-16) mkfs.vfat: Too few blocks for viable filesystem – linsek Sep 1 '16 at 20:51
  • aha, excellent. I suspect the problem with my untested script, is that sfdisk was using cylinders, like fdisk used to, and now it's using sectors (512 bytes). Can you try multiplying the numbers in the first two columns of sfdisk input by 255 * 63 ? Btw I suspect this geometry is terrible and SD cards might not be very pleased with it. If you don't need an exact size then nowadays you should always round to at least the nearest 1MiB. – sourcejedi Sep 1 '16 at 22:11
  • I ended up modifying the arguments to fdisk as follows: { echo 63,144585,0x0C,* echo 144585,,,-} | sfdisk ... – linsek Sep 6 '16 at 19:31

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.