将grub2安装到qemu上

本文详细介绍了如何在Ubuntu 14.04上使用QEMU创建、虚拟化、分区、格式化、挂载及启动磁盘文件的过程,包括使用dd命令创建磁盘文件、losetup命令虚拟化磁盘、fdisk命令分区、mkfs.ext4命令格式化磁盘、mount命令挂载磁盘、grub安装以及最终运行QEMU启动磁盘。

环境:ubuntu14.04 qemu-2.0.0

1.创建磁盘文件
sudo dd if=/dev/zero of=disk.img bs=4096 count=8192

2.将磁盘文件虚拟为循环块设备
sudo losetup /dev/loop1 disk.img

3.对磁盘文件分区
sudo fdisk /dev/loop1
命令执行结果:
命令(输入 m 获取帮助): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认为 1):
将使用默认值 1
起始 sector (2048-65535,默认为 2048):
将使用默认值 2048
Last sector, +扇区 or +size{K,M,G} (2048-65535,默认为 65535):
将使用默认值 65535
命令(输入 m 获取帮助): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 22: 无效的参数.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
4.对磁盘文件格式化
sudo mkfs.ext4 /dev/loop1
命令执行结果:
mke2fs 1.42.9 (4-Feb-2014)
Discarding device blocks: 完成
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
8192 inodes, 32768 blocks
1638 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33554432
4 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
5.挂载磁盘文件到本地文件系统
sudo mount /dev/loop1 /mnt

6.创建启动目录
sudo mkdir /mnt/boot

7.安装grub2到启动目录
sudo grub-install –boot-directory=/mnt/boot –force dev/loop1
命令执行结果:
Installing for i386-pc platform.
grub-install: warning: File system `ext2’ doesn’t support embedding.
grub-install: warning: 无法嵌入。在此次安装中 GRUB 只能通过使用块列表安装。但是块列表是不可信赖的,不推荐使用。
Installation finished. No error reported.

8.解挂载
sudo umount /mnt

9.解设备虚拟
sudo losetup -d /dev/loop1

10.运行启动qemu
sudo qemu-system-i386 -hda disk.img

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值