如何保持 sfdisk 正常工作?

如何保持 sfdisk 正常工作?

我已更新到 Ubuntu 15.10,但它给我带来了一个大问题:sfdisk 不再起作用。

我确实需要 sfdisk 在 SD 卡上为我的嵌入式 Linux 创建分区,但似乎选项已经改变。

这是我的脚本:

CARD_DEV=$1

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 CYLINDERS - $CYLINDERS
    {
        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
fi

输出错误:

sfdisk: invalid option -- 'D'

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

Display or manipulate a disk partition table.

Commands:
 -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

Options:
 -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
      Start-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

答案1

这似乎是该命令的一个工作版本,可以在新旧 sfdisk 版本中运行。

# p1 74MB FAT
# p2 Remainder Linux
sfdisk -u S -L $CARD_DEV << EOF
63,144522,0x0C,*
160650,,,-
EOF

“-u S”将单位设置为扇区,这是新版本中的默认设置,但在旧版本中需要设置

“-L” 可防止旧版本在创建分区时出错。

来源:https://e2e.ti.com/support/arm/sitara_arm/f/791/t/509510

相关内容