sfdisk 用法

sfdisk -f $device  >& /dev/null << EOF
$part1_offset,$part1_size,83,*           //第一分区:从$part1_offset开始,$part1_size个柱面,LINUX_NATIVE (83)类型,启动分区
,$part2_size,L,-                              //第二分区:接着上一个分区,$part2_size个柱面,LINUX_NATIVE (83)类型,非启动分区

,,E                                                       //剩余空间为扩展分区        E is EXTENDED_PARTITION (5)
,,L                                                       //扩展分区全部划成逻辑分区   
EOF

 

 

>& /dev/null : 重定向command 的stdout 到/dev/null

<< EOF   EOF : list string

sfdisk : -f force

reads lines of the form : <start> <size> <id> <bootable> <c,h,s> <c,h,s>

 

Fields are separated by whitespace, or comma or semicolon possibly followed 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 default value is used.

The <c,h,s> parts can (and probably should) be omitted - sfdisk computes them from <start> and <size> and the disk geometry as given by the kernel or specified using the -H, -S, -C flags.

Bootable is specified as [*|-], with as default not-bootable. (The value of this field is irrelevant for Linux - when Linux runs it has been booted already - but might play a role for certain boot loaders and for other operating systems. For example, when there are several primary DOS partitions, DOS assigns C: to the first among these that is bootable.)

Id is given in hex, without the 0x prefix, or is [E|S|L|X], where L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), E is EXTENDED_PARTITION (5) , and X is LINUX_EXTENDED (85).


分区实例:

 60 echo "[Partitioning $1...]"
 61 
 62 DRIVE=$1
 63 dd if=/dev/zero of=$DRIVE bs=1024 count=1024 &>/dev/null
 64 
 65 SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`             //检测多少字节
 66 
 67 echo DISK SIZE - $SIZE bytes
 68 
 69 CYLINDERS=`echo $SIZE/255/63/512 | bc`                          //计算多少柱面
 70 
 71 echo CYLINDERS - $CYLINDERS
 72 {
 73 echo ,9,0x0C,*
 74 echo ,$(expr $CYLINDERS / 4),,-
 75 echo ,$(expr $CYLINDERS / 4),,-
 76 echo ,,0x0C,-
 77 } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE &> /dev/null                //分区

。。。。。。。

 86 mkfs.vfat -F 32 -n boot ${DRIVE}1 &> /dev/null                                            //格式化
 87 mkfs.ext4 -L rootfs ${DRIVE}2 &> /dev/null
 88 mkfs.ext4 -L usrdata ${DRIVE}3 &> /dev/null
 89 mkfs.vfat -F 32 -n data ${DRIVE}4 &> /dev/null

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值