分区磁盘映像文件

Sha*_*jee 5 fedora partition parted

我想使用以下命令对原始磁盘映像进行分区:

#creating the blank image
$ dd if=/dev/zero of=example.img bs=1M count=50

#write the partition table
$ parted example.img mktable msdos

#creating partition but not the file system
#creating fat32 primary partition 1 to 15 MB
$ parted example.img mkpart p fat32 1 15
#creating ext3 primary partition 16 to end
$ parted example.img mkpart p ext3 16 -0
Run Code Online (Sandbox Code Playgroud)

这些命令不会创建文件系统。我怎么能那样做?我正在尝试mkfs命令,parted但它显示没有找到命令。如何在外部创建文件系统?

Jod*_*e C 7

使用该命令kpartx创建一个环回设备,然后可以对其进行格式化。

kpartx -a /path/to/imagefile.img  # Presents partitions from the image file
mkfs.vfat /dev/mapper/loop0p1   # Format partition 1
mkfs.ext3 /dev/mapper/loop0p2   # Format partition 2
kpartx -d /path/to/imagefile.img  # Unmaps the partitions from the image file
Run Code Online (Sandbox Code Playgroud)

相关 kpartx 示例在这里