Install VMWare Player in Fedora

After

1
dnf install kernel-headers kernel-devel

we still failed building kernel modules for VMWare Player in fedora,

1
vm_basic_defs.h:54:12: fatal error: stddef.h: No such file or directory

A solution is

1
2
3
4
# e.g. current kernel version is 5.16.12-200.fc35.x86_64
cd /usr/src/kernel/5.16.12-200.fc35.x86_64/include
ln -s linux/stddef.h stddef.h
ln -s linux/stdarg.h stdarg.h

refer to:
https://stackoverflow.com/questions/54480765/how-can-i-solve-stdarg-h-no-such-file-or-directory-while-compiling-out-of-tree-l

Fedora kernel: bad shim signature

One easy method is disabling Secure Boot option in machine EFI BIOS.

In other way, we can't sign vmlinuz using MOK, because MOK is only a gate keeper for kernel after vmlinuz booting up, and if we want EFI firmware to admit vmlinuz as descendant, we must require the machine manufacturer to sign the vmlinuz we built.

MOK: Machine Owner Key
UEFI: Unified Extensible Firmware Interface

refer to:
https://www.rodsbooks.com/efi-bootloaders/secureboot.html

Optimizing the kernel for VMware

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
[*] 64-bit kernel (leave blank for x86)
 
General Setup --->
  [*] Optimize very unlikely/likely branches
 
Power management and ACPI options --->
  [*] ACPI (Advanced Configuration and Power Interface) Support --->
 
Processor type and features --->
  Processor Family (usually Core2/Newer Xeon)
 
Bus Options --->
  < > PCCard (PCMCIA/Cardbus) support
 
Networking support --->
  [ ] Amateur Radio support
  [ ] Wireless (only if you plan on using nat EXCLUSIVELY)
 
Device Drivers --->
  Generic Driver Options
    [*] Maintain a devtmpfs filesystem to mount at /dev
 
  Misc Devices --->
    [*] VMware Balloon Driver (manages memory between VM and host)
    [*] VMware VMCI Driver (Virtual Machine Communication Interface - low-latency access to host memory bus)
 
  SCSI device support --->
    [*] SCSI low-level drivers --->
      <*> VMware PVSCSI driver support (high throughput storage adapter)
 
  [*] Fusion MPT device support --->
    <*> Fusion MPT ScsiHost drivers for SPI
 
  [*] Network device support --->
    [*] Ethernet driver support --->
      (disable every driver but this)
      [*] AMD Devices
        <*> AMD PCNet32 PCI support
    [ ] Wireless LAN (ONLY if you disabled Wireless networking support above)
    < > VMware VMXNET3 ethernet driver (PCNet32 is more than enough for most use cases - enable this only if you have spare cpu cycles to burn)
 
  Graphics support --->
    <*> Direct Rendering Manager
    < > Intel 8xx/9xx/G3x/G4x/HD Graphics
    <*> DRM driver for VMware Virtual GPU
      [*] Enable framebuffer console support under vmwgfx by default
    <*> Support for frame buffer devices
 
    Console display driver support --->
      <*> Framebuffer Console support
 
  Sound card support --->
    <*> Advanced Linux Sound Architecture --->
      [*] PCI sound devices
        <*> (Creative) Ensoniq AudioPCI 1371/1373
        < > Intel HD Audio
 
  File systems --->
    (enable only those you anticipate using)
    <*> Second extended fs support
    <*> The Extended 4 (ext4) filesystem
    <*> XFS filesystem support
    <*> Btrfs filesystem Unstable disk format
 
    Pseudo filesystems --->
      [*] Tmpfs virtual memory file system support (former shm fs)
        [*] Tmpfs POSIX Access Control Lists

efi boot (uncertain, maybe need to ask pc maker for signing the kernel.)

1
2
3
4
5
6
Processor type and features --->
  [*] EFI runtime service support 
  [*]   EFI stub support
Firmware Drivers  --->
   EFI (Extensible Firmware Interface) Support  --->
       <*> EFI Variable Support via sysfs

device mapper

1
2
3
Device Drivers
	Multiple devices driver support (RAID and LVM)
		<M>   Device mapper support

refer to:
https://forums.gentoo.org/viewtopic-p-7332884.html
https://stackoverflow.com/questions/40344484/cant-load-self-compiled-linux-kernel

利用vmware调试kernel

在vmware虚拟机A上

1
2
apt install libssl-dev
apt install libncurses-dev

从文后链接中下载kernel源码,比如版本4.15.18,解压编译

1
2
3
4
make menuconfig
make
make modules_install
make install

A关机,克隆A为B,A的虚拟机设置中增加串口

1
2
3
使用命名管道:\\.\pipe\com_1
该端是服务器。
另一端是虚拟机。

B的虚拟机设置中增加串口

1
2
3
使用命名管道:\\.\pipe\com_1
该端是客户端。
另一端是虚拟机。

A以新编译的内核引导,可能事先要加大内存;B以旧内核引导。在B中运行

1
cat < /dev/ttyS1

在A中运行

1
echo Helloworld > /dev/ttyS1

如果B中回显消息,说明串口连通。
编辑A中的/boot/grub/grub.cfg,找到新编译内核启动项,在handoff后加入kgdbwait kgdboc=ttyS1,115200 nokaslr,如

1
linux /boot/vmlinuz-4.15.18 root=UUID=7ccc722d-2cbd-4597-a367-e0635333ddbf ro quiet splash $vt_handoff kgdbwait kgdboc=ttyS1,115200 nokaslr

B退出cat程序,A重启以新编译的内核引导到kdb等待状态。在B中kernel源码根目录运行

1
2
3
4
5
gdb vmlinux
set serial baud 115200
target remote /dev/ttyS1
lx-symbols
c

A中进入系统后可用下面语句触发调试

1
2
3
#echo 1 > /proc/sys/kernel/sysrq
#echo kms,kbd > /sys/module/kgdboc/parameters/kgdboc
echo g > /proc/sysrq-trigger

vmware串口调试提速的方法为,关掉此虚拟机,编辑启动文件.vmx,加入

1
serial1.pipe.charTimePercent = "25"

其中serial1要因时而变,要查找同文件中是否有同样名称。
运行后很稳定的话,还可将25再改小再试。

注1:因为新内核的KASLR机制,如果在内核启动命令行中不加入nokaslr,调试时看到不到堆栈也下不了断点。Cannot insert breakpoint。

注2:因为源地址无法访问了,有个未尝试的点摘抄下来

1
2
3
在没有编译内核的情况下,还可以直接通过修改虚拟机的启动文件.vmx,添加:
debugStub.listen.guest32 = "TRUE"
然后在调试机器中通过:target remote ip:8832(8864)来调试,ip为真实机器的IP

refer to:
https://mirrors.edge.kernel.org/pub/linux/kernel/
https://stackoverflow.com/questions/49360506/in-kgdb-i-cannot-set-the-breakpoint
https://askubuntu.com/questions/964540/gdb-qemu-cant-put-break-point-on-kernel-function-kernel-4-10-0-35
https://www.cnblogs.com/xiaofool/p/5377737.html
https://docs.vmware.com/en/VMware-Workstation-Pro/12.0/com.vmware.ws.using.doc/GUID-B285C62D-1E7E-49E8-81D6-77910B2024A6.html

ubuntu下载当前版本内核源码

1
vi /etc/apt/sources.list

uncomment lines beginning with 'deb-src' and save, then

1
2
apt-get update
apt-get source linux-image-unsigned-$(uname -r)

refer to:
https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel
https://stackoverflow.com/questions/45766719/error-during-ubuntu-kernel-source-download