fsdisk 分区

芯片主控:imx6q
http://lornyin.top/?p=545

昨天在做一个linux嵌入式项目时要修改板子的分区,查看了ucl2.xml (mfgtool)文件后,找到了他的分区脚本

#!/bin/sh

# partition size in MB
BOOT_ROM_SIZE=10


# call sfdisk to create partition table
# destroy the partition table
node=$1
dd if=/dev/zero of=${node} bs=1024 count=1

echo "#change test"

sfdisk --force -uM ${node} << EOF
${BOOT_ROM_SIZE},500,0c
600,,83
,5000,83
EOF

我们具体来看看sfdisk这一段,网上百度sfdisk发现都是一些比较常见的用法,很少有写到EOF这种用法,于是决定查看官方文档,

man sfdisk

发现输出信息太多,我们把输出结果重定向一个文件

man sfdisk > sfdisk

把输出结果输出到了一个名字叫sfdisk的文本文件中

然后我们来分析下他的分区脚本
这里写图片描述

红框部分是分区参数,每一行为一个分区,上面代码建立的3个分区,我们参考sfdisk文档来分析下几个参数

在151(man sfdisk > sfdisk 的文件)行起,有对参数的说明,一行有4个参数,分别是 开始地址、大小、分区类型、bootable

开始地址就不多说了,我们看看后面3个参数,

大小:

大小这个参数默认值是尽可能大的一个值,如果写成

echo "#change test"

sfdisk --force -uM ${node} << EOF
${BOOT_ROM_SIZE},500,0c
600,,83
EOF

就表示第二个分区大小为剩下空间大小,指定大小可以带上单位,用乘法加后缀 KiB, MiB, GiB, TiB, PiB, EiB, ZiB ,YiB

分区类型:

默认值为L (83),代表linux分区,MBR为83

S (82),代表swap分区

E (5), 代表扩展分区

H (933), 代表home分区

X (85) , 代表linux扩展分区

bootable:

这里的参数会将分区标记为可引导。大家可以套用0c参数,脚本这里的0c标记了第一个分区为可引导分区

更多的信息大家可以参考下help信息,老夫能力有限,这些足够我使用了,就没有再进一步探究

INPUT FORMATS
       sfdisk supports two input formats and generic header lines.

       Header lines
              The optional header lines specify generic information that apply to the partition table.  The header-line format is:

                     <name>: <value>

              The currently recognized headers are:

                     unit   Specify the partitioning unit.  The only supported unit is sectors.

                     label  Specify the partition table type.  For example dos or gpt.

                     label-id
                            Specify the partition table identifier.  It should be a  hexadecimal number (with a 0x prefix) for MBR and a UUID for GPT.

              Note that it is only possible to use header lines before the first partition is specified in the input.

       Unnamed-fields format

                     start size type bootable

              where each line fills one partition descriptor.

              Fields are separated by whitespace, comma or semicolon possibly followed by whitespace; initial and trailing  whitespace  is  ignored.   Numbers  can  be
              octal,  decimal  or  hexadecimal;  decimal  is  the default.  When a field is absent, empty or specified as '-' a default value is used.  But when the -N
              option (change a single partition) is given, the default for each field is its previous value.

              The default value of start is the first non-assigned sector aligned according to device I/O limits.  The default start offset for the first partition  is
              1  MiB. The offset may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted as offset in
              bytes.

              The default value of size indicates "as much as possible"; i.e. until the next partition or end-of-device.  A numerical argument  is  by  default  inter‐
              preted as a number of sectors, however if the size is followed by one of the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the
              number is interpreted as the size of the partition in bytes and it is then aligned according to the device I/O limits.  A '+' can be used  instead  of  a
              number  to  enlarge  the partition as much as possible.  Note '+' is equivalent to the default behaviour for a new partition; existing partitions will be
              resized as required.

              The partition type is given in hex for MBR (DOS), without the 0x prefix, a GUID string for GPT, or a shortcut:

                     L      Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.

                     S      swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT

                     E      extended partition; means 5 for MBR

                     H      home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT

                     X      linux extended partition; means 85 for MBR.

              The default type value is L

              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 ir might play a role for certain boot loaders and for other operating systems.

       Named-fields format
              This  format  is  more  readable, robust, extendible and allows to specify additional information (e.g. a UUID).  It is recommended to use this format to
              keep your scripts more readable.

                     [device :] name[=value], ...

              The device field is optional.  sfdiskextracts the partition number from the device name.  It allows to specify the  partitions  in  random  order.   This
              functionality is mostly used by --dump.  Don't use it if you are not sure.

              The value can be between quotation marks (e.g. name="This is partition name").  The currently supported fields are:

                     start=number
                            The  first non-assigned sector aligned according to device I/O limits.  The default start offset for the first partition is 1 MiB. The off‐
                            set may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted as offset  in
                            bytes.

                     size=number
                            Specify  the  partition  size in sectors.  The number may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and
                            YiB), then it's interpreted as size in bytes and the size is aligned according to device I/O limits.

                     bootable
                            Mark the partition as bootable.

                     attrs=string
                            Partition attributes, usually GPT partition attribute bits.  See --part-attrs for more details about the GPT-bits string format.

                     uuid=string
                            GPT partition UUID.

                     name=string
                            GPT partition name.

                     type=code
                            A hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition.  For backward compatibility the Id=  field  has  the
                            same meaning.

BACKING UP THE PARTITION TABLE
       It is recommended to save the layout of your devices.  sfdisk supports two ways.

       Use the --dump option to save a description of the device layout to a text file.  The dump format is suitable for later sfdisk input.  For example:

              sfdisk --dump /dev/sda > sda.dump

       This can later be restored by:

              sfdisk /dev/sda < sda.dump

       If  you  want  to  do  a  full  (binary)  backup  of  all  sectors  where the partition table is stored, then use the --backup option.  It writes the sectors to
       ~/sfdisk-<device>-<offset>.bak files.  The default name of the backup file can be changed with the --backup-file option.  The backup files contain only raw data
       from the device.  Note that the same concept of backup files is used by wipefs(8).  For example:

              sfdisk --backup /dev/sda

       The GPT header can later be restored by:

              dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda seek=$((0x00000200)) bs=1 conv=notrunc

       Note that sfdisk since version 2.26 no longer provides the -I option to restore sectors.  dd (1) provides all necessary functionality.

COLORS
       Implicit coloring can be disabled by an empty file /etc/terminal-colors.d/sfdisk.disable.

       See terminal-colors.d(5) for more details about colorization configuration. The logical color names supported by sfdisk are:

       header The header of the output tables.

       warn   The warning messages.

       welcome
              The welcome message.

NOTES
       Since version 2.26 sfdisk no longer provides the -R or --re-read option to force the kernel to reread the partition table.  Use blockdev --rereadpt instead.

       Since  version  2.26  sfdisk  does  not  provide  the  --DOS, --IBM, --DOS-extended, --unhide, --show-extended, --cylinders, --heads, --sectors, --inside-outer,
       --not-inside-outer options.

ENVIRONMENT
       SFDISK_DEBUG=all
              enables sfdisk debug output.

       LIBFDISK_DEBUG=all
              enables libfdisk debug output.

       LIBBLKID_DEBUG=all
              enables libblkid debug output.

       LIBSMARTCOLS_DEBUG=all
              enables libsmartcols debug output.

SEE ALSO
       fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)

AUTHOR
       Karel Zak <kzak@redhat.com>

       The current sfdisk implementation is based on the original sfdisk from Andries E. Brouwer.

AVAILABILITY
       The sfdisk command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.

util-linux
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值