add linux_emul base, reorganize docs
[openbsd_emul.git] / linux_emul_base / README
CommitLineData
cae36a52 1INTRO
2
3Linuxemu is a program that can execute Linux/i386 ELF binaries on
4Plan9. It was started by Russ Cox and development was continued by
5me. Its opensource, I dont care what you are doing with it, but maybe
6Russ does, i don't know :-)
7
8If you found some bugs or have some other improvements/ideas send a
9email to:
10
11cinap_lenrek AT gmx DOT de
12
13
14SOURCE
15
16linuxemu is available on sources. On Plan9 do:
17
18% 9fs sources
19% cp /n/sources/contrib/cinap_lenrek/linuxemu3.tgz .
20
21Another source is my server on the web:
22
23% hget http://9hal.ath.cx/usr/cinap_lenrek/linuxemu3.tgz >linuxemu3.tgz
24
25
26DOCUMENTATION
27
28documentation is provided in the doc directory:
29
30doc/linuxemu.txt
31doc/todo.txt
32
33
34COMPILE
35
36% tar xzf linuxemu3.tgz
37% cd linuxemu3
38% mk
39
40
41INSTALL
42
43% mk install
44
45
46BOOTSTRAP
47
48You need a linux rootfilesystem packed in a tarball. Go!
49get some linux rootfs:
50
51http://9hal.ath.cx/usr/cinap_lenrek/mroot.tbz
52http://9hal.ath.cx/usr/cinap_lenrek/mroot-linuxemu.tbz
53
54the -linuxemu version contains no symlinks and can be extracted with
55plain plan9 tools bunzip/tar so you can skip the BOOTSTRAP section.
56:-)
57
58You can create your own with debootstrap on debian linux... or help
59me write a installer that unpacks and installs slackware on plan9...
60In any case, linuxemu is not hardwared to any linux distribution!
61
62Extract your linux rootfilesystem with the static linked gnutar from
63the bootstrap directory. (This will create all the fake symlinks for
64you)
65
66% 8.out bootstrap/tar xf /tmp/mroot.tar
67
68
69RUNNING
70
71Then you can use the linux script to "chroot" into your linux
72rootfs. the linux script is neccesary because for linux programs
73to run shared libraries from your linux root have to appear at /lib
74and /usr/lib and configuration files are expected to be in /etc.
75the script will build a private namespace and bind the linuxroot
76over the plan9 root. the original plan9 namespace is mounted to /9.
77
78% linux -r ./mroot /bin/bash -i
79
80if you omit the -r option, the linuxroot defaults to /sys/lib/linux. you
81may put your linux root there or add a bind to your $home/lib/profile.
82
83You should change /etc/resolv.conf to match your network nameserver
84setup. Also, you may want to edit /etc/apt/sources.list to change the
85debian mirror.
86
87
88DEBUGGING
89
90If linuxemu crashes, use acid to figure out whats going on:
91
92% mk acid
93% acid -l linuxemu.acid <pid>
94
95then you can issue the following commands:
96
97ustk() dump a (userspace) stacktrace for the current thread
98umem(Current()) dump the memory mappings
99ufds(Current()) dump the filedescriptor table
100utrace(Current()) dump the internal tracebuffer (enabled by -d option)
101
102use xasm()/xcasm() for disassembly for linux code.
103
104You can also enable full trace logging:
105
106% linux -r ./mroot -dd /bin/bash -i >[2]/tmp/linuxemu.log
107
108This slows linuxemu down. In case of race conditions, it often
109happens that the bug disapears when doing full trace logging!
110
111
112NPTL/thread-local storage
113
114If you get one of these errors:
115
116"cannot set up thread-local storage: cannot set up LDT for thread-local storage"
117
118this is glibc/libpthread complaining! the problem is the following:
119glibc on i386 decided at some point to use the extra segment registers
120GS and FS as an indirection pointer for thread local storage. the
121operating system kernel therfor must have a mechanism to let userspace
122change descriptor table entries and swap them in/out on context
123switch.
124
125to make it work here are several options:
126
1271) recompile and link the program with a pre NPTL version of glibc.
128
1292) on some distributions, a non-tls version of libc/libpthread is available.
130in my debian mroot, the NPTL version is in /lib/tls, the older version
131is in /lib. by renaming /lib/tls to /lib/_tls_disabled_ the loader will
132use the non-tls version.
133
1343) i made a kernel patch that adds support for per process descriptors to
135plan9:
136/n/sources/contrib/cinap_lenrek/segdescpatch
137http://9hal.ath.cx/usr/cinap_lenrek/segdescpatch.tgz
138it will add the files gdt and ldt to devarch (#P).