macos上的虚拟化
操作系统引导恢复
Win10
Win10引导需要用Win10系统盘来修复。从 M$
官方网站下载,创建安装u盘。
在BIOS里设置U盘启动,进入Win10安装界面,点击 “下一步” ,在新的页面选择左下角的 “修复计算机”。
修复界面依次选择:疑难解答->高级工具->命令提示符 进入命令行,显示 X:\Sources>
,之后用到 diskpart
和 bcdboot
命令。
用 diskpart
找到efi分区
用到如下指令 list disk 列出所有挂在磁盘 list par 列出当前磁盘分区 sel disk x 选择某一磁盘x sel par x 选择某一分区x
diskpart //进入diskpart工具 list disk //查看所有磁盘 sel disk x //根据情况选择windows的磁盘编号,x为磁盘编号 list par //列出上一步所选磁盘的分区,其中就有存放efi的分区,类型为系统,大小几百M # 或者 list vol,注意看每个volumne的分区格式是否正确 select par x //选择efi的分区,x为分区编号 # 或者 select volumne x assign letter=o //为选择的分区分配一个盘符为o以便修复 exit //退出diskpart,不要关闭命令行框
bcdboot进行修复
c:\
不一定是系统盘,需要用 dir
命令查看盘内文件来判断哪个是系统盘, dir c:\
和 dir d:\
等,记住系统盘是哪个。
然后执行
bcdboot x:\windows /s o: /f uefi /l zh-cn #其中x为系统盘盘符。
会提示“已成功创建启动文件”。
然后输入 exit
退出命令行,关机重启或者 “继续” 就能进入Windows了。
Ubuntu
用Ubuntu的安装u盘启动,选择第四项 “firmware”,重启后就可以直接进入grub引导。
恢复UEFI引导项
装完catalina后,win10和Ubuntu的引导项都丢失了。在恢复Ubuntu的引导项后,OC的又没有了,真是折腾啊。
Ubuntu中增加uefi启动选项
Ubuntu的u盘启动速度比win10的快,命令多,优先使用Ubuntu恢复OC的启动选项。
用efibootmgr增加启动选项到bios。Ubuntu默认安装了efibootmgr。
U盘引导后,命令行
sudo su - lsbkf -f blkid # 确认 eftbootmgr
win10中增加uefi启动选项
RE
引导
OC引导Ubuntu
OC看不见Ubuntu分区。
Ubuntu的grub2引导OC
grub2引导oc的问题是,不确定会对黑苹果造成什么影响,为了更好的定位问题,还是考虑用OC进行引导。
host macos/VirtualBox
在同一块nvme ssd上的不同分区。想通过VirtualBox直接访问ssd上对应的分区。
efi安装的系统,启动是麻烦啊。
efi分区由于是macos在用,为了安全起见,不能把用户的读写权限给加到 /dev/disk0s5
上。只能把分区 dd 后,转为 vdi 格式。
dd if=/dev/disk0s5 of=~/VirtualBox_VMs/win10/efi.img VBoxMange convertrawdisk efi.img efi.vdi
win10 vm
efi windows ntfs windows recovery linux linux swap
fs0: EFI\Microsoft\Boot\bootmgfw.efi # 没有反应,不知道为什么?
昨天晚上在用本地的nvme ssd盘的partition 1、5后,win10启动会蓝屏,checksum不正确,应该是系统认为换成sata盘的问题,今天安装了extention pack后,应该可以支持nvme了。在hp zhan66 pro g1上用macos测试,会蓝屏,win10起不来。
要关闭win10 home edition的更新,否则一更新就容易把虚机搞定。
德语的,要翻译 https://the-digital-native.de/?p=366
主要看grub的那部份。
I recently purchased a Lenovo P1 that already had Windows 10 Pro preinstalled . Of course, I installed a Linux right away: In my case, a Kubuntu 20.04. For this I reduced the existing NTFS partition with Windows installation to 850GB and created 100GB free space for Linux. Why did I leave the NTFS partition so big? Because, according to my research, it works much better to write from Linux on an NTFS partition than to set up an ext4 partition in Windows. The common data partition becomes the Windows NTFS partition. I did not use a swap partition at all, since 48GB Ram will be enough for everything.
So now I have a dual boot system Ubuntu 20.04 / Windows 10. That's fine. But even under Linux I like to quickly need the Windows functionalities at hand (Photoshop, …). And since maintaining two Windows 10 instances is twice the effort, a possibility to boot the physical system in VirtualBox comes in handy here. That’s what this is about.
- Identify the Windows partitions
I'll just use the KDE Partition Manager here. If you don't have Kubuntu and where the KDE partition manager is missing, you can install it:
sudo apt-get install partitionmanager
Let's take a look at the partitioning. This should look similar on every system with EFI.
Here we see the following partitions:
/dev/nvme0n1p1 #a fat32 partition belonging to the EFI. You can also recognize it because it is /boot/efimounted below . This partition is relevant to us because we need it to boot. /dev/nvme0n1p2 #is a so-called Microsoft Reserved Partition , which is actually no longer relevant nowadays. /dev/nvme0n1p3 #is now the really important partition for us. Windows is here. /dev/nvme0n1p5 #contains our Linux distribution /dev/nvme0n1p4 #contains a Windows recovery, in case you have to set up Windows again.
- Access rights in the file system
In order sudo to have full access to our Windows 10 partition even without full access, we still have to do something. The best way to do this is to define a
udev rule
thatgroupadds
the Windows 10 partition to a specific one.First, let's create a new group for the Windows 10 partition:
sudo groupadd win10disk #Now add your own user to the group sudo usermod -a -G win10disk youruser #Now we need to find out the UUID of the Windows 10 partition. It works like this: sudo udevadm info /dev/nvme0n1p3 | grep UUID #This should output the UUID, e.g. as follows: E: ID_PART_TABLE_UUID=579b23f9-843f-4fec-a246-0ed74800bef1
If there is a different unique ID than
ID_PART_TABLE_UUID
, this also works. Copy the variable and create the file/etc/udev/rules.d/99-win10disk.ruleswith
something like the following:ENV{ID_PART_TABLE_UUID}=="579b23f9-843f-4fec-a246-0ed74800bef1", GROUP="win10disk"
Save the file and now do a restart. Now check whether everything worked with:
ls -l /dev/nvme0n1p3 #The output should look something like this: brw-rw---- 1 root win10disk 259, 3 Jun 1 13:29 /dev/nvme0n1p3
- VirtualBox Raw Host Access VMDK file
In order for VirtualBox to be able to boot the physical partitions from EFI and Windows, a special VMDK (Virtual Machine Disk) file must be created that represents the partitions. This file does not contain any data from the physical partitions, but is just a kind of reference that allows VirtualBox access.
You can
VBoxManage create
the VirtualBox raw disk image with. The target directory can be-filename
specified with the option. We want to integrate the partitions /dev/nvme0n1p1(EFI) and /dev/nvme0n1p3(Windows). That would be partitions 1 and 3 of /dev/nvme0n1:VBoxManage internalcommands createrawvmdk -filename ~/win10.vmdk -rawdisk /dev/nvme0n1 -partitions 1,3 #The output should look something like this: RAW host disk access VMDK file /path/to/windows10.vmdk created successfully.
- Create and configure the virtual machine
Create a Windows 10 VM as usual. Under Hard disk, select the option “Use an existing virtual hard disk file” and select the one you created previously win10.vmdk.
When the wizard is finished, open the settings of the new VM. Under System under “Boot Order” select “Hard Disk” and deactivate all other options. Activate the option “Enable EFI (special OSses only)” if your laptop uses EFI (this is what we assume here):
Under Storage you can check again whether everything is correctly integrated. The file should be selected under Controller: SATAwin10.vmdk . You will probably want to activate the “Solid-state Drive” option .
- Set up GRUB
Now let's start the virtual machine. Most likely, GRUB will now start without being able to load Windows directly. With
ls
you can display all partitions:grub> ls (proc) (hd0) (hd0,gtp5) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1) #We already know that our Windows installation is on partition 3. Let's verify this: grub> ls (hd0,gpt3) Partition hd0,gpt3: Filesystem type ntfs - Label 'Windows', UUID ABCDEF - Partition start at 283648KiB #Now do the following: grub> insmod part_gpt grub> insmod chain grub> set root=(hd0,gpt3) grub> insmod ntfs #We still have to define the /boot/efi partition mounted on our Linux as /dev/nvme0n1p1a chainloader : grub> chainloader (hd0,gtp1)/EFI/Microsoft/Boot/bootmgfw.efi #And that was it! We can now start the boot process. The settings made are saved and Windows will start up automatically in the future. grub> boot
- What else needs to be considered
Now don't forget to insert themVBoxGuestAdditions.iso ( Devices → Insert Guest Additions CD Image ) and install them. After restarting Windows, everything should now work. In particular, it should be possible to freely change the window size.
If this is not the case, it is due to a bug in the current VirtualBox version (6.1.8), which seems to appear in some and not in some. The problem can be solved by setting the Graphics Controller to
VBoxVGA
in the settings of the VM under Display and deactivating Enable 3D Acceleration. That is not optimal, but it is better than working on a screen that is much too small. Then shut down the VM cleanly via the operating system and restart it. It should work now. - Windows 10 Quick Start & Hibernate
Remember that you have to deactivate the quick start in Windows 10. But you should also do that for a simple dual boot. Otherwise there will be problems with possible data loss. Hibernate is also problematic at times and I advise against using it.
- Conclusion
It's amazing that Windows 10 works so well in this form. Remember that with every direct start we have different hardware than via VirtualBox. So one should suspect driver problems. It is also astonishing that you do not have to reactivate it every time you change hardware. But everything is great and it works!
I personally use the VM mainly for Adobe products (Photoshop, Lightroom, Illustrator, Acrobat Pro), Canon EOS Utility, the Brother P-Touch Editor (label printer) and the tax return (Taxman 2020 for self-employed). Photoshop and Lightroom, in particular, work better under a native booted system (hardware acceleration!) Unfortunately, there does not seem to be any usable software for tax declarations by independent small businesses for Linux (happily proves the opposite to me!)
- 参考
- Booting a Physical Windows 10 Disk Using VirtualBox on Linux https://forums.virtualbox.org/viewtopic.php?f=7&t=98410
- https://www.jamieweb.net/blog/booting-a-physical-windows-10-disk-using-virtualbox-on-linux/
ubuntu vm
生成raw partition的vmdk文件
https://www.virtualbox.org/manual/ch09.html#adv-storage-config
# 查看partition diskutil list # 查看partition的uuid diskutil info /dev/disk0s5 diskutil umountDisk /dev/disk0s3 # 修改owner sudo chown albert /dev/disk0s3 # 把Ubuntu使用的ext4分区和swap分区加到raw partition中. # disk0s3是主分区 # disk0s4是swap分区 $ VBoxManage internalcommands createrawvmdk -filename \ ~/VirtualBox_VMs/ubuntu/raw-ubuntu.vmdk -rawdisk /dev/disk0 -partitions 3,4 # 在Virtualbox中注册Ubuntu使用的partition,至少要有 read 权限,否则注册会报错
efi启动
sudo chmod o+r /dev/disk0s5
sudo vifs
efi linux linux swap
使用host io
efi启动后,会进入 efi shell中 fs0: EFI\ubuntu\grub2x64.efi #
选择高级 e ctrl+x 启动 然后就看见kernel panic,这是什么意思?
- Raw disk booting of Windows 10 broken with Ubuntu artful https://forums.virtualbox.org/viewtopic.php?f=2&t=85903
You can enter this in GRUB to Start Windows 10.
insmod chain set root=(hd0,gpt1) chainloader /EFI/Microsoft/Boot/bootmgfw.efi boot
found at stackoverflow (dot) com/questions/51101487/booting-raw-disk-windows-10-vm-in-virtualbox-boots-to-grub-shell
- https://forums.virtualbox.org/viewtopic.php?f=3&t=98765
Are you installing Ubuntu Guest for the first time on UEFI boot? (Settings>System>Extended Features>Enable EFI) Found this command somewhere (if we are in the Shell like attached picture)
fs0: cd EFI/ubuntu grubx64.efi
For my case, just typed the last one "grubx64.efi" and enter then the live CD somehow take over. (Shell> grubx64.efi) Make sure your Settings>General>Version is Ubuntu(64-Bit). I'm using "ubuntu-20.04.1-desktop-amd64.iso", "VirtualBox-6.1.16-140961-Win.exe", also add "Oracle_VM_VirtualBox_Extension_Pack-6.1.16.vbox-extpack" for NVME virtualization. Source = Just search keyword: serverfault + how-to-install-ubuntu-server-12-04-in-a-virtualbox-vm-with-uefi-boot-enabled
dsm vm
panic问题
发现VirtualBox启动后,在一分钟以内,必然panic重启。可能和sata控制器有关,具体原因不明。但是用qemu是ok的
bridge模式无法获取通过dhcp分配ip问题
在启动了VirtualBox的dhcp功能后,可以获取到ip了,神奇啊,折腾了好久都搞不定,配上dhcp地址池后就ok了,什么原因?
pci passthrough - 在macos明确不支持,操作系统不支持
只有linux才能支持
nat + intel桌面网卡
可以获取到ip,能上网
nat + virtio
panic
admin@dsm617:/$ [ 96.549152] init: Caught abort, core dumped [ 96.555890] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000600 [ 96.555890] [ 96.563169] CPU: 1 PID: 1 Comm: init Tainted: P C O 3.10.102 #15284 [ 96.567909] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 96.574741] ffffffff814aafc8 ffffffff814aa09c 0000000000000010 ffff8800bb4a7ee8 [ 96.580367] ffff8800bb4a7e80 ffffffff8105dbf5 0000000000000600 ffff8800bb485b58 [ 96.586268] ffff8800bb485af0 0000000000000000 000000000000bb07 ffff8800b9275480 [ 96.592308] Call Trace: [ 96.594147] [<ffffffff814aafc8>] ? dump_stack+0xc/0x15 [ 96.597834] [<ffffffff814aa09c>] ? panic+0xbb/0x1ce [ 96.600463] [<ffffffff8105dbf5>] ? sched_move_task+0x95/0x110 [ 96.604490] [<ffffffff81036689>] ? do_exit+0xa29/0xa30 [ 96.609159] [<ffffffff810366f7>] ? do_group_exit+0x37/0x90 [ 96.612572] [<ffffffff8103675b>] ? SyS_exit_group+0xb/0x10 [ 96.617626] [<ffffffff814b0fb2>] ? system_call_fastpath+0x16/0x1b [ 96.622303] Rebooting in 3 seconds.. [ 99.709414] ACPI MEMORY or I/O RESET_REG.
host macos/QEMU
通过串口debug的时候真是爽,不知道VirtualBox要怎么配置,倒是可以把console的log打到文件里面,就是需要登录到console上,看看dsm磁盘和网卡的情况。为什么获取不到ip,不挂硬盘,单独用dsm的image是可以进入到console的。
dsm vm
网卡只能用bridge方式,需要tuntap 或者 tunnelblick的tuntap kext。推荐用tunnelblick进行过签名的kext版本。
nat + e1000
不配置网卡的话,默认是e1000
可以获取到ip,能上网
sudo qemu-system-x86_64 \ -cpu host \ -accel hvf \ -display none \ -machine pc \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=synoboot-ds3617xs-dsm617-20200824.img \ -net nic,model=e1000e,macaddr=00:11:32:f4:e4:18 \ -net tap,ifname=tap0,script=no,downscript=no #-net nic,model=virtio,macaddr=00:11:32:f4:e4:32 \
sudo qemu-system-x86_64 \ -cpu host \ -accel hvf \ -display none \ -machine pc \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=synoboot-ds3617xs-dsm617-20200824.img \ -device virtio-net-pci,netdev=eth0,mac='00:00:00:01:00:02' \ -netdev tap,ifname=tap0,id=eth0,script=no,downscript=no # -device e1000e,netdev=eth0,mac='00:00:00:01:00:01' \ # -netdev tap,ifname=tap0,id=eth0,script=no,downscript=no,vhost=on -device virtio-net-pci,netdev=dev1,mac='00:00:00:01:00:02',vectors=32,mq=on \ -netdev tap,ifname=tap-0,id=dev1,script=no,downscript=no,vhost=on,queues=16 \
sudo sysctl net.inet.ip.forwarding=1 sudo sysctl net.link.ether.inet.proxyall=1 # sudo sysctl net.inet.ip.fw.enable=1
https://github.com/Tunnelblick/Tunnelblick/issues/73 设置DHCP后,在tap0上居然可以抓到dhcp的ack包了,神奇了,但是为什么dsm不认呢?
sudo ifconfig bridge0 addm tap0 sudo ipconfig set tap0 DHCP
qemu help
$qemu-system-x86_64 -nic model=help Supported NIC models: e1000 e1000-82544gc e1000-82545em e1000e i82550 i82551 i82557a i82557b i82557c i82558a i82558b i82559a i82559b i82559c i82559er i82562 i82801 ne2k_pci pcnet rtl8139 tulip virtio-net-pci virtio-net-pci-non-transitional virtio-net-pci-transitional vmxnet3
$qemu-system-x86_64 -device e1000e,help e1000e options: acpi-index=<uint32> - (default: 0) addr=<int32> - Slot and optional function number, example: 06.0 or 06 (default: -1) bootindex=<int32> disable_vnet_hdr=<uint8> - Do not use virtio headers, perform SW offloads emulation instead (default: 0) failover_pair_id=<str> mac=<str> - Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56 multifunction=<bool> - on/off (default: false) netdev=<str> - ID of a netdev to use as a backend rombar=<uint32> - (default: 1) romfile=<str> romsize=<uint32> - (default: 4294967295) subsys=<uint16> - PCI device Subsystem ID (default: 0) subsys_ven=<uint16> - PCI device Subsystem Vendor ID (default: 32902) x-pcie-extcap-init=<bool> - on/off (default: true) x-pcie-lnksta-dllla=<bool> - on/off (default: true)
-device e1000e,netdev=dev0,mac='00:00:00:01:00:01' \ -netdev tap,ifname=tap-int,id=dev0,script=no,downscript=no,vhost=on \ -device virtio-net-pci,netdev=dev1,mac='00:00:00:01:00:02',vectors=32,mq=on \ -netdev tap,ifname=tap-0,id=dev1,script=no,downscript=no,vhost=on,queues=16 \
nat + e1000 + raw physical disk
可以telnet正常登录,看见盘,需要解决dhcp获取ip的问题
如果VirtualBox可以bridge方式获取dhcp,那intel的网卡驱动应该是没有问题的吧,为什么qemu使用操作系统的bridge方式就不行呢?
不用tunnelblick的tap kext,改为tuntaposx的看看,用brew install tuntap 安装
vmnet for qemu on macos - 要编译源码吗?
https://forum.osdev.org/viewtopic.php?f=1&t=39828
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04637.html
另外一个用vmnet.framework给qemu打patch的,牛逼啊 https://www.mail-archive.com/qemu-devel@nongnu.org/msg816630.html
真多,有问问题的,没有答案 https://www.mail-archive.com/qemu-devel@nongnu.org/msg750375.html
compile qemu on macos
https://alexwinston.wordpress.com/2015/09/10/compiling-qemu-on-osx/
Compiling QEMU on OSX
After googling quite extensively I was unable to find a definitive guide to compile QEMU on OS X Yosemite so I pieced together the steps myself and have documented them below. It should be noted that MacPorts does have a port for QEMU 2.3 but I wanted to compile the newest version from GitHub myself.
It is assumed that Xcode and the CLI tools are already installed.
The first and most important step is to install MacPorts
After this is complete it is a simple matter of installing the required ports from the command line.
sudo port install pkgconfig sudo port install glib2 sudo port install libpixman sudo port self update sudo port upgrade outdated
After the ports have been installed the QEMU source should be downloaded from github from the command line.
git clone git://git.qemu.org/qemu.git;
After downloading the source the most important piece of the puzzle seems to be the following
cd qemu git submodule update –init dtc
Once this submodule has been downloaded you can configure and make QEMU.
./configure –enable-cocoa –target-list=i386-softmmu,arm-softmmu,x86_64-softmmu,aarch64-softmmu –disable-vnc make
This particular configuration demonstrates compiling several of the target architectures available in QEMU. Adding or removing architectures from the –target-list will be required to meet your particular needs.
If QEMU builds successfully you should now have directories for each architecture listed in the –target-list.
A simple way to test that everything is working as expected is to run QEMU for x86_64. Before you do this however it is worth downloading the Tiny Core Linux iso for testing in QEMU.
./x86_64-softmmu/qemu-system-x86_64 -cdrom Core-current.iso -boot d -net nic -net user,hostfwd=tcp:127.0.0.1:8008-:80
Tiny Core Linux should boot and drop you to a command prompt after pressing “enter”.
The following links were invaluable in helping to determine exactly how to build and test QEMU 2.4 on the Mac.
https://jon.sprig.gs/blog/post/53 https://github.com/psema4/pine/wiki/Installing-QEMU-on-OS-X http://blog.definedcode.com/osx-qemu-kvm https://theintobooks.wordpress.com/2012/10/30/installing-qemu/ http://blogs.coreboot.org/blog/2015/06/03/gsoc-coreboot-for-arm64-qemu-week-1/ http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/
也可以看看 https://theintobooks.wordpress.com/2016/03/03/installing-qemu-on-mac-os-x-el-capitan/
Build qemu on MacOS Submitted by peter on Fri, 02/02/2018 - 11:51 看着qemu的版本很老 https://notes.bitfunnel.net/?q=node/50
使用不同的glibc
brew install安装的glib版本太高,查到只有2.58.3及以下的版本编译的qemu,bridge+tap才是正常的。而且2.58.3以下版本编译的qemu,使用vmnet framework也是ok的。
失败的尝试
试了下面几个环境变量,configure会报错。
GLIBC=/Volumes/sandisk/Users/albert/glib-2.58.3 ./configure --enable-cocoa --target-list=x86_64-softmmu GLIB_LIBS="-L/Volumes/sandisk/Users/albert/glib-2.58.3 -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0"
export GLIB_CONFIG=/Volumes/sandisk/Users/albert/glib-2.58.3 ./configure --enable-cocoa --target-list=x86_64-softmmu ./configure --enable-cocoa --target-list=x86_64-softmmu --with-internal-glib=/Volumes/sandisk/Users/albert/glib-2.58.3
尝试一下自己编译的c文件是否能读到glib版本,编译过不去。
#-I/usr/local/Cellar/glib/2.68.4/include -I/usr/local/Cellar/glib/2.68.4/include/glib-2.0 -I/usr/local/Cellar/glib/2.68.4/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.45/include -Werror -o config-temp/qemu-conf.exe config-temp/qemu-conf.c -m64 -fstack-protector-strong -L/usr/local/Cellar/glib/2.68.4/lib -L/usr/local/opt/gettext/lib -lgthread-2.0 -lglib-2.0 gcc -I/Volumes/sandisk/Users/albert/glib-2.58.3/include -I/Volumes/sandisk/Users/albert/glib-2.58.3/lib/glib-2.0/include -I/Volumes/sandisk/Users/albert/glib-2.58.3/include/glib-2.0 -Werror -L/Volumes/sandisk/Users/albert/glib-2.58.3/include -lglib-2.0 *.c
qemu的configure里是通过pkg-config来找依赖的modules的编译和头文件路径的
详解pkg-config –cflags –libs glib-2.0的作用 https://blog.csdn.net/shenwansangz/article/details/48738677
pkg-config
来查找 glib
的path,服了,搞死人啊。
./configure 3294 ########################################## 3295 # glib support probe 3296 3297 glib_req_ver=2.48 3298 glib_modules=gthread-2.0 3299 if test "$modules" = yes; then 3300 glib_modules="$glib_modules gmodule-export-2.0" 3301 fi 3302 if test "$plugins" = yes; then 3303 glib_modules="$glib_modules gmodule-2.0" 3304 fi 3305 3306 for i in $glib_modules; do 3307 if $pkg_config --atleast-version=$glib_req_ver $i; then 3308 glib_cflags=$($pkg_config --cflags $i) 3309 glib_libs=$($pkg_config --libs $i) 3310 else 3311 error_exit "glib-$glib_req_ver $i is required to compile QEMU" 3312 fi 3313 done # 直接设置环境变量 PKG_CONFIG_PATH=/Volumes/sandisk/Users/albert/glib-2.58.3/lib/pkgconfig pkg-config --libs gthread-2.0 # 这样编译是ok的。查看 build/config.log里面的glib指向了2.58.3版本的glib PKG_CONFIG_PATH=/Volumes/sandisk/Users/albert/glib-2.58.3/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --enable-cocoa --target-list=x86_64-softmmu
本机上用 pkg-config 查看 gthread-2.0 的结果,用的是brew安装的glib,版本是2.66.4_1
$pkg-config --libs gthread-2.0
-L/usr/local/Cellar/glib/2.66.4_1/lib -L/usr/local/opt/gettext/lib -lgthread-2.0 -lglib-2.0 -lintl
pkg-config说明
The pkg-config package contains tools for passing the include path and/or library paths to build tools during the make file execution.
pkg-config is a function that returns meta information for the specified library.
The default setting for PKG_CONFIG_PATH is /usr/lib/pkgconfig because of the prefix we use to install pkgconfig. You may add to PKG_CONFIG_PATH by exporting additional paths on your system where pkgconfig files are installed. Note that PKG_CONFIG_PATH is only needed when compiling packages, not during run-time.
- PKG_CONFIG_PATH 环境变量
ENVIRONMENT VARIABLES PKG_CONFIG_PATH A colon-separated (on Windows, semicolon-separated) list of di- rectories to search for .pc files. The default directory will always be searched after searching the path; the default is libdir/pkgconfig:datadir/pkgconfig where libdir is the libdir for pkg-config and datadir is the datadir for pkg-config when it was installed.
- 下个问题是我怎么知道到底链接了哪个glib?
otool
? macos下是没有ldd
的。
sudo ./qemu-system-x86_64 \ -cpu host \ -accel hvf \ -display none \ -machine pc \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -drive if=sata,format=raw,file=/dev/disk1s4 \ -device virtio-net-pci,netdev=eth0,mac='00:11:32:01:02:03' \ -netdev vmnet-macos,id=eth0,mode=bridged,ifname=en3
vmnet-v6.1.0-patches-v2版本
编译
cd /Volumes/sandisk/Users/albert/workspace/vmnet-v6.1.0-patches-v2/qemu PKG_CONFIG_PATH=/Volumes/sandisk/Users/albert/glib-2.58.3/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --enable-cocoa --target-list=x86_64-softmmu --enable-vmnet --enable-vhost-net # 报错,只支持linux --enable-vhost-scsi --enable-vhost-kernel [2021-09-08 Wed 12:25:11] --enable-vhost-net 在link的时候报错了。
查看编译的qemu支持的网络模式
[albert@G1 /Volumes/sandisk/Users/albert/workspace/vmnet-v6.1.0-patches-v2/qemu/build]
$./qemu-system-x86_64 -netdev type=help
Available netdev backend types:
socket
hubport
tap
user
vde
bridge
vhost-user
vmnet-host
vmnet-shared
vmnet-bridged
用qemu启动DSM进行测试,很好,DSM启动ok,可以进入系统,通过DHCP获取ip。
cd /Volumes/sandisk/Users/albert/workspace/vmnet-v6.1.0-patches-v2/qemu/build sudo ./qemu-system-x86_64 \ -cpu host \ -smp 2 \ -accel hvf \ -display none \ -machine pc \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -drive format=raw,file=/dev/disk1s4 \ -device virtio-net-pci,netdev=eth0,mac='00:11:32:01:02:03' \ -netdev vmnet-bridged,id=eth0,ifname=en3 #-drive if=ide,format=raw,file=/dev/disk1s4 \
sudo ./qemu-system-x86_64 \ -cpu host \ -smp 2 \ -accel hvf \ -display none \ -machine q35 \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/Downloads/alpine-standard-3.14.2-x86_64.iso \ -device virtio-net-pci,netdev=eth0,mac='00:11:32:01:02:03' \ -netdev vmnet-bridged,id=eth0,ifname=en3
使用 virtio-scsi,没有悬念,必挂无疑,直接panic了。
./qemu-system-x86_64 \ -cpu host \ -smp 2 \ -accel hvf \ -display none \ -machine q35 \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -device virtio-scsi-pci,id=scsi0,num_queues=4 \ -device scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0 \ -drive file=/dev/disk1s4,if=none,id=drive0
sudo ./qemu-system-x86_64 \ -cpu host \ -smp 2 \ -accel hvf \ -display none \ -machine q35 \ -monitor tcp:0.0.0.0:4001,server,nowait \ -m 3072 \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -device megasas,id=scsi0 \ -device scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0 \ -drive file=/dev/disk1s4,if=none,id=drive0
virtio-blk 看看如何?找不到硬盘。
sudo ./qemu-system-x86_64 \ -cpu host -smp 2 -accel hvf -machine q35 -m 3072 \ -display none -monitor tcp:0.0.0.0:4001,server,nowait \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -device virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4 \ -drive file=/dev/disk1s4,if=none,id=drive0
看看iso格式,如何用qemu命令行加载。
qemu-system-x86_64 -bios /usr/share/ovmf/ovmf_x64.bin \ -cpu host -enable-kvm -m 2G \ -drive file=/dev/md0,media=disk,format=raw \ -cdrom /path/to/windows.iso
用这个命令
sudo ./qemu-system-x86_64 \ -machine q35 -cpu host -smp 2 -accel hvf -m 3072 \ -display none \ -monitor tcp:0.0.0.0:4001,server,nowait \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -drive format=raw,file=/dev/disk1s4 \ -device virtio-net-pci,netdev=eth0 \ -netdev vmnet-bridged,id=eth0,ifname=en3
macports是如何编译qemu的
已经从前几天安装是的5.2版本升级到6.1.0版本了 https://github.com/macports/macports-ports/blob/master/emulators/qemu/Portfile
- dependency
- glib2
https://download.gnome.org/sources/glib/2.58/glib-2.58.3.tar.xz
[albert@Macmini /Users/albert/workspace/glib-2.58.3] $./autogen.sh You don't have gtk-doc installed, and thus won't be able to generate the documentation. *** No autoreconf found, please install it *** [albert@Macmini /Users/albert/workspace/glib-2.58.3] $brew install autoconf
接着报错,需要安装 automake
autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force -I m4macros ${ACLOCAL_FLAGS} sh: aclocal: command not found autoreconf: error: aclocal failed with exit status: 127 brew install automake
./configure --prefix=/Users/albert/qemu/glib-2.58.3
- libpixman
Pixel region Library
libpixman is a generic library for manipulating pixel regions. A PixRegion is a set of Y-X banded rectangles that cover the desired region.
$brew install pixman Updating Homebrew... Warning: pixman 0.40.0 is already installed and up-to-date. To reinstall 0.40.0, run: brew reinstall pixman
- libusb
$brew install libusb Warning: libusb 1.0.24 is already installed and up-to-date. To reinstall 1.0.24, run: brew reinstall libusb
- zlib
$brew install zlib ==> Pouring zlib--1.2.11.catalina.bottle.tar.gz ==> Caveats zlib is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. For compilers to find zlib you may need to set: export LDFLAGS="-L/usr/local/opt/zlib/lib" export CPPFLAGS="-I/usr/local/opt/zlib/include" For pkg-config to find zlib you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig" ==> Summary � /usr/local/Cellar/zlib/1.2.11: 12 files, 376.6KB
- glib2
- compile
cd ~/workspace/vmnet-v6.1.0-patches-v2 git clone -b vmnet-v6.1.0-patches-v2 --depth=10 git@github.com:shchuko/qemu # 检查glib的版本是2.58.3吗 pkg-config --libs gthread-2.0 PKG_CONFIG_PATH=/Users/albert/qemu/glib-2.58.3/lib/pkgconfig:$PKG_CONFIG_PATH pkg-config --libs gthread-2.0 -L/Users/albert/qemu/glib-2.58.3/lib -lgthread-2.0 -lglib-2.0 -lintl -Wl,-framework -Wl,CoreFoundation PKG_CONFIG_PATH=/Users/albert/qemu/glib-2.58.3/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --prefix=/Users/albert/qemu --enable-cocoa --target-list=x86_64-softmmu --enable-vmnet --enable-vhost-net --enable-vhost-kernel
如果需要支持avx avx2,参考 https://wiki.qemu.org/Hosts/Mac ,安装
llvm
cd /Users/albert/workspace/vmnet-v6.1.0-patches-v2/qemu/build sudo ./qemu-system-x86_64 \ -machine q35 -cpu host -smp 2 -accel hvf -m 3072 \ -display none \ -monitor tcp:0.0.0.0:4001,server,nowait \ -serial telnet:0.0.0.0:5001,server,nowait \ -usb -drive if=none,format=raw,id=disk1,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -device usb-storage,drive=disk1 \ -drive format=raw,file=/dev/disk1 \ -device virtio-net-pci,netdev=eth0 \ -netdev vmnet-bridged,id=eth0,ifname=en0 #-drive format=raw,file=/dev/disk1 \
- vhost-net是不支持macos的
https://www.redhat.com/en/blog/introduction-virtio-networking-and-vhost-net https://www.redhat.com/en/blog/deep-dive-virtio-networking-and-vhost-net
vhost-net
需要vhost-kernel
,vhost-kernel只支持linux。无法在host层面实现了。只能在guest vm中使用virtio-net
。为什么会报错呢?在笔记本上编译为什么不报错?
tls/3.6.16/lib -Wl,-rpath,/usr/local/Cellar/pixman/0.40.0/lib -Wl,-rpath,/usr/lib -Wl,-rpath,/usr/local/Cellar/jpeg/9d/lib -Wl,-rpath,/usr/local/Cellar/libusb/1.0.24/lib -lc++ Undefined symbols for architecture x86_64: "_vhost_ack_features", referenced from: _vhost_net_ack_features in hw_net_vhost_net.c.o _vhost_net_init in hw_net_vhost_net.c.o "_vhost_dev_cleanup", referenced from: _vhost_net_init in hw_net_vhost_net.c.o _vhost_net_cleanup in hw_net_vhost_net.c.o "_vhost_dev_disable_notifiers", referenced from: _vhost_net_start in hw_net_vhost_net.c.o _vhost_net_stop_one in hw_net_vhost_net.c.o "_vhost_dev_enable_notifiers", referenced from: _vhost_net_start in hw_net_vhost_net.c.o "_vhost_dev_get_config", referenced from: _vhost_net_get_config in hw_net_vhost_net.c.o "_vhost_dev_init", referenced from: _vhost_net_init in hw_net_vhost_net.c.o "_vhost_dev_set_config", referenced from: _vhost_net_set_config in hw_net_vhost_net.c.o "_vhost_dev_start", referenced from: _vhost_net_start in hw_net_vhost_net.c.o "_vhost_dev_stop", referenced from: _vhost_net_start in hw_net_vhost_net.c.o _vhost_net_stop_one in hw_net_vhost_net.c.o "_vhost_get_features", referenced from: _vhost_net_get_features in hw_net_vhost_net.c.o "_vhost_net_set_backend", referenced from: _vhost_net_start in hw_net_vhost_net.c.o _vhost_net_stop_one in hw_net_vhost_net.c.o "_vhost_virtqueue_mask", referenced from: _vhost_net_virtqueue_mask in hw_net_vhost_net.c.o (maybe you meant: _cryptodev_vhost_virtqueue_mask) "_vhost_virtqueue_pending", referenced from: _vhost_net_virtqueue_pending in hw_net_vhost_net.c.o (maybe you meant: _cryptodev_vhost_virtqueue_pending) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Configurable features Documentation: NO system-mode emulation: YES user-mode emulation: NO block layer: YES Install blobs: YES module support: NO fuzzing support: NO Audio drivers: coreaudio sdl Trace backends: log QOM debugging: YES vhost-kernel support: NO vhost-net support: YES vhost-crypto support: NO vhost-scsi support: NO vhost-vsock support: NO vhost-user support: NO vhost-user-blk server support: NO vhost-user-fs support: NO vhost-vdpa support: NO vmnet support: YES build guest agent: YES vhost-net vhost-net kernel acceleration support vhost-vsock virtio sockets device support vhost-scsi vhost-scsi kernel target support vhost-crypto vhost-user-crypto backend support vhost-kernel vhost kernel backend support vhost-user vhost-user backend support vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support Crypto TLS priority: "NORMAL" GNUTLS support: YES GNUTLS crypto: YES libgcrypt: NO nettle: NO crypto afalg: NO rng-none: NO Linux keyring: NO PKG_CONFIG_PATH=/Users/albert/qemu/glib-2.58.3/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --prefix=/Users/albert/qemu --enable-cocoa --target-list=x86_64-softmmu --enable-vmnet --enable-vhost-net ERROR: --enable-vhost-vsock requires --enable-vhost-kernel ERROR: vhost-user is only available on Linux ERROR: vhost-vdpa is only available on Linux ERROR: --enable-vhost-scsi requires --enable-vhost-kernel ERROR: vhost-kernel is only available on Linux --enable-mpath ../meson.build:164:2: ERROR: Problem encountered: Multipath is supported only on Linux
brew install libgcrypt # 再看看? brew install nettle # 已经安装了 #[2021-09-09 Thu 12:03:07] Has header "lzfse.h" : NO brew install lzfse /usr/local/Cellar/lzfse/1.0: 7 files, 63.5KB # [2021-09-09 Thu 12:06:29] # Run-time dependency capstone found: NO (tried pkgconfig) # Configuring capstone-defs.h using configuration # capstone - Multi-platform, multi-architecture disassembly framework brew install capstone /usr/local/Cellar/capstone/4.0.2: 25 files, 14.6MB
sudo ./qemu-system-x86_64 \ -machine q35 -cpu host -smp 2 -accel hvf -m 3072 \ -display none \ -monitor tcp:0.0.0.0:4001,server,nowait \ -serial telnet:0.0.0.0:5001,server,nowait \ -drive if=ide,format=raw,file=/Users/albert/dsm/synoboot-ds3617xs-dsm617-20200824.img \ -drive media=disk,format=raw,file=/dev/disk1 \ -device virtio-net-pci,netdev=eth0 \ -netdev vmnet-bridged,id=eth0,ifname=en0
- vhost-net是不支持macos的
iperf3 测试网速和cpu
用wifi的效果可以。在600Mb/s,再用网线试试。
macos是否有losetup和mdadm类似的命令
gvt-d on macos
linux上的,不是macos上的 https://www.reddit.com/r/VFIO/comments/innriq/successful_macos_catalina_with_intel_gvtg/
这里讨论了gpu pci passthrough在macos的情况,结论是没有可能。 https://forums.macrumors.com/threads/egpu-parallels.2276462/