嵌入式linux 用虚拟机,如何制作嵌入式Linux虚拟机

简介

本文介绍如何在ESXi虚拟化平台下,利用内核文件(bzImage)和内存文件(initrd.img)制作嵌入式Linux虚拟机模板。

虚拟机创建

可以通过vSphere Client来创建一个Linux虚拟机,其中一些选项:

1. Guest Operation System: Other Linux(32-bit)

2. Create a disk: 4GB Thin Provision

注:手工创建方法:

1. 通过vmkfstools创建虚拟磁盘

2. 通过vi编辑.vmx配置文件

3. vim-cmd solo/registervm注册虚拟机

创建分区和文件系统

将新创建的虚拟机磁盘添加到Ubuntu 9.04的虚拟机上,磁盘挂载在/dev/sdb上。用户创建时,将"/dev/sdb"修改相应的实际磁盘标识。

1. 通过"fdisk /dev/sdb"创建分区。最终作者创建的分区情况如下,其中/dev/sdb1设置为启动分区:

Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x94007daa

Device Boot Start End Blocks Id System

/dev/sdb1 * 1 9 72261 83 Linux

/dev/sdb2 10 18 72292+ 83 Linux

/dev/sdb3 19 27 72292+ 83 Linux

/dev/sdb4 28 522 3976087+ 5 Extended

/dev/sdb5 28 487 3694918+ 83 Linux

/dev/sdb6 488 522 281106 83 Linux2. 初始化文件系统

通过mkfs.ext4将相应的分区格式为ext4文件系统,如:

root@sv-changeme-desktop:/home/infinera# mkfs.ext4 /dev/sdb1

mke2fs 1.41.4 (27-Jan-2009)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

18072 inodes, 72260 blocks

3613 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67371008

9 block groups

8192 blocks per group, 8192 fragments per group

2008 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

root@sv-changeme-desktop:/home/infinera#

安装和配置GRUB

作者使用的GRUB版本为1.99,具体如何编译安装grub,见参考资料。

1. 安装GRUB

将启动分区/dev/sdb1挂载到/home/bob/sdb/boot。通过grub-install安装GRUB。

root@sv-changeme-desktop:~# mount /dev/sdb1 /home/bob/sdb/boot

root@sv-changeme-desktop:~# grub-install --no-floppy --root-directory=/home/bob/sdb/boot/ /dev/sdb

Installation finished. No error reported.2. 配置GRUB

进入/home/bob/sdb/boot/grub目录,通过grub-mkconfig命令生成grub.cfg缺省配置文件。用户可以根据自己需要编辑grub.cfg,并将自己的bzImage和initrd.img文件拷贝到/home/bob/sdb/boot目录下。

root@sv-changeme-desktop:/home/bob/sdb/boot/grub# grub-mkconfig -o grub.cfg

Generating grub.cfg ...

cat: /boot/grub/video.lst: No such file or directory

Found linux image: /boot/vmlinuz-2.6.28.9-custom

Found initrd image: /boot/initrd.img-2.6.28.9-custom

Found linux image: /boot/vmlinuz-2.6.28-11-generic

Found initrd image: /boot/initrd.img-2.6.28-11-generic

done

虚拟机上电

经过上面的步骤,Linux虚拟机创建完成(用户可以根据自己项目需要配置其它分区的内容)。后面就可以将虚拟机上电,测试Linux是否能够正常启动。

参考资料

1. GRUB编译与安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CarpVM 是一个用 C 语言编写的小型虚拟机。可以嵌入在应用程序中使用。 包含的指令集有: HALT (code): Halts and attempts to clean up stack, data memory, and label memory before exiting with given exit code. NOP (): Does nothing. Seriously. LOAD (reg, val): Loads given integer value into given register. MOV (dst, src): Copies contents of src register into dst register. ADD (): Pops the top two integers from the stack and pushes their sum. SUB (): Pops the top two integers from the stack and pushes the difference (lower minus upper). MUL (): Pops the top two integers from the stack and pushes their product. MOD (rega, regb): Computes rega % regb and stores in ERX. NOT (reg): Computes bitwise NOT of reg and stores in reg. XOR (): Pops the top two integers from the stack and XORs them. OR (): Pops the top two integers from the stack and ORs them. AND (): Pops the top two integers from the stack and ANDs them. INCR (reg): Increments value in given register. DECR (reg): Decrements value in given register. INC (): Increments the value at the top of the stack. DEC (): Decrements the value at the top of the stack. PUSHR (reg): Pushes value in given register. PUSH (val): Pushes given value. POP (val): Pops an integer from the stack and dumps it into GBG. CMP (): Pops the top two integers from the stack and checks if equal. 0 means equal. Result will be pushed onto the stack. MOV (rega, regb): Move value in rega to regb. JZ (addr): Jumps to given absolute address if top of the stack is 0. RJZ (diff): Adds differential to current EIP (relative jump) if top of the stack is 0. JNZ (addr): Jumps to given absolute address if top of the stack is not 0. RJNZ (diff): Adds differential to current EIP (relative jump) if top of the stack is not 0. JMP (addr): Jumps to given absolute address. RJMP (diff): Adds differential to current EIP (relative jump). DBS (key, val): Sets data memory at key (string pointer) to given value. DBG (key, reg): Gets value from data memory at key (string pointer) and dumps it into given register. CALL (key, nargs): Save state and set EIP to value in data memory at key. RET (val): Push return value and load state. PREG (reg): Prints contents of given register. PTOP (): Peeks top of stack and prints top value. 标签:CarpVM
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值