NFS Mounts in QEMU virtual machine

Source: Internet
Author: User
Tags bz2 chmod mkdir iptables git clone
In a virtual machine run by QEMU, it is often necessary to mount the NFS file system, configure it once in the Centeros 6.0 system, run a INITRAMFS in the virtual machine, and successfully mount NFS in it. The following is a record of the experimental steps.

First, establish the development environment
Yum Groupinstall "Development Tools"
Yum Install glibc-static

Second, install QEMU
Yum Install zlib
Yum Install SDL Sdl-devel
Yum Install Gnutls-devel
CD ~
wget http://wiki.qemu.org/download/qemu-0.15.1.tar.gz
Tar zxvf qemu-0.15.1.tar.gz
CD qemu-0.15.1
./configure; Make Make install
Note: "Out of memory" errors may occur during compilation, and you can try to add the makefile
CFLAGS + = $ (CFLAGS)-pipe
To solve.

third, make a INITRAMFS to start the virtual machine
CD ~
mkdir image
wget http://busybox.net/downloads/busybox-1.19.3.tar.bz2
Tar jxvf busybox-1.19.3.tar.bz2
CD busybox-1.19.3
Make Defconfig
Make Menuconfig
Build Options
--Build BusyBox as a static binary (no shared libs)
Make
Make install Config_prefix=~/image
CD ~/image
mkdir proc SYS Dev etc mnt
Mknod-m dev/console C 5 1
Mknod-m dev/null C 1 3
mkdir ETC/INIT.D
Emacs Etc/init.d/rcs
#!/bin/sh
MOUNT-T proc Proc/proc
Mount-t Sysfs Sysfs/sys
Mdev-s
chmod +x Etc/init.d/rcs
Emacs Etc/inittab
:: Sysinit:/etc/init.d/rcs
Tty1::askfirst:/bin/sh
Tty2::askfirst:/bin/sh
Tty3::askfirst:/bin/sh
Tty4::askfirst:/bin/sh
Tty5::askfirst:/bin/sh
Tty6::askfirst:/bin/sh
:: Restart:/sbin/init
:: Ctrlaltdel:/sbin/reboot
:: Shutdown:/bin/umount-a-R
MV LINUXRC Init
Find. | Cpio-o-H NEWC | gzip > ~/image.cpio.gz
Cd/usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.tar.bz2
Tar jxvf linux-2.6.34.tar.bz2
Ln-s linux-2.6.34 Linux
Cd/usr/src/linux
Make Menuconfig
Device Drivers
-Block Devices
--RAM block device support (using standalone INITRD)
Make
Make Modules_install
Qemu-kernel ARCH/X86/BOOT/BZIMAGE-INITRD ~/image.cpio.gz-vnc:1

Iv. Configure virtual bridges and tap devices to enable host and virtual machines to communicate

1. If the kernel does not support tap devices or virtual bridges, the kernel needs to be compiled. Center OS 6.0 is supported by default, so there is no need to compile the kernel.
Yum Install kernel
Yum Install Ncurses-devel
Device Drivers
-Network Device Support
--Universal Tun/tap device driver Support (TAP devices supported)
Networking Support
-Networking Options
-802.1d Ethernet Bridging (Virtual bridge support)
Note: Centeros has its own set of methods for compiling the kernel. See:

2. Install the relevant software and configure the virtual bridge and tap device.
Yum Install Brctl
Yum Install Tunctl
Emacs/etc/sysconfig/network-scripts/ifcfg-eth0
Device= "Eth0"
Bootproto= "DHCP"
Hwaddr= "00:0c:29:20:dc:25"
Nm_controlled= "Yes"
onboot= "Yes"
Bridge= "Br0"
Emacs/etc/sysconfig/network-scripts/ifcfg-br0
Device= "Br0"
Type= "Bridge"
Bootproto= "DHCP"
onboot= "Yes"
Emacs/etc/qemu-ifup
#!/bin/sh
If [-N "$"];then
Brctl addif br0 tap0
Ifconfig tap0 0.0.0.0 up
Exit 0
Else
echo "Error:no interface Specified"
Exit 1
Fi
Emacs/etc/qemu-ifdown
#! /bin/sh
If [-N "$"];then
Ifconfig tap0 Down
Brctl Delif br0 tap0
Exit 0
Else
echo "Error:no interface Specified"
Exit 1
Fi
chmod +x/etc/qemu-ifup
chmod +x/etc/qemu-ifdown

3. Test the connectivity of the virtual machine to the host.
You first need to shut down the host's firewall:
/etc/init.d/iptables stop
Chkconfig iptables off
To adjust the virtual machine Initramfs content to support DHCP clients:
CD ~/image
CP ~/busybox-1.19.3/examples/udhcp/simple.script Usr/share/udhcpc/default.script
Find. | Cpio-o-H NEWC | gzip > ~/image.cpio.gz
The virtual machine core needs to be programmed with at least one NIC driver:
Cd/usr/src/linux
Make Menuconfig
Device drivers
-Network Device Support
-Ethernet (1000Mbit)
--Intel (R) pro/1000 Gigabit Ethernet Support (Intel 82540em,qemu default NIC)
Device drivers
-Network Device Support
-Ethernet (100Mbit)
--AMD PCnet32 PCI Support (PCNET32)
Make
Make Modules_install
Qemu-kernel arch/x86/boot/bzimage-initrd ~/image.cpio.gz-net nic-net tap,ifname=tap0-vnc:1
In the virtual machine, enter:
Ifconfig eth0 0.0.0.0 up
Udhcpc-i eth0

v. Mount NFS in a virtual machine

First install and set up the NFS server in the host

Yum Install Nfs-utils
Emacs/etc/exports
/192.168.0.0/24 (Rw,no_root_squash)
/etc/init.d/nfs start
Chkconfig NFS On
Support for NFS clients in the virtual machine kernel needs to be compiled:
Cd/usr/src/linux
Make Menuconfig
File Systems
-Network File Systems
--NFS Client Support
Make
Make Modules_install
Qemu-kernel arch/x86/boot/bzimage-initrd ~/image.cpio.gz-net nic-net tap,ifname=tap0-vnc:1
In the virtual machine, enter:
Ifconfig eth0 0.0.0.0 up
Udhcpc-i eth0
Mount-t nfs-o nolock 192.168.0.24://mnt
MOUNT-T proc Proc/mnt/proc
Mount-t Sysfs Sysfs/mnt/sys
Mount-v-o Bind/mnt/dev Dev
Chroot/mnt/bin/bash--login


Reference documents
1. I need to Build a Custom Kernel
2. Proficient in Initramfs building step by step
3. Installing the QEMU virtual machine

4. The QEMU virtual machine communicates with the external network


build embedded Linux kernel environment-run an arm Linux system on QEMU


purpose of this article:

Build the embedded Linux kernel learning environment and run the Linux system on a PC (Linux) QEMU virtual machine for further debugging later.

This article describes the content:

To run a QEMU virtual machine on a Linux host, simulate the arm versatile platform, and start the Linux system on that platform


This article outlines:

1. Installing Toolchain
2. Install Qemu
3. Build Linux Kernel
4. Prepare root filesystem
5. Start QEMU



1. Installing Toolchain

1). Open the following page:
http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

2). Select Arm Processors->download the Gnu/linux Release in supported processors

3). Fill in the name, Email, country information, click ' Get Lite '. The download address will be sent to the email

4). In the email click Download Address, open the download page click "Download sourcery codebench Lite 2011.09-70"

5). In the list of packages, select IA32 gnu/linux Installer in recommended packages, The Arm-2011.09-70-arm-none-linux-gnueabi.bin will be downloaded and the file can be run directly from the GUI installation. (You can also choose to install the TAR package in the advanced packages itself, but it's easy to run the graphical interface, no need to consider too many settings)

6). Run in Shell
$./arm-2011.09-70-arm-none-linux-gnueabi.bin
Start the graphical installation interface and follow the prompts to install.

7). After the installation is complete, verify in the shell that the arm-none-linux-gnueabi-command is valid.
(If you choose to install Codesourcery to the user's home directory in the installation, path will be automatically added to the user's bash profile, and you can rerun bash profile to enable Codesourcery's path.) [Centos:source ~/.bash_profile, Ubuntu:source ~/.profile]

2. Install QEMU

1). Open http://wiki.qemu.org/Download, download qemu-1.0.1.tar.gz

2). Unzip the tar package and compile Qemu-system-arm:
$tar ZXVF qemu-1.0.1.tar.gz
$CD qemu-1.0.1
$./configure--target-list=arm-softmmu--prefix=/usr/local/(must specify Target-list, otherwise all arch type binary will be compiled)
$make; make install

3). Confirm that the Qemu-system-arm command is valid in the shell


3. Build Linux kernel

1). Download kernel source code from kernel.org
Method 1: Get the TAR package directly:
$wget www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.7.tar.gz
$tar ZXVF linux-2.6.33.7.tar.gz
Method 2: Use git:
$git Clone Http://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
$git checkout-b v2.6.33.7 v2.6.33.7 #<---will create v2.6.33.7 branch

2). Configure, compile kernel
Enter the kernel directory
$make Mrproper #清除所有配置和编译产生的文件
$make arch=arm versatile_defconfig # using the default configuration of versatile
$make arch=arm Menuconfig # make minor changes
Select the "Use the ARM EABI to compile the kernel" option in kernel feature. Save exit.
$make arch=arm cross_compile=arm-none-linux-gnueabi-#开始编译

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.