如何运行用户模式 ​​Linux 内核?

如何运行用户模式 ​​Linux 内核?

我按照这里的步骤在用户模式下成功编译了内核: https://btrfs.wiki.kernel.org/index.php/Debugging_Btrfs_with_GDB

但是当我./linux以各种方式开始时,它总是给我一个非常相似的错误:

pc@linux-94q0:~/linux-4.11-rc4> ./linux root=/mnt
Core dump limits :
    soft - 0
    hard - NONE
Checking that ptrace can change system call numbers...OK
Checking syscall emulation patch for ptrace...OK
Checking advanced syscall emulation patch for ptrace...OK
Checking environment variables for a tempdir...none found
Checking if /dev/shm is on tmpfs...OK
Checking PROT_EXEC mmap in /dev/shm...OK
Adding 33251328 bytes to physical memory to account for exec-shield gap
Linux version 4.11.0-rc4 (pc@linux-94q0) (gcc version 4.8.5 (SUSE Linux) ) #1 Fri Mar 31 12:40:07 CEST 2017
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16087
Kernel command line: root=/mnt
PID hash table entries: 256 (order: -1, 2048 bytes)
Dentry cache hash table entries: 8192 (order: 4, 65536 bytes)
Inode-cache hash table entries: 4096 (order: 3, 32768 bytes)
Memory: 26140K/65240K available (3518K kernel code, 770K rwdata, 948K rodata, 114K init, 195K bss, 39100K reserved, 0K cma-reserved)
NR_IRQS:15
clocksource: timer: mask: 0xffffffffffffffff max_cycles: 0x1cd42e205, max_idle_ns: 881590404426 ns
Calibrating delay loop... 6966.47 BogoMIPS (lpj=34832384)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes)
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
devtmpfs: initialized
Using 2.6 host AIO
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: 0, 6144 bytes)
xor: measuring software checksum speed
   8regs     : 19749.600 MB/sec
   8regs_prefetch: 17312.000 MB/sec
   32regs    : 18694.400 MB/sec
   32regs_prefetch: 17317.600 MB/sec
xor: using function: 8regs (19749.600 MB/sec)
NET: Registered protocol family 16
raid6: int64x1  gen()  4139 MB/s
raid6: int64x1  xor()  2318 MB/s
raid6: int64x2  gen()  3758 MB/s
raid6: int64x2  xor()  2685 MB/s
raid6: int64x4  gen()  3413 MB/s
raid6: int64x4  xor()  2153 MB/s
raid6: int64x8  gen()  2865 MB/s
raid6: int64x8  xor()  1626 MB/s
raid6: using algorithm int64x1 gen() 4139 MB/s
raid6: .... xor() 2318 MB/s, rmw enabled
raid6: using intx1 recovery algorithm
clocksource: Switched to clocksource timer
VFS: Disk quotas dquot_6.6.0
VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
NET: Registered protocol family 2
TCP established hash table entries: 512 (order: 0, 4096 bytes)
TCP bind hash table entries: 512 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 512 bind 512)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
NET: Registered protocol family 1
console [stderr0] disabled
mconsole (version 2) initialized on /home/pc/.uml/y33GMV/mconsole
Checking host MADV_REMOVE support...OK
workingset: timestamp_bits=62 max_order=13 bucket_order=0
io scheduler noop registered
io scheduler deadline registered (default)
io scheduler mq-deadline registered
NET: Registered protocol family 17
Initialized stdio console driver
Console initialized on /dev/tty0
console [tty0] enabled
Initializing software serial port version 1
console [mc-1] enabled
Failed to initialize ubd device 0 :Couldn't determine size of device's file
Btrfs loaded, crc32c=crc32c-generic, debug=on
VFS: Cannot open root device "/mnt" or unknown-block(0,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 0 PID: 1 Comm: swapper Not tainted 4.11.0-rc4 #1
Stack:
 6381bd80 60066344 602a250a 62cab500
 602a250a 600933ba 6381bd90 60297e6f
 6381beb0 60092b41 6381be30 60380ea1
Call Trace:
 [<600933ba>] ? 
printk+0x0/0x94
 [<6001c4d8>] 
show_stack+0xfe/0x158
 [<60066344>] ? 
dump_stack_print_info+0xe1/0xea
 [<602a250a>] ? 
bust_spinlocks+0x0/0x4f
 [<602a250a>] ? 
bust_spinlocks+0x0/0x4f
 [<600933ba>] ? 
printk+0x0/0x94
 [<60297e6f>] 
dump_stack+0x2a/0x2c
 [<60092b41>] 
panic+0x173/0x322
 [<60380ea1>] ? 
klist_next+0x0/0xa6
 [<600929ce>] ? 
panic+0x0/0x322
 [<600cac33>] ? 
kfree+0x0/0x8a
 [<600f01da>] ? 
SyS_mount+0xae/0xc0
 [<600933ba>] ? 
printk+0x0/0x94
 [<600f012c>] ? 
SyS_mount+0x0/0xc0
 [<60002378>] 
mount_block_root+0x356/0x374
 [<6029e3f9>] ? 
strcpy+0x0/0x18
 [<60002432>] 
mount_root+0x9c/0xa0
 [<6029e543>] ? 
strncmp+0x0/0x25
 [<60002614>] 
prepare_namespace+0x1de/0x238
 [<600eb9d3>] ? 
SyS_dup+0x0/0x5e
 [<60001ee1>] 
kernel_init_freeable+0x300/0x31b
 [<600933ba>] ? 
printk+0x0/0x94
 [<603835e9>] 
kernel_init+0x1c/0x14a
 [<6001b140>] 
new_thread_handler+0x81/0xa3

Aborted (core dumped)

我现在已经尝试了我能想到的一切来满足这个./linux root=选项,但似乎没有任何效果。

  1. 我创建了一个根文件系统https://buildroot.org/,将其作为 .gz、.tar、.tar.gz、未压缩文件夹传递
  2. 我将 buildroot.org 的内容放入 btrfs 循环设备中,然后右键单击磁盘实用程序并创建一个 .img 文件。尝试从那开始。
  3. 当然,我尝试了所有我能想到的常用选项,比如./linux root=/mnt./linux root=/dev/loop0

我不知道还能尝试什么。为什么这不起作用?我尝试找出-6错误代码的含义,但似乎所有Linux内核错误代码都是正数。 https://gist.github.com/nullunar/4553641

我真的不知道还能做什么,我想我可以开始花几个小时阅读 udb 的内容到底意味着什么,但我真的希望有人能告诉我需要传递给命令行的内容我现在的兴趣只是调试 btrfs,而不是一般的 Linux。

答案1

https://www.linux.com/news/how-run-linux-inside-linux-user-mode-linux

./linux-2.6.19-rc5 ubda=FedoraCore5-x86-root_fs mem=128M
此命令中的 ubda 参数为 UML 内核提供一个文件名,用于创建虚拟机的 /dev/ubda 虚拟块设备,该设备将成为其根文件系统。

答案2

我已经在以下位置详细描述了有效的 Buildroot 设置:如何在 Fedora 18 上为用户模式 ​​Linux 创建 rootfs?

主要的问题是我必须破解 BusyBoxinit才能添加::sysinit:/sbin/mdev -s to the inittab.

相关内容