Linux下sfdisk分区命令

来源:互联网 发布:船舶软件 编辑:程序博客网 时间:2024/06/01 22:13
sfdisk [options] device …

常用选项:
-s [or --show-size]: 显示一个分区的大小
-c [or --id]: 显示或者修改文件系统类型ID
-l [or --list]: 显示每个设备的分区表信息
-d [or --dump]: 同上,但是以一个格式化的方式输出
-i [or --increment]: number cylinders etc. from 1 instead of from 0
-uS, -uB, -uC, -uM: 以扇面/块/柱面数/MB为单位 显示或形成报告
-T [or --list-types]:显示所有已知的sfdisk能辨识的文件系统ID
-D [or --DOS]: 兼容DOS但是会浪费一点磁盘空间
-R [or --re-read]: 让内核重新读取分区表
-N# : 只改变分区的编号 #
-n : 修改但实际上并没有保存到磁盘
-O file : 保存扇面修改并写入分区表文件
-I file : 重新恢复修改的扇面

危险的选项:
-g [or --show-geometry]: print the kernel’s idea of the geometry
-G [or --show-pt-geometry]: print geometry guessed from the partition table
-x [or --show-extended]: also list extended partitions on output
or expect descriptors for them on input
-L [or --Linux]: do not complain about things irrelevant for Linux
-q [or --quiet]: suppress warning messages
You can override the detected geometry using:
-C# [or --cylinders #]:set the number of cylinders to use  //设置要使用的气缸数
-H# [or --heads #]: set the number of heads to use   //设置要使用的磁头数
-S# [or --sectors #]: set the number of sectors to use   //设置要使用的扇区数

柱面大小=512*256(磁头数)*64(扇区)

eg.

#!/bin/sh
export LANG=C
export LANGUAGE=en

device="/dev/mmcblk0"

PC_HIBERNATE=32
PC_ROOTFS=112
PC_PRODUCT=32
PC_DATA=224
PC_LOG=32
PC_VR=150
PC_BACKUP=16
PC_MAP=3000
PC_EXTEND=$((${PC_DATA}+${PC_LOG}+${PC_VR}+${PC_BACKUP}+${PC_MAP}))
PC_TOTAL=$((${PC_HIBERNATE}+${PC_ROOTFS}+${PC_PRODUCT}+${PC_EXTEND}))
FORMAT_P9=1

FMT_HIB="0xA0"
FMT_FAT="0x0C"
FMT_LINUX="0x83"
FMT_EXTEND="0x05"

if [ -e "/dev/mmcblk0p9" ]; then
    echo "/dev/mmcblk0p9 is exist"
    FORMAT_P9=0
fi

execute ()
{
    $* >/dev/null
    if [ $? -ne 0 ]; then
        echo
        echo "ERROR: executing $*"
        echo
        exit 1
    fi
}

#echo "************************************************************"
#echo "*         THIS WILL DELETE ALL THE DATA ON $device          "
#echo "*                                                          *"
#echo "*         Press <ENTER> to confirm....                     *"
#echo "************************************************************"
#read junk

{
echo ,${PC_HIBERNATE},${FMT_HIB},-
echo ,${PC_ROOTFS},${FMT_LINUX},-
echo ,${PC_PRODUCT},${FMT_LINUX},-
echo ,${PC_EXTEND},${FMT_EXTEND},-
echo ,${PC_DATA},${FMT_LINUX},-
echo ,${PC_LOG},${FMT_LINUX},-
echo ,${PC_VR},${FMT_LINUX},-
echo ,${PC_BACKUP},${FMT_LINUX},-
echo ,${PC_MAP},${FMT_LINUX},-
} | sfdisk -D -H 255 -S 63 -C ${PC_TOTAL} ${device}

echo "Formatting ${device}p2"
execute "mkfs.ext4 -L rootfs -b 4096 -j ${device}p2"
execute "tune2fs -c 0 -i 0 ${device}p2"

echo "Formatting ${device}p3"
execute "mkfs.ext4 -L product -b 4096 -j ${device}p3"
execute "tune2fs -c 0 -i 0 ${device}p3"

echo "Formatting ${device}p5"
execute "mkfs.ext4 -L external -b 4096 -j ${device}p5"
execute "tune2fs -c 0 -i 0 ${device}p5"

echo "Formatting ${device}p6"
execute "mkfs.ext4 -L log -b 4096 -j ${device}p6"
execute "tune2fs -c 0 -i 0 ${device}p6"

echo "Formatting ${device}p7"
execute "mkfs.ext4 -L vr -b 4096 -j ${device}p7"
execute "tune2fs -c 0 -i 0 ${device}p7"

echo "Formatting ${device}p8"
execute "mkfs.ext4 -L backup -b 4096 -j ${device}p8"
execute "tune2fs -c 0 -i 0 ${device}p8"

if [ $FORMAT_P9 -eq 1 ];then
echo "Formatting ${device}p9"
execute "mkfs.ext4 -L map -b 4096 -j ${device}p9"
execute "tune2fs -c 0 -i 0 ${device}p9"
else
echo "FORMAT_P9=${FORMAT_P9},skip Formatting ${device}p9"
fi


原创粉丝点击