芯片主控: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=1echo "#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 FORMATSsfdisk supports two input formats and generic header lines.Header linesThe 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-idSpecify 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 formatstart size type bootablewhere 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 beoctal, decimal or hexadecimal; decimal is the default. When a field is absent, empty or specified as '-' a default value is used. But when the -Noption (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 is1 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 inbytes.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 thenumber 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 anumber to enlarge the partition as much as possible. Note '+' is equivalent to the default behaviour for a new partition; existing partitions will beresized 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 GPTE extended partition; means 5 for MBRH home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPTX linux extended partition; means 85 for MBR.The default type value is Lbootable is specified as [*|-], with as default not-bootable. The value of this field is irrelevant for Linux - when Linux runs it has been bootedalready - but ir might play a role for certain boot loaders and for other operating systems.Named-fields formatThis format is more readable, robust, extendible and allows to specify additional information (e.g. a UUID). It is recommended to use this format tokeep 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. Thisfunctionality 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=numberThe 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 inbytes.size=numberSpecify the partition size in sectors. The number may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB andYiB), then it's interpreted as size in bytes and the size is aligned according to device I/O limits.bootableMark the partition as bootable.attrs=stringPartition attributes, usually GPT partition attribute bits. See --part-attrs for more details about the GPT-bits string format.uuid=stringGPT partition UUID.name=stringGPT partition name.type=codeA hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition. For backward compatibility the Id= field has thesame meaning.BACKING UP THE PARTITION TABLEIt 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.dumpThis can later be restored by:sfdisk /dev/sda < sda.dumpIf 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 datafrom the device. Note that the same concept of backup files is used by wipefs(8). For example:sfdisk --backup /dev/sdaThe GPT header can later be restored by:dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda seek=$((0x00000200)) bs=1 conv=notruncNote that sfdisk since version 2.26 no longer provides the -I option to restore sectors. dd (1) provides all necessary functionality.COLORSImplicit 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.welcomeThe welcome message.NOTESSince 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.ENVIRONMENTSFDISK_DEBUG=allenables sfdisk debug output.LIBFDISK_DEBUG=allenables libfdisk debug output.LIBBLKID_DEBUG=allenables libblkid debug output.LIBSMARTCOLS_DEBUG=allenables libsmartcols debug output.SEE ALSOfdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)AUTHORKarel Zak <kzak@redhat.com>The current sfdisk implementation is based on the original sfdisk from Andries E. Brouwer.AVAILABILITYThe sfdisk command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.util-linux