mke2fs - create an ext2/ext3/ext4 filesystem
e2fsck - check a Linux ext2/ext3/ext4 file system
mkfs - build a Linux filesystem
他会调用如下一些工具来制作文件系统:
mkfs.f2fs,mkfs.bfs, mkfs.ext2, mkfs.ext3, mkfs.ext4, mkfs.minix, mkfs.msdos, mkfs.vfat, mkfs.xfs
fsck - check and repair a Linux filesystem
支持fsck.f2fs, fsck.ext2 or fsck.ext3, cramfsck, fsck.minix, fsck.msdos, fsck.jfs, fsck.nfs, fsck.vfat
Android平台上使用如下命令:
out/host/linux-x86/bin$ ./make_f2fs --help
Usage: mkfs.f2fs [options] device [sectors]
[options]:
-a heap-based allocation [default:0]
-c [device path] up to 7 devices excepts meta device
-d debug level [default:0]
-e [cold file ext list] e.g. "mp3,gif,mov"
-E [hot file ext list] e.g. "db"
-f force overwrite the exist filesystem
-g add default options
-i extended node bitmap, node ratio is 20% by default
-l label
-m support zoned block device [default:0]
-o overprovision ratio [default:5]
-O feature1[feature2,feature3,...] e.g. "encrypt"
-q quiet mode
-R root_owner [default: 0:0]
-s # of segments per section [default:1]
-S sparse mode
-t 0: nodiscard, 1: discard [default:1]
-w wanted sector size
-z # of sections per zone [default:1]
-V print the version number and exit
向一个空的f2fs文件镜像中添加文件:
$ sload_f2fs
Usage: sload.f2fs [options] device
[options]:
-C fs_config
-f source directory [path of the source directory]
-p product out directory
-s file_contexts
-S sparse_mode
-t mount point [prefix of target fs path, default:/]
-T timestamp
-d debug level [default:0]
-V print the version number and exit
android userdata.img的生成:
build/make/tools/releasetools/build_image.py \
$(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
build_image.py会解析userdata_image_info.txt,并最后调用mkf2fsuserimg来制作userdata.img,格式为F2FS文件系统:
elif fs_type.startswith("f2fs"):
build_command = ["mkf2fsuserimg.sh"]
build_command.extend([out_file, prop_dict["image_size"]])
if fs_config:
build_command.extend(["-C", fs_config])
build_command.extend(["-f", in_dir])
if target_out:
build_command.extend(["-D", target_out])
if "selinux_fc" in prop_dict:
build_command.extend(["-s", prop_dict["selinux_fc"]])
build_command.extend(["-t", prop_dict["mount_point"]])
if "timestamp" in prop_dict:
build_command.extend(["-T", str(prop_dict["timestamp"])])
build_command.extend(["-L", prop_dict["mount_point"]])
实际运行命令,我进行了一下简化,如下所示:
mkf2fsuserimg.sh IMAGE/userdata.img 8318382080 -f ./input_dir -s META/file_contexts.bin -t data -T 1230768000 -L data
它的各个选项的含义如下所示:
Usage:
mkf2fsuserimg.sh OUTPUT_FILE SIZE
[-C FS_CONFIG] [-f SRC_DIR] [-D PRODUCT_OUT]
[-s FILE_CONTEXTS] [-t MOUNT_POINT] [-T TIMESTAMP]
[-L LABEL]
最后这个脚本会调用如下的命令,简化一下的结果如下:
make_f2fs -S 48318382080 -g android -l data IMAGE/userdata.img
sload_f2fs -S -f ./input_dir -s META/file_contexts.bin -t /data -T 1230768000 IMAGE/userdata.img
这两个命令分别是用于创建一个f2fs的镜像,以及向这个镜像中添加文件。