创建原始磁盘映像并将其以救援模式安装到 QEMU 时出现问题

创建原始磁盘映像并将其以救援模式安装到 QEMU 时出现问题

我正在尝试从原始磁盘映像创建引导系统。这就是我所做的:

$ dd if=/dev/zero of=system2.img bs=1M count=6000
6000+0 records in
6000+0 records out
6291456000 bytes (6.3 GB) copied, 69.3662 s, 90.7 MB/s
$ sudo fdisk system2.img
Command (m for help): o
Building a new DOS disklabel with disk identifier 0xdd22ed22.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): w
The partition table has been altered!

Syncing disks.
$ sudo fdisk system2.img

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-12287999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-12287999, default 12287999):
Using default value 12287999

Command (m for help): a
Partition number (1-4): 1

Command (m for help): w
The partition table has been altered!

Syncing disks.
$ sudo kpartx -avs system2.img
add map loop1p1 (252:0): 0 120832 linear /dev/loop1 2048
$ sudo mkfs.ext4 -U c0f21c98-ebf4-4f27-91b8-205da17c7893 /dev/mapper/loop1p1
mke2fs 1.42 (29-Nov-2011)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
15104 inodes, 60416 blocks
3020 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=61865984
8 block groups
8192 blocks per group, 8192 fragments per group
1888 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

然后我尝试使用此磁盘映像 QEMU 和救援模式(从 debian netinst ISO 启动)。它让我安装/dev/sda1,但失败了。从/var/log/syslog它看来就像看到了/dev/sda1FAT

我有另一个磁盘映像,适用于救援模式。我能发现它们之间的唯一区别是,如果我查看工作映像,cfdisk我会看到第一个分区类型为ext4.在失败的图像中它说Linux

答案1

显然存在一个错误kpartx。此命令序列有效:

$ sudo losetup --show --find system2.img
/dev/loop5
$ sudo kpartx -avs /dev/loop5

不应将磁盘映像文件直接提供给kpartx

在 Ubuntu 12.04 上测试

相关内容