In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use QEMU to build Linux kernel development and debugging environment", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use QEMU to build a Linux kernel development and debugging environment.
1. Compile the kernel
The kernel needs to be compiled in advance, and the general kernel compilation method is shown here.
Select the general configuration file under the kernel directory:
Cp arch/x86/configs/x86_64_defconfig .config
Adjust the kernel configuration file to the current kernel version:
Make menuconfig
Compile the kernel file:
Make bzImage2. Generate root file system
This step is most important to generate a file system for the debug environment. Here are four methods.
2.1Creating busybox root file system (method 1)
Busybox is a lightweight collection of tools that includes init and most commonly used Linux tools. Official website: https://busybox.net.
The root file system compiled by this method is the smallest and the startup speed is the fastest. That is, there may be fewer tools that come with you, and some things need to be compiled by yourself.
2.1.1 create an image file
Create an image file in raw format:
Qemu-img create-f raw disk.raw 512Mmkfs-t ext4. / disk.raw
Mount the raw file to a temporary directory:
Sudo mount-o loop. / disk.raw. / img2.1.2 installation module
Go to the kernel directory and mount the modules in the kernel into the file system:
Sudo make modules_install\ # install kernel module INSTALL_MOD_PATH=./img # specify installation path 2.1.3 busybox
Download the source code for busybox, which needs to be configured before compilation. Busybox is configured in a similar way to the kernel:
Cd busyboxmake defconfigmake menuconfig
Adjust the following options to compile to include static libraries:
Busybox Settings->-Build Options [*] Build BusyBox as a static binary (no shared libs)
Then compile busybox, where path_to_disk_img_mount_point is the temporary directory where the raw file was mounted:
Make CONFIG_PREFIX= install2.1.4 creates system files
Configure the init environment:
Create three directories: etc/init.d, dev, proc and sys manually under the root directory.
/ etc/inittab:
: sysinit:/etc/init.d/rcS::askfirst:/bin/ash::ctrlaltdel:/sbin/reboot::shutdown:/sbin/swapoff-a::shutdown:/bin/umount-a-r::restart:/sbin/init
/ etc/init.d/rcS:
#! / bin/shmount-t proc proc / procmount-t sysfs sysfs / sys
And change / etc/init.d/rcS to an executable file.
2.1.5 Kernel startup script
Boot the kernel normally:
Qemu-system-x86_64\-m 512\-kernel. / kernel/arch/x86_64/boot/bzImage\-drive format=raw,file=./disk.raw\-append "init=/linuxrc root=/dev/sda rw"
Check the kernel serial port output:
Qemu-system-x86_64\-m 512\-kernel. / kernel/arch/x86_64/boot/bzImage\-drive format=raw,file=./disk.raw\-append "init=/linuxrc root=/dev/sda rw console=ttyS0"\-serial file:./serial.out2.2 uses ISO files to create debian file systems (method 2)
This method is similar to a virtual machine installation system, which uses the installation bootstrap that comes with the system to generate a file system. The result of this installation is a complete debian, which can be installed with the apt installation tool.
2.2.1 generate an image file
Generate a raw image file:
Qemu-img create-f raw debiam-10G.img 10G
Install debian:
Qemu-system-x86_64-m 512-boot d-hda. / debiam-10G.img-cdrom iso/debian-9.4.0-amd64-netinst.iso2.2.2 kernel startup script qemu-system-x86_64-m 512-boot c-kernel. / kernel/arch/x86_64/boot/bzImage-append root=/dev/sda1-hda. / debiam-10G.img-hdb. / fat.img-net nic-net user Hostfwd=tcp::10022-:222.3 uses debootstrap to make Debian Root File system (method 3)
This is done by using debian's official debootstrap to install debian in a directory on the local machine. This system is also a complete debian.
2.3.1 generate an image file
Generate a raw image file:
Qemu-img create-f raw debiam-10G.img 10G
Mount the file system:
Sudo mount-o loop. / debiam-10G.img. / img2.3.2 install debian
Install debian. The path_to_disk_img_mount_point here is the mount point of the image file just now:
Sudo debootstrap-arch amd64 stretch 2.3.3 configure the network
The network here is the network between the host and the virtual machine.
Let the system automatically run dhclient when it starts:
$cat > / etc/systemd/network/eth.network
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.