- (Video) you need to learn Virtual Machines RIGHT NOW!! (Kali Linux VM, Ubuntu, Windows)
- 2
- To edit
---tags: Linux Kernel---# Linux on Virtual Machine (QEMU)contributed by < Dung-Ru Tsai ># Ubuntu Image on [QEMU](https://www.qemu.org/download/)**1. Build and Install QEMU**```bash git clone https://gitlab.com/qemu-project/qemu.gitcd qemugit submodule initgit submodule update --recursivegit checkout v6.1.0mkdir buildcd build../configure --prefix=/usr/local/bin \ --enable-debug \ --enable-virtfsmake -j8sudo make install```:::success[Dependency](https://wiki.qemu.org/Hosts/Linux#Simple_build_and_test):```sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev```:::**2. Bridge host network with TAP interface**> [Setting up Qemu with a tap interface](https://gist.github.com/extremecoders-re/e8fd8a67a515fee0c873dcafc81d811c)- Create a bridge interface on Host (by netplan)```bashvim /etc/netplan/01-network-manager-all.yaml===== copy start =====network: version: 2 renderer: networkd ethernets: eno1: dhcp4: false dhcp6: false bridges: br0: interfaces: [eno1] addresses: [192.168.100.4/24] gateway4: 192.168.100.254 mtu: 1500 nameservers: addresses: [8.8.8.8] parameters: stp: false forward-delay: 4 dhcp4: false dhcp6: true===== copy end =====sudo netplan apply```- Create tap0 interface[bridge network with tap](https://blog.elastocloud.org/2015/07/qemukvm-bridged-network-with-tap.html)```bash=sudo ip tuntap add dev tap0 mode tapsudo ip link set dev tap0 master br0sudo ip link set dev tap0 up```**3. Create Disk image**```shellqemu-img create -f qcow2 kvm-generic.qcow2 30G```**4. Install Ubuntu ISO**> [qemu ubuntu20.04](https://www.arthurkoziel.com/qemu-ubuntu-20-04/)> [qemu quick reference](https://www.notion.so/QEMU-11408fae00c74630914c044f815d8549)```bash=#!/bin/bashPREFIX=/home/jake/mount_1TB/gns3serverISO=${PREFIX}/ubuntu-20.04.3-live-server-amd64.iso # Installation mediaNET=br0 # bridge nameOS=linux # os typeVM_DISK=${PREFIX}/kvm-generic.qcow2 # VM image on disksudo qemu-system-x86_64 \ -machine type=q35,accel=hvf \ -smp 2 \ -hda ${VM_DISK}\ -cdrom ${ISO} \ -m 4096 \ -vga virtio \ -usb \ -device usb-tablet \ -enable-kvm \ -cpu host \ -display default \ -boot d \ -netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no \ -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01```:::successQEMU Parameter help`qemu-system-x86_64 -accel ?``qemu-system-x86_64 -netdev ?`:::- Connect to VNC: `127.0.0.1:5900` **5. Running the system**```bash#!/bin/bashPREFIX=/home/jake/mount_1TB/gns3serverNET=br0 # bridge nameOS=linux # os typeVM_DISK=${PREFIX}/kvm-generic.qcow2 # VM image on disksudo ip tuntap add dev tap0 mode tapsudo ip link set dev tap0 master br0sudo ip link set dev tap0 upsudo qemu-system-x86_64 \ -machine type=q35,accel=hvf \ -smp 4 \ -hda ${VM_DISK}\ -m 4096 \ -vga virtio \ -usb \ -device usb-tablet \ -enable-kvm \ -cpu host \ -netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no \ -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01 \ -serial telnet:127.0.0.1:4322,server,nowait \ -display default -nographic```[Another example](https://gist.github.com/dungru/bf11265caf466d5a82672f3e984c8be9)**6. Redirect GRUB output to serial console (optional)**> [SerialConsoleHowto](https://help.ubuntu.com/community/SerialConsoleHowto)- Connect to VNC- Edit the `/etc/default/grub`, redirect serial message to ttyS0```bash=# If you change this file, run 'update-grub' afterwards to update# /boot/grub/grub.cfg. GRUB_DEFAULT=0GRUB_TIMEOUT=1GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8" # Uncomment to disable graphical terminal (grub-pc only)GRUB_TERMINAL=serialGRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"...```- Update the GRUB```bashsudo update-grubreboot# Open another terminaltelnet 127.0.0.1 4322```**7. Connect with ssh**```ssh dutsai@your-vm-ip```- [Install/running scripts](https://gist.github.com/dungru/96f4dd9f7a69c6baae1c77425f5a25af)# Enlarge the disk on VMhttps://www.linuxtechi.com/extend-lvm-partitions/https://www.tecmint.com/extend-and-reduce-lvms-in-linux/- Add new the partition```shell=qemu-img resize kvm-generic.qcow2 +60Gsudo fdisk -lsudo fdisk -cu /dev/sdaTo Create new partition Press n.Change the type using t.Type 8e to change the partition type to Linux LVM.Press w to write the changes.sudo sudo fdisk -l #check ```- Add new physical volume and add to volume group```shell=# Add physical volumesudo pvcreate /dev/sda4$ sudo pvs PV VG Fmt Attr PSize PFree /dev/sda3 ubuntu-vg lvm2 a-- <29.00g 0 /dev/sda4 ubuntu-vg lvm2 a-- 29.26g 0# Extend Volume Groupsudo vgextend ubuntu-vg /dev/sda4$ sudo vgs # check volume VG #PV #LV #SN Attr VSize VFree ubuntu-vg 1 1 0 wz--n- <29.00g <9.00g```- Resize Logical Volume```shell=# Get LV Pathsudo lvdisplay # Do it$ sudo lvextend /dev/ubuntu-vg/ubuntu-lv -l+100%FREE$ sudo resize2fs -p /dev/ubuntu-vg/ubuntu-lv$ df -h /Filesystem Size Used Avail Use% Mounted on/dev/mapper/ubuntu--vg-ubuntu--lv 28G 19G 8.1G 70% /```-------< obsoleted ># ARM64 QEMU Environment Setting## Method01: buildroot### 1. Set up the QEMU for aarch64```shell=wget https://download.qemu.org/qemu-2.12.1.tar.xztar xvJf qemu-2.12.1.tar.xzcd qemu-2.12.1./configure --target-list=aarch64-softmmu# Work with VirtIO + 9Psudo apt-get install libcap-dev libattr1-dev./configure --enable-virtfs --target-list=aarch64-softmmumake````--enable-virtfs` : 使得 VirtIO + 9P 可以運作,`--target-list` : 只產生可以運行 aarch64 架構的 qemu耐心等待一段時間之後,在 `aarch64-softmmu` 目錄下可以找到`qemu-system-aarch64`- Install the binary qemu-system-aarch64 to /usr/bin/```shell#$ sudo cp qemu-2.12.1/aarch64-softmmu/qemu-system-aarch64 /usr/binsudo make install```:::infoBuildroot Guide- 第3章 行程(process)環境:https://hackmd.io/s/rJf1ONuye - from link: [Taiwan linux study group](https://hackmd.io/KYRgLADAZgJgzFAtAQwBxwKyLHYrEBGAbBmIsBARGAQJxgDGUlQA):::### 2. Build AArch64 image with buildroot```shell=$ sudo apt-get install libncurses-dev$ git clone https://github.com/buildroot/buildroot$ make list-defconfigs# Generate the .config$ make qemu_aarch64_virt_defconfig$ make menuconfig# 使用Kernel 5.0 header$ make linux-menuconfig# 開啟 9P File System$ make```- [設定Kernel 5.0 教學](https://hackmd.io/s/ryQIj1MKV#%E8%AA%BF%E6%95%B4%E8%87%B3-Linux-50x)- 9P File System9P File System [設定教學](https://wiki.qemu.org/Documentation/9psetup)### 3. Run the emulation Qemu```shell=$ qemu-system-aarch64 -M virt \-cpu cortex-a53 \-nographic -smp 1 \-kernel output/images/Image \-append "root=/dev/vda console=ttyAMA0" \-netdev user,id=eth0 -device virtio-net-device,netdev=eth0 \-drive file=output/images/rootfs.ext4,if=none,format=raw,id=hd0 \-device virtio-blk-device,drive=hd0 \-fsdev local,security_model=passthrough,id=fsdev0,path=/tmp \-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=host_mount```注意最後兩行 `-fsdev` and `-device`, 是為了掛載 host 的目錄才有的### 4. 掛載 host 的目錄```shell=mkdir sharemount -t 9p -o trans=virtio host_mount share -oversion=9p2000.L```Reference: [0xff07](https://hackmd.io/s/ryQIj1MKV#2019q1-Homework4-smallsys)[9psetup](https://wiki.qemu.org/Documentation/9psetup)## Method-02: Kernel source### 1. Set up the QEMU for aarch64```shell=wget https://download.qemu.org/qemu-2.12.1.tar.xztar xvJf qemu-2.12.1.tar.xzcd qemu-2.12.1./configure --target-list=aarch64-softmmu# Work with VirtIO + 9Psudo apt-get install libcap-dev libattr1-dev./configure --enable-virtfs --target-list=aarch64-softmmumake````--enable-virtfs` : 使得 VirtIO + 9P 可以運作,`--target-list` : 只產生可以運行 aarch64 架構的 qemu耐心等待一段時間之後,在 `aarch64-softmmu` 目錄下可以找到`qemu-system-aarch64`- Install the binary qemu-system-aarch64 to /usr/bin/```shell$ sudo cp qemu-2.12.1/aarch64-softmmu/qemu-system-aarch64 /usr/binsudo make install```### 2. Create initramfs cpio (Create the file system)```shell$ git clone https://github.com/buildroot/buildroot$ make list-defconfigs$ make qemu_aarch64_virt_defconfig$ make menuconfig```- Target options —> Target Architecture: 選擇 AArch64 little-endian- Toolcahin —> Toolchain type: 選擇 External toolchainToolchain: 選擇 Linaro AArch64 2018.05- System configuration —> Run a getty (login prompt) after bootTTY port 改為 ttyAMA0- Filesystem images —> cpio the root filesystem (for use as an initial RAM filesystem)儲存之後,進行 make。若無異常,可以在 output/images 目錄底下找到 **rootfs.cpio**### 3. Build aarch64 Kernel from source:::infoKernel Source code - [Linux Kernel]( https://www.kernel.org/pub/linux/kernel/ ) - [Preempty Kernel patch]( https://www.kernel.org/pub/linux/kernel/projects/rt/) - [Building the preeempty kernel on ubuntu](https://ubuntuforums.org/showthread.php?t=2273355):::```shell=git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux-stablecd linux-stablesudo apt-get install gcc-aarch64-linux-gnumake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfigmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig```Edit the .config for 9P```shell=CONFIG_CMDLINE="console-ttyAMA0"# points at your buildrootimageCONFIG_INITRAMFS_SOURCE="/home/jake/QEMU/rootfs.cpio" # needed for virtfs mountCONFIG_NET_9P=y CONFIG_NET_9P_VIRTIO=y```一切就緒就開始編譯核心```shell=## Build the Kernelmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-```The image path will show at `arch/arm64/boot/Image` or linux/vmlinux### 4. Run the emulation QEMU```shell=#!/bin/bashqemu-system-aarch64 \-machine virt \-machine type=virt \-cpu cortex-a57 \-nographic -smp 1 \-m 8192 \-kernel /home/jake/QEMU/linux-stable/arch/arm64/boot/Image \--append "console=ttyAMA0" \-fsdev local,security_model=passthrough,id=test_dev,path=/home/jake/Workspace/ -device virtio-9p-pci,id=fsdev0,fsdev=test_dev,mount_tag=host_mount ```- `-kernel` : 指定第二步驟編譯好的 image path- `-fsdev, path` : 指定共享目錄的路徑 - path 是在 host 這邊要目錄分享的路徑,這邊是用 `/home/jake/Workspace/` - 而最後面那個 `mount_tag=host_mount` 是到時候在 guest 裡面 mount 時會用到.### 5. 掛載 host 的目錄透過 VirtIO + 9P 使得 guest 與 host 共享目錄:`mount -t 9p -o trans=virtio host_mount /mnt`- Exit the QEMU:Ctrl+a X#### Reference- Video: [Starting Linux kernel exploration with Eukabuka](https://www.youtube.com/watch?v=zK2Agg3U2cU)- QEMU Source :https://www.qemu.org/download/#source- [Running Linux in QEMU’s aarch64 system emulation mode](https://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/)- [atlantis0914](https://hackmd.io/s/HJb80Rdt4#2019q1-Homework4-smallsys)# X86_64 QEMU Environment Setting [PASS]## Method-01 buildroot source### 1. Build the QEMU```shellwget https://download.qemu.org/qemu-4.2.0.tar.xztar xvJf qemu-4.2.0.tar.xzcd qemu-4.2.0# Work with VirtIO + 9Psudo apt-get install libcap-dev libattr1-devsudo apt install build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache flex bison libelf-devsudo apt-get install libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev install libnfs-dev libiscsi-dev./configure --enable-virtfs --target-list=x86_64-softmmu --enable-debugmake -j8... wait for a whilesudo make install````--enable-virtfs`: Enable the virtual file IO system### 2. Build the Linux from buildrootCheck the basic build guide in`cat README````shellmake list-defconfigsmake qemu_x86_64_defconfigmake# find the kernel, bootloader, root filesystem, etc. in output/images```### 3. Run the qemu with LinuxCheck the qemu startup guide`cat board/qemu/x86_64/readme.txt````shellqemu-system-x86_64 -M pc \ -kernel output/images/bzImage \ -drive file=output/images/rootfs.ext2,if=virtio,format=raw \ -append "rootwait root=/dev/vda console=tty1 console=ttyS0" \ -serial stdio \ -net nic,model=virtio \ -net user# Optionally add -smp N to emulate a SMP system with N CPUs.```:::success```shelludhcpc: sending select for 10.0.2.15udhcpc: lease of 10.0.2.15 obtained, lease time 86400deleting routersrandom: mktemp: uninitialized urandom read (6 bytes read)adding dns 10.0.2.3OKWelcome to Buildrootbuildroot login: root```:::## Method-02 Kernel Source### 1. Build the QEMU```shellsudo apt update -ysudo apt install libcap-ng-dev libattr1-dev build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache flex bison libelf-dev libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libnfs-dev libiscsi-dev ninja-buildwget https://download.qemu.org/qemu-6.2.0.tar.xztar xvJf qemu-6.2.0.tar.xzcd qemu-6.2.0./configure --enable-virtfs --target-list=x86_64-softmmu --enable-debugmake -j8... wait for a whilesudo make install````--enable-virtfs`: Enable the virtual file IO system### 2.1 Create the root file system```shell$ git clone https://github.com/buildroot/buildroot$ make list-defconfigs$ make qemu_x86_64_defconfig$ make menuconfig```- Target options —> Target Architecture: 選擇 x86_64- Filesystem images —> ext2/3/4 root file system:::infocpio the root filesystem (for use as an initial RAM filesystem) :::儲存之後,進行 make。若無異常,可以在 output/images 目錄底下找到 **rootfs.cpio**### 2.2 Build Kernel from linux source- [Prepare the environment for developing Linux kernel with qemu](https://medium.com/@daeseok.youn/prepare-the-environment-for-developing-linux-kernel-with-qemu-c55e37ba8ade)- https://mirrors.edge.kernel.org/pub/linux/kernel/```bash=make ARCH=x86_64 x86_64_defconfig make ARCH=x86_64 menuconfigmake -j8```- Kernel hacking -> Compile the kernel with debug info -> Provide GDB scripts for kernel debugging- `Reduce debugging information` option off- Force unload the kernel module: `MODULE_FORCE_UNLOAD`- KGDB```shellCONFIG_DEBUG_INFO=yCONFIG_FRAME_POINTER=yCONFIG_HAVE_ARCH_KGDB=yCONFIG_KGDB=yCONFIG_KGDB_SERIAL_CONSOLE=y```- Ensure the following 9P options are enabled in the kernel configuration.```shell CONFIG_NET_9P=y CONFIG_NET_9P_VIRTIO=y CONFIG_NET_9P_DEBUG=y (Optional) CONFIG_9P_FS=y CONFIG_9P_FS_POSIX_ACL=y CONFIG_PCI=y CONFIG_VIRTIO_PCI=y CONFIG_PCI_HOST_GENERIC=y (only needed for the QEMU Arm 'virt' board)```The final image will show in `arch/x86/boot/bzImage`.- ramfile system only```# Only for ramfile system when you choose in builtroot Filesystem images is cpio:CONFIG_INITRAMFS_SOURCE="/home/jake/QEMU/rootfs.cpio"```### 3.1 Run qemu with own Linux Kernel (No File system)```shellqemu-system-x86_64 -s -S\-kernel arch/x86/boot/bzImage \-hda /dev/zero \-append "root=/dev/zero console=ttyS0" \-serial stdio -display none```Try the KGDB```shellcd linuxgdb ./vmlinux(gdb) target remote localhost:1234(gdb) break start_kernel(gdb) cContinuing.Breakpoint 1, start_kernel () at init/main.c:786786{```### 3.2 Run qemu with own Linux Kernel with Files system```bashqemu-system-x86_64 -kernel arch/x86/boot/bzImage \-boot c -m 2049M \-append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" \-hda output/images/rootfs.ext4 \-fsdev local,security_model=passthrough,id=fsdev0,path=/home/dutsai/Workspace_vm \-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=host_mount \-nographic \-monitor telnet::45454,server,nowait \-serial mon:stdio```- `-kernel` : 指定第二步驟編譯好的 image path- `-fsdev, path` : 指定共享目錄的路徑 - path 是在 host 這邊要目錄分享的路徑,這邊用 `/home/dutsai/Workspace_vm` - `mount_tag=host_mount` 在 guest 裡面 mount 時會用.- `-serial mon:stdio` Send Ctrl+C to guest - `Ctrl+a X` to exit qemu.### 4. Mount host folderhttps://wiki.qemu.org/Documentation/9psetup```bash=# In qemumount -t 9p -o trans=virtio host_mount /root -oversion=9p2000.L```### 5. KGDB```shellqemu-system-x86_64 \-kernel linux-5.16.14/arch/x86/boot/bzImage \-boot c -m 4096M \-append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" \-hda buildroot/output/images/rootfs.ext4 \-fsdev local,security_model=passthrough,id=fsdev0,path=/home/dutsai/Workspace_vm \-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=host_mount \-nographic \-monitor telnet::45454,server,nowait \-serial mon:stdio \-S -gdb tcp::33004```Try to open another terminal to run gdb.```shellcd linuxgdb ./vmlinux(gdb) target remote localhost:33004(gdb) break start_kernel(gdb) cContinuing.Breakpoint 1, start_kernel () at init/main.c:786786{```## Method-03 Ycoto[RISC-V Embedded Linux - Get started with Buildroot/Yocto](https://hackmd.io/@coscup/SJLHICJTc/%2F%40coscup%2FSkfNICy69)# Update Linux Kernel:::infoKernel Source code - [Linux Kernel]( https://www.kernel.org/pub/linux/kernel/ ) - [Preempty Kernel patch]( https://www.kernel.org/pub/linux/kernel/projects/rt/) - [Building the preeempty kernel on ubuntu](https://ubuntuforums.org/showthread.php?t=2273355):::- Get from Newest [release](https://github.com/torvalds/linux/tags)- [Ubuntu 22.04 is Jammy Jellyfish](https://code.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy)- [將 memchr() 放入核心並重新 compile](https://hackmd.io/@arthur-chang/linux2022-quiz8?fbclid=IwAR3TsBYPmvISIC7xcYQ8s2uPZo9aWk7vm8DZqHwMdggfH5PVUKcUgnAJfCs#%E5%B0%87-memchr-%E6%94%BE%E5%85%A5%E6%A0%B8%E5%BF%83%E4%B8%A6%E9%87%8D%E6%96%B0-compile)Source code: https://www.kernel.org/```shell=$ sudo apt-get install liblz4-tool libc6-dev libncurses5-dev openssl wget ca-certificates bc libzstd-dev zstd$ sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison dwarves$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.17.9.tar.xz$ cp /boot/config-`uname -r` .config$ make menuconfig選擇 load 再選擇 save# make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig$ scripts/config --disable SYSTEM_TRUSTED_KEYS$ scripts/config --disable SYSTEM_REVOCATION_KEYSCONFIG_DEBUG_INFO_BTF=n# Build$ make -j12$ make modules -j12# Install$ sudo make INSTALL_MOD_STRIP=1 modules_install -j 4$ sudo make install$ sudo mkinitramfs /lib/modules/5.17.9/ -o /boot/initrd.img-5.17.9$ sudo update-grub2# Install Method2$ su -c "make modules_install install"```# Patch RT (Linux)- Install the ubuntu 16.04- [Building and Install the preeempt kernel on Ubuntu](https://ubuntuforums.org/showthread.php?t=2273355)- Kernel Version https://www.kernel.org/pub/linux/kernel/ - linux-4.4.60- Preempt RT Version https://www.kernel.org/pub/linux/kernel/projects/rt/ - patch-4.4.60-rt73 (Linux preempt RT 4.4.60-rt73+) - https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.4/older/patch-4.4.60-rt73.patch.gz- [Linux RT Kernel config](https://gist.github.com/ldotrg/c69d0ee45ab28884d26c9ba8fc275e70) replace the `.config` file - Must turn off **Check for stack overflows** - `sudo apt-get install libssl-dev`### build kernel command```shell=$ sudo apt-get update$ sudo apt-get install build-essential linux-tools-common linux-tools-generic cmake automake libtool libusb-1.0-0-dev openssh-server samba vim linux-headers-`uname -r` can-utils libpopt-dev$ mkdir -p kernel$cd kernel# Download the kernel linux-4.4.60.tar.gz and patch-4.4.60-rt73.patch.gz $ wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.4.60.tar.gz$ wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.4/older/patch-4.4.60-rt73.patch.gz$ tar -xzvf linux-4.4.60.tar.gz$ cd linux-4.4.60$ gzip -cd ../patch-4.4.60-rt73.patch.gz | patch -p1 --verbose$ sudo apt-get install libncurses-dev libssl-dev# Change .config file$ make menuconfig##Graphical Menu### Processor type and features ---> [Enter]# Preemption Model (Voluntary Kernel Preemption (Desktop)) [Enter]# Fully Preemptible Kernel (RT) [Enter] #Select# [Esc][Esc]# <Save> [Enter]/*# Kernel hacking --> [Enter]# Memory Debugging [Enter]# Check for stack overflows #Already deselected - do not select# [Esc][Esc]# [Right Arrow][Right Arrow]# .config# <Okay> [Enter]# <Exit> [Enter]# [Esc][Esc]# [Right Arrow]# <Exit> [Enter]*/makesudo make modules_install -j3sudo make install -j3 ```:::danger- [Linux RT Kernel .config simple](https://gist.github.com/ldotrg/c69d0ee45ab28884d26c9ba8fc275e70) replace the `.config` file in Linux-4.4.60- [EGSE .config full](https://gist.github.com/ldotrg/1ca2213f8c8569f59f4169a5ac4eab71):::**After install the kernel**- Verify and update. Verify that `initrd.img-4.4.60-rt73`, `vmlinuz-4.4.60-rt73`, and `config-4.4.60-rt73` exist. They should have been created in the previous step. ```shell$cd /boot$ ls```### Set the default kernel**1. Go to see the menuentry in** ```shellvim /boot/grub/grub.cfg```search your menuentry version and copy it.```menuentry 'Ubuntu, with Linux 4.4.60-rt73'```2. **sudo vim /etc/default/grub**```shell=$ sudo vim /etc/default/grub GRUB_DEFAULT='Advanced options for Ubuntu>Ubuntu, with Linux 4.4.60-rt73' GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=1"```:::dangerCPU Isolation```shell=sudo vim /etc/default/grub ===> add GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=1"sudo update-grubsudo reboot# Loogin Permissionsudo vim /etc/ssh/sshd_config ===> modify "PermitRootLogin yes"```:::3. **sudo update-grub** - it will show the error message, please change the GRUB_DEFAULT by use the correct one on error message.4. In BIOS, Turn off Hyper threading# Lima macOS1st Start```limactl start --name=default template://ubuntu-ltslimactl shell default```https://github.com/lima-vm/lima```sudo apt-get install sshfs build-essential linux-tools-common linux-tools-generic automake* linux-headers-`uname -r` net-tools wireless-tools```[linux-image-5.4.0-109-generic_5.4.0-109.123_arm64.deb](https://ubuntu.pkgs.org/20.04/ubuntu-proposed-main-arm64/linux-image-5.4.0-109-generic_5.4.0-109.123_arm64.deb.html)```sudo apt install linux-modules-extra-`uname -r````- YAML file on mac: ```vim /Users/dutsai/.lima/default# Ubuntu 20.04 LTS (Focal Fossa)# This example requires Lima v0.7.0 or later.images:# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.- location: "https://cloud-images.ubuntu.com/releases/20.04/release-20220302/ubuntu-20.04-server-cloudimg-amd64.img" arch: "x86_64" digest: "sha256:243157ea0390890d6e60ce5e08e0249b16e23b6b313b63aed50f39f92b020afe"- location: "https://cloud-images.ubuntu.com/releases/20.04/release-20220302/ubuntu-20.04-server-cloudimg-arm64.img" arch: "aarch64" digest: "sha256:fb2b4efdbf0011bd2a9fd49e9d31efdd252966c889f07b5d246351ec5734a329"# Fallback to the latest release image.# Hint: run `limactl prune` to invalidate the cache- location: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img" arch: "x86_64"- location: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-arm64.img" arch: "aarch64"mounts:- location: "~"- location: "~/Workspace_mac/vwifi" writable: true- location: "/tmp/lima" writable: true```# User mode Linuxhttps://hackmd.io/@sysprog/user-mode-linux-env```shell$ sudo apt install build-essential libncurses-dev flex bison$ sudo apt install xz-utils wget ca-certificates bc fakeroot$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.12.tar.xz$ tar xvf linux-5.12.tar.xz$ make mrproper$ make defconfig ARCH=um SUBARCH=x86_64$ make linux ARCH=um SUBARCH=x86_64 -j `nproc````- Root file system```shell$ export REPO=http://dl-cdn.alpinelinux.org/alpine/v3.13/main$ mkdir -p rootfs$ curl $REPO/x86_64/APKINDEX.tar.gz | tar -xz -C /tmp/$ export APK_TOOL=`grep -A1 apk-tools-static /tmp/APKINDEX | cut -c3- | xargs printf "%s-%s.apk"`$ curl $REPO/x86_64/$APK_TOOL | fakeroot tar -xz -C rootfs$ fakeroot rootfs/sbin/apk.static \ --repository $REPO --update-cache \ --allow-untrusted \ --root $PWD/rootfs --initdb add alpine-base$ echo $REPO > rootfs/etc/apk/repositories$ echo "LABEL=ALPINE_ROOT / auto defaults 1 1" >> rootfs/etc/fstab```- UML.sh``````[howto-usermode-linux](https://xeiaso.net/blog/howto-usermode-linux-2019-07-07)### Original Assignment info: [F08: smallsys](https://hackmd.io/s/BkhVVlHu4#F08-smallsys)
2117 2
keep reading
Read more from Dung-Ru Tsai
published in HackMDGenericName
get connected
or
By clicking below, you agree to ourTerms of use.
Sign up using Facebook Sign up via Twitter Sign up via GitHub Sign up via Dropbox
New to HackMD?Record
FAQs
Can you run QEMU on a virtual machine? ›
To make sure you can set up VMs with QEMU, you need to install and enable the libvirt daemon that runs virtualization in the background. Without it, QEMU or any other hypervisor will refuse to work. Once you're done with this step, you can move on to the QEMU installation process.
Can I run Linux on QEMU? ›How To Use QEMU To Test Operating Systems & Distributions. QEMU is a virtualization technology emulator that allows you to run operating systems and Linux distributions easily on your current system without the need to install them or burn their ISO files.
Is QEMU necessary with KVM? ›Based on the discussion above, it is quite clear that QEMU plays a very critical role in Linux based Open Source virtualization solutions. For all practical applications, QEMU needs KVM's performance boost. However, it is clear that **KVM by itself cannot provide the complete virtualization solution. It needs QEMU.
What is QEMU vs KVM? ›So to conclude: QEMU is a type 2 hypervisor that runs within user space and performs virtual hardware emulation, whereas KVM is a type 1 hypervisor that runs in kernel space, that allows a user space program access to the hardware virtualization features of various processors.
Can QEMU be detected? ›However, Qemu did not raise any exceptions when trying to access a reserved or unimplemented MSR. Hence, Qemu can be easily detected using this approach. This code, run in a kernel module (MSRs can only be accessed in privileged mode), should result in a general protection fault.
Is QEMU faster than VirtualBox? ›VirtualBox is faster and has a better UI than QEMU. It's also a good choice only for x86 and x64 architectures. Lastly, VirtualBox doesn't require advanced knowledge or experience.
What does QEMU do in Linux? ›QEMU is a machine emulator that can run operating systems and programs for one machine on a different machine. However, it is more often used as a virtualiser in collaboration with KVM kernel components. In that case it uses the hardware virtualisation technology to virtualise guests.
What systems can QEMU emulate? ›QEMU can boot many guest operating systems, including Linux, Solaris, Microsoft Windows, DOS, and BSD; it supports emulating several instruction sets, including x86, MIPS, 32-bit ARMv7, ARMv8, PowerPC, SPARC, ETRAX CRIS and MicroBlaze.
Is QEMU same as VirtualBox? ›Features: QEMU is both an emulator and hypervisor. VirtualBox is just a hypervisor. Apart from this, their feature set mostly boils down to the various architectures and operating systems that both support, but we have already covered all of that in the above sections.
Can you run KVM on a VM? ›Kernel-based Virtual Machine (KVM) is an open source virtualization technology built into Linux®. Specifically, KVM lets you turn Linux into a hypervisor that allows a host machine to run multiple, isolated virtual environments called guests or virtual machines (VMs).
Can KVM replace VMware? ›
KVM is an open source virtualization technology that changes the Linux kernel into a hypervisor that can be used for virtualization and is an alternative to proprietary virtualization technologies, such as those offered by VMware.
Why KVM is better than VirtualBox? ›KVM, a type 1 hypervisor, is smaller and faster than VirtualBox, but VirtualBox is more scalable. KVM is better integrated with Linux, and while it will work with other guests, it works best with Linux. In short, if you want to install a binary Linux distribution as a guest, it's better to use KVM.
Why do we need QEMU? ›QEMU is the virtual machine monitor (VMM): it provides hardware emulation and a low-level interface to the virtual machine. A QEMU process is a virtual machine on its own: you can terminate it by sending a signal to the process, examine processor consumption using top, and so on.
Is QEMU a docker? ›Multi-architecture support
With support for Apple M1 ARM Mac and QEMU included in Docker Desktop, you are able to build and use multi-architecture images (Linux x86, ARM, Windows) on whatever platform you are working on out of the box.
It can be used to launch different Operating Systems without rebooting the PC or to debug system code. User mode emulation (Linux host only). In this mode, QEMU can launch Linux processes compiled for one CPU on another CPU. For example, it can be used to launch Wine or to ease cross-compilation and cross-debugging.
How do I get rid of QEMU? ›- Go to the installation folder of QEMU. Most of the times it is located in C:\Programs files or C:\Program files(x86)
- Double click the file to start the uninstallation process.
Shutting down QEMU:
If you are running in graphics mode, then from the ctrl-alt-2 qemu window, type "quit" after "Power down" to exit the qemu process.
VM Threat Detection relies on the capabilities of Google Cloud's hypervisor; it can't run in on-premises environments and in other public cloud environments. VM Threat Detection scans each VM instance immediately after the instance is created. In addition, VM Threat Detection scans each VM instance every 30 minutes.
Does QEMU use GPU? ›It support Intel (Intel GVT-g, SR-IOV), NVIDIA (Nvidia VGPU, SR-IOV) and AMD (AMD SR-IOV). You have to create YAML configurations for each virtual machine. Currently Intel and NVIDIA GPUs are tested, with limited support for AMD.
Can you run Windows 10 in QEMU? ›Initial setup
Open up the Virtual Machine Manager and click on the upper left button to open the New VM window. The first thing you have to do is to select how you would like to install the operating system. In this case, we are using a Windows 10 ISO image. Click forward and choose the Windows 10 ISO you downloaded.
Can QEMU emulate a Raspberry Pi? ›
Running qemu for the Raspberry PI 3 hardware
It will boot using the Raspberry PI 3 kernel provided by the kernel8. img file and will have a few boot options that configure the console and the root drive which for a Raspberry PI is the eMMC device located at /dev/mmcblk0p2 .
QEMU is installed in a directory named build which is a sub directory of the directory that contains your local copy of the QEMU source code repository. Your command line environment should currently be inside this build directory. QEMU provides sample disk images to test the installation here.
What does QEMU stand for? ›Share to Facebook Share to Twitter. Definition(s): A software module that is a component of the hypervisor platform that supports full virtualization by providing emulation of various hardware devices.
How do I use QEMU virtual machine? ›...
Once again, I'll guide you through the steps.
- Step 1: Locate the QEMU log file on your virtualization host. ...
- Step 2: Copy lines from the log file to your new script. ...
- Step 3: Create the shell script. ...
- Step 4: Run the VM using your newly created script.
While QEMU does support booting other OS's, we don't use that functionality since Android is Linux. The Android Emulator is downstream from the QEMU emulator. It adds support for booting Android devices, emulates typical Android hardware (OpenGL, GPS, GSM, Sensors) and a GUI interface.
Can QEMU emulate hardware? ›Admins looking for an alternative tool for emulating hardware should consider QEMU, which supports x86, PowerPC, ARM and SPARC architectures. QEMU is an open source emulator and virtualization tool that specializes in emulating different CPU architectures.
Is QEMU better than VirtualBox on Windows? ›Therefore, QEMU is recommended for advanced level users and for kernel developers. On the other hand, VirtualBox better suits the users who want to get multiple operating systems to run on a single machine without a dual boot hindrance.
Why is QEMU faster? ›QEMU/KVM is better integrated in Linux, has a smaller footprint and should therefore be faster. VirtualBox is a virtualization software limited to x86 and amd64 architecture. Xen uses QEMU for the hardware assisted virtualization, but can also paravirtualize guests without hardware virtualisation.
Can I run QEMU in Windows? ›Qemu is an open source virtual machine host app which can be used to emulate different operating systems on the host operating system. We can run QEMU to install Ubuntu or any other relevant software. To install the QEMU we will go to the official site of QEMU and download the Windows version.
Can KVM be hacked? ›Unsecure KVM switches are susceptible to cyberattacks and can allow cybercriminals to access classified data. If a cybercriminal wants to steal information off a classified server, they can attach a USB drive with malware on it into an unsecure KVM switch to access multiple servers instead of just one.
How to install KVM on a virtual machine? ›
- Prerequisites.
- Checking Your Hardware. Using the lscpu Command. Using the cpu-checker Tool.
- Installing KVM on Ubuntu.
- Creating Your First Virtual Machine in KVM. Using the virt-manager (GUI) Using the virt-install (CLI)
- Managing VMs in the Command Line. Listing VMs. ...
- Conclusion.
- Requirements and Assumptions.
- Prepare an OVM/Xen host (dom0)
- Test connectivity to OVM/Xen Host from KVM host.
- Copy the "Oracle Linux Virtualization Manager" certificate on the KVM host.
- Create a "Passord File" for KVM-host access to "Oracle Linux Virtualization Manager" API.
KVM, which stands for Kernel-based Virtual Machine, is an open-source hypervisor. The KVM hypervisor is used by large organizations including Amazon and Oracle (in the Oracle Cloud Infrastructure).
What OS can run in KVM? ›KVM provides hardware-assisted virtualization for a wide variety of guest operating systems including Linux, BSD, Solaris, Windows, Haiku, ReactOS, Plan 9, AROS Research Operating System and macOS.
Is there a GUI for KVM? ›A Gnome user interface for KVM. Karesansui is an open-source virtualization management application. It's smart graphical user interface lowers your management cost, and brings a total management/audit solution for both physical and virtual servers.
What is the difference between QEMU virtualization and emulation? ›The Main Difference Between Virtualization and Emulation
In virtualization, you can directly access the hardware. The main difference between the virtual machine and emulator is that the virtual machine runs code directly with a different set of domains in use language. The basic emulation requires an interpreter.
Kernel-based Virtual Machine (KVM) is a full virtualization solution for Linux®. In the KVM architecture, each guest (virtual machine) is implemented as a regular Linux process. After you install KVM, you can run multiple guests, with each of them running a different operating system image.
Does QEMU use UEFI? ›UEFI for x86 QEMU/KVM VMs is called OVMF (Open Virtual Machine Firmware). It comes from EDK2 (EFI Development Kit), which is the UEFI reference implementation.
Is Docker better than VM? ›Advantages of Docker Containers
Docker is fast. Very fast. While a VM can take an at least a few minutes to boot and be dev-ready, it takes anywhere from a few milliseconds to (at most) a few seconds to start a Docker container from a container image.
SeaBIOS also runs inside an emulator; it is the default BIOS for the QEMU and KVM virtualization environments, and can be used with the Bochs emulator.
How does QEMU user work? ›
QEMU relies on the host kernel to emulate most signal system calls, for example to emulate the signal mask. On Linux, QEMU supports both normal and real-time signals. Threading: On Linux, QEMU can emulate the clone syscall and create a real host thread (with a separate virtual CPU) for each emulated thread.
How to check if QEMU is using KVM? ›if you have access to the QEMU monitor (Ctrl-Alt-2, use Ctrl-Alt-1 to get back to the VM display), enter the "info kvm" command and it should respond with "KVM support: enabled"
Can QEMU run in VirtualBox? ›A: VirtualBox makes use of QEMU in two ways: first of all, some of our virtual hardware devices have their origin in the QEMU project. We have found them to be very useful and took them as a starting point.
How to use QEMU virtual machine? ›...
Once again, I'll guide you through the steps.
- Step 1: Locate the QEMU log file on your virtualization host. ...
- Step 2: Copy lines from the log file to your new script. ...
- Step 3: Create the shell script. ...
- Step 4: Run the VM using your newly created script.
Android Emulator allows you to run emulations of Android devices on Windows, macOS or Linux machines. The Android Emulator runs the Android operating system in a virtual machine called an Android Virtual Device (AVD). The AVD contains the full Android software stack, and it runs as if it were on a physical device.
Why QEMU is better than VirtualBox? ›The Difference Between QEMU and Oracle VirtualBox
CPU architectures: VirtualBox only works on x86 CPU architecture. This will not be a problem for most users, as the vast majority of systems come with the usual 64 bit Intel or AMD CPU. QEMU works with many CPU architectures, including x86, ARM, Alpha, and SPARC.
QEMU is a machine emulator that can run operating systems and programs for one machine on a different machine.
Is QEMU easy to use? ›QEMU is a fast processor emulator using dynamic translation to achieve good emulation speed. It is a free open-source alternative to VMware. As QEMU requires no host kernel patches to run, it is very safe and easy to use.
Can you run Linux in a VM? ›A VM can run any Linux on a sufficiently powerful PC. Generally speaking, any Windows 10 system with 16 GB of RAM should be able to run VMs. Even a Windows 10 Home PC with only 8 GB of memory can run VMs, but you may see performance problems on the Windows side.
Is it OK to run Docker in a VM? ›Running Docker on a VM isn't tricky. Docker is nothing more than a standard application or service. In this article, we'll create a virtualized Linux environment and then install the Docker app.
What is the difference between a virtual machine VM and an emulator? ›
Virtual machines make use of CPU self-virtualization, to whatever extent it exists, to provide a virtualized interface to the real hardware. Emulators emulate hardware without relying on the CPU being able to run code directly and redirect some operations to a hypervisor controlling the virtual container.