linux-sfdisk用法说明

本文详细介绍了如何使用sfdisk命令创建磁盘分区表,包括分区大小的定义、分区类型的指定等关键步骤。通过具体实例展示了sfdisk命令的用法,并解释了输入格式的各个字段含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

[root@ /]#sfdisk --force -uM /dev/mmcblk1 << EOF
2> 0,256,83
2> 256,128,83
> 384,,83
E> EOF

 

( <start> <size> <id><bootable> <c,h,s> <c,h,s>)

 

#!/bin/sh

# partition size in MB

BOOT_ROM_SIZE=10   MBR数据区,10MB

ROOT_SYSTEM_SIZE=150

# call sfdisk to create partition table

# destroy the partition table

node=$1

dd if=/dev/zero of=${node} bs=1024 count=1 清除分区表MBR

sfdisk --force -uM ${node} << EOF

${BOOT_ROM_SIZE},${ROOT_SYSTEM_SIZE},83

,,83 将其他所有空间再分成一个区,,此处应该就是mmcblk0p2了。

EOF

83Linux分区标识

 

Ubootkernel是直接使用dd写入mmcblk0中的,而分区则是使用sfdisk进行的,空出了ubootkernel的位置,从起始地址10MB开始的。

 

INPUT FORMAT

      sfdisk reads lines of the form

             <start> <size> <id><bootable> <c,h,s> <c,h,s>

      where each line fills one partition descriptor.

 

      Fields are separated by whitespace, or comma or semicolon possiblyfollowed by whitespace; initial and trailing whitespace  is  ignored.  Numbers  can  be

      octal, decimal or hexadecimal, decimal is default.  When a field is absent or empty, a defaultvalue is used.

 

      The <c,h,s> parts can (and probably should) be omitted - sfdiskcomputes them from <start> and <size> and the disk geometry asgiven by the kernel or speci?

      fied using the -H, -S, -C flags.

 

      Bootable is specified as [*|-], with as default not-bootable.  (The value of this field is irrelevant forLinux - when Linux runs it has been booted already

      -  but  might play a role for certain boot loadersand for other operating systems.  Forexample, when there are several primary DOS partitions, DOS assigns

      C: to the first among these that is bootable.)

 

       Id is given inhex, without the 0x prefix, or is [E|S|L|X], where L (LINUX_NATIVE (83)) is thedefault, S is LINUX_SWAP (82), E is EXTENDED_PARTITION  (5),

       and X is LINUX_EXTENDED (85).

 

      The default value of start is the first nonassigned sector/cylinder/...

 

      The default value of size is as much as possible (until next partitionor end-of-disk).

 

      However, for the four partitions inside an extended partition, thedefaults are: Linux partition, Extended partition, Empty, Empty.

 

      But when the -N option (change a single partition only) is given, the defaultfor each field is its previous value

EXAMPLE

      The command

              sfdisk /dev/hdc << EOF

              0,407

              ,407

              ;

              ;

              EOF

      will partition /dev/hdc just as indicated above.

 

      The command

              sfdisk/dev/hdb << EOF

              ,3,L

              ,60,L

              ,19,S

              ,,E

              ,130,L

              ,130,L

              ,130,L

              ,,L

              EOF

      will  partition  /dev/hdb into two Linux partitions of 3 and60 cylinders, a swap space of 19 cylinders, and an extended partition coveringthe rest. Inside

      the extended partition there are four Linux logical partitions, three of130 cylinders and one covering the rest.

 

      With the -x option, the number of input lines must be a multiple of 4:you have to list the two empty partitions that you never want using twoblank  lines.

      Without  the -x option, you giveone line for the partitions inside a extended partition, instead of four, andterminate with end-of-file (^D).  (Andsfdisk

      will assume that your input line represents the first of four, that thesecond one is extended, and the 3rd and 4th are empty.

 注意: 在高版本内核版本执行如下命令后会报错报错sfdisk: unsupported unit ‘M’ , 是因为自己的linux-4.14.98版本过高;

[root@ /]#sfdisk --force -uM /dev/mmcblk1 << EOF

这种情况需要使用如下操作方法

[root@yeastar /]#sfdisk --force  /dev/mmcblk1 << EOF
,256M,83
,128M,83
,,83
EOF

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值