转载: 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
[*] 64-bit kernel (leave blank for x86)
 
General Setup --->
  [*] Optimize very unlikely/likely branches
 
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

refer to:
https://forums.gentoo.org/viewtopic-p-7332884.html#7332884

利用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

注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

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