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=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總結
- 上一篇: 关于微PE的那些事和重装系统
- 下一篇: hrbust/哈理工oj 2220 强