The FreeBSD-linuxulator explained (for devel­op­ers): basics

The last post about the Lin­ux­u­la­tor where I explained the Lin­ux­u­la­tor from an user point of view got some good amount of atten­tion. Trig­gered by a recent expla­na­tion of the Lin­ux­u­la­tor errno stuff to a fel­low FreeB­SD devel­op­er I decid­ed so see if more devel­op­ers are inter­est­ed in some more info too…

The syscall vector

In sys/linux/linux_sysvec.c is all the basic set­up to han­dle Lin­ux “sys­tem stuff” in FreeB­SD. The “sys­tem stuff” is about trans­lat­ing FreeB­SD errnos to Lin­ux errnos, about trans­lat­ing FreeB­SD sig­nals to Lin­ux sig­nales, about han­dling Lin­ux traps, and about set­ting up the FreeB­SD sys­tem vec­tor (the ker­nel struc­ture which con­tains all the data to iden­ti­fy when a Lin­ux pro­gram is called and to be able to lookup the right ker­nel func­tions for e.g. syscalls and ioctls).

There is not only one syscall vec­tor, there is one for a.out (struct sysentvec linux_sysvec) and one for ELF (struct sysentvec elf_linux_sysvec) bina­ries (at least on i386, for oth­er archi­tec­tures it may not make sense to have the a.out stuff, as they maybe nev­er seen any a.out Lin­ux binary).

The ELF AUX args

When an ELF image is exe­cut­ed, the Lin­ux­u­la­tor adds some run­time infor­ma­tion (like page­size, uid, guid, …) so that the user­land can query this infor­ma­tion which is not sta­t­ic at build-time eas­i­ly. This is han­dled in the elf_linux_fixup func­tion(). If you see some error mes­sages about miss­ing ELF notes from e.g. glibc, this is the place to add this infor­ma­tion to. It would not be bad from time to time to have a look what Lin­ux is pro­vid­ing and miss­ing pieces there. FreeB­SD does not has an auto­mat­ed way of doing this, and I am not aware of some­one who reg­u­lar­ly checks this. There is a lit­tle bit more info about ELF notes avail­able in a mes­sage to one of the FreeB­SD mail­ing lists, it also has an exam­ple how to read out this data.

Traps

Lin­ux and FreeB­SD do not share the same point of view how a trap shall be han­dled (SIGBUS or SIGSEGV), the cor­re­spond­ing deci­sion mak­ing is han­dled in translate_traps() and a trans­la­tion table is avail­able as _bsd_to_linux_trapcode.

Sig­nals

The val­ues for the sig­nal names are not the same in FreeB­SD and Lin­ux. The trans­la­tion tables are called linux_to_bsd_signal and bsd_to_linux_signal. The trans­la­tion is a fea­ture of the syscall vec­tor (= automatic).

Errnos

The val­ues for the errno names are not the same in FreeB­SD and Lin­ux. The trans­la­tion table is called bsd_to_linux_errno. Return­ing an errno in one of the Lin­ux syscalls will trig­ger an auto­mat­ic trans­la­tion from the FreeB­SD errno val­ue to the Lin­ux errno val­ue. This means that FreeB­SD errnos have to be returned (e.g. FreeB­SD ENOSYS=78) and the Lin­ux pro­gram will receive the Lin­ux val­ue (e.g. Lin­ux ENOSYS=38, and as the Lin­ux ker­nel returns neg­a­tive errnos, the lin­ux pro­gram will get ‑38).

If you see some­where an “-ESOMETHING” in the Lin­ux­u­la­tor code, this is either a bug, or some clever/tricky/dangerous use of the sign-bit to encode some info (e.g. in the futex code there is a func­tion which returns ‑ENOSYS, but the sign-bit is used as an error indi­ca­tor and the call­ing code is respon­si­ble to trans­late neg­a­tive errnos into pos­i­tive ones).

Syscalls

The Lin­ux syscalls are defined sim­i­lar to the FreeB­SD ones. There is a map­ping table (sys/linux/syscalls.master) between syscall num­bers and the cor­re­spond­ing func­tions. This table is used to gen­er­ate code (“make sysent” in sys//linux/) which does what is necessary.

Jumstart/JET for FreeB­SD (brain­storm­ing)

There are some HOW­TOs out there in the net which describe some auto­mat­ic net­work based install via PXE-booting a machine from a serv­er which has a spe­cif­ic FreeB­SD release in the PXE-booting area and a non-interactive con­fig for sysin­stall to install this FreeB­SD ver­sion on the machine which PXE-boots this.

The set­up of this is com­plete­ly man­u­al and only allows to net­boot one FreeB­SD ver­sion. The server-side set­up for the clients is also com­plete­ly man­u­al (and only allows to install one client at a time, it seems). This is not very user-friendly, and far away from the pow­er of Jumpstart/JET for Solaris where you cre­ate a tem­plate (maybe from anoth­er tem­plate with auto­mat­ic val­ue (IP, name, MAC) replace­ment) and can spec­i­fy dif­fer­ent OS releas­es for dif­fer­ent clients and then just run a com­mand to gen­er­ate a good con­fig for this.

I thought a lit­tle bit how it could be done and decid­ed to write down all the stuff (so far 160 lines, 830 words) to not for­get some details. All in all I think this could be done (at least a sen­si­ble sub­set) in a week or two (full­time) if you have the hard­ware, moti­va­tion, and time. As always, the prob­lems are with­in the details, so I may be off with my esti­ma­tion a lit­tle bit (also depends upon the knowledge-level (shell, tftp, dhcpd, install-software) of the per­son doing this).

Unfor­tu­nate­ly I do not know if I have the hard­ware at home to do some­thing like this. I have some unused hard­disks which could be used in a machine which is used tem­po­rary as a test-install-client (nor­mal­ly I use this machines as my Desk­top… if I do not use my lit­tle Net­book instead, as I do not do much at home cur­rent­ly), but I’ve nev­er checked if this machine is PXE-booting-capable (VIA KT133 chipset with a 3Com 3c905C-TX Fast Ether­link XL). I also do not have the time to do this (with the cur­rent rate of free time I would expect to need about a year), except maybe some­one would call my boss and nego­ti­ate something.

I can not remem­ber any request to have some­thing like this on the freebsd-current, freebsd-arch or freebsd-hackers list since I read them (and that is since about at least 3.0‑RELEASE). Is this because near­ly nobody is inter­est­ed in some­thing like this, or are the cur­rent pos­si­bil­i­ties enough for your needs? Do you work at a place where this would be wel­come (= direct­ly used when it would be done)? If you use a sim­ple solu­tion to make a net-install, what is your expe­ri­ence with this (pros/cons)?

Solaris 10 update 9: the not so nice things about it

I updat­ed some work­sta­tions of the client to Solaris 10 update 9. Upon installing my xorg.conf (dual-screen set­up) I had to notice that it does not work any­more. The prob­lem is, that the NVidia dri­ver does not con­tain sup­port for the graph­ic card we use.

Nor­mal­ly this is not a big deal, this can hap­pen… but in this case this is about SUN Ultra 20 work­sta­tions with SUN pro­vid­ed NVidia Quat­tro FX (NV37GL) cards. Ok, they are not the most recent ones, they where bought 4 – 5 years ago, but still, they just work as need­ed here and the cur­rent Solaris release has no out-of-the-box sup­port for them. I would expect this to work already in a fresh install (yes, I was not able to get the nv dri­ver to work with two screens on this graph­ic card, it seems the nv dri­ver has not sup­port for this).

Solu­tion for me: down­load the old dri­ver from NVidia and inte­grate it into Jump­start (but still, some hours are lost because of first try­ing to get a work­ing dual-screen set­up with the nv dri­ver before tak­ing an old NVidia dri­ver and using it like before in xorg.conf).

Anoth­er glitch a co-worker dis­cov­ered is that StarOf­fice is not includ­ed any­more. That is again some­thing which will cause some loss of time. I will have to have a look how to han­dle it. Prob­a­bly it is best to install it on the serv­er and mount it via NFS on the work­sta­tions. I will see soon if this is can be done (instal­la­tion of OO into a spe­cif­ic place which can be shared) or not.

Rant about Berke­ley­DB docs

I was build­ing Berke­ley­DB (4.7, yes I know, there are more recent ver­sions avail­able) on a Solaris machine. First try was to unpack, cd into the direc­to­ry, run con­fig­ure. It failed, there is no con­fig­ure script. Bah. 🙁

Sec­ond try: search­ing for docs… found some… in HTML (the README refers to it and tells noth­ing else). This is a remote machine, I do not want to use a HTML brows­er remote­ly (I may not even have one installed there…). Bah. 🙁

Ok, dist/configure exists, no spe­cial options need­ed for my case, it seems.

There is even a Solaris spe­cif­ic HTML file, but from a quick glance at it with ‘less’, it looks like a FAQ.

Usabil­i­ty from a com­mand line: zero.
Pos­si­bil­i­ty to com­pile from a GUI (unix): I doubt it.

What is wrong with plain text files? If I down­load the source and want to com­pile it (and for Solaris this is the nor­mal way of work­ing), why the hell do I need some GUI instead of get­ting a plain text file with the required descrip­tion (which is not graph­i­cal­ly enhanced in the HTML ver­sion either)? You can even gen­er­ate a plain text ver­sion of the docs auto­mat­i­cal­ly dur­ing the src-packaging process.

Hey Ora­cle, there is room for improve­ment here!

Fight­ing with the Ora­cle Direc­to­ry Serv­er 7 (DSEE7) on Solaris 10 update 9

After mov­ing our sec­ondary man­age­ment site (our team is split up into 2 dif­fer­ent loca­tions) to a new build­ing, we decid­ed to clean-up some things. One of those things involves mov­ing the LDAP to a dif­fer­ent machine (more or less a new serv­er for the new site, it is inde­pen­dent regard­ing LDAP/homes/… from the pri­ma­ry site). While I am at it, I take the oppor­tu­ni­ty to move from DSEE5 to DSEE7 (my pre­vi­ous post about the DSEE6 migra­tion was at the pri­ma­ry site). This time I took the pack­age dis­tri­b­u­tion instead of the zip dis­tri­b­u­tion (the main rea­son is that I can get patch-listings with an auto­mat­ic tool, and the sec­ondary man­age­ment site has no disaster-recovery require­ments for the appli­ca­tions… we just will set­up a new sec­ondary site some­where else if necessary).

Here my expe­ri­ences with the instal­la­tion instruc­tions of DSEE7.

  • The install instruc­tions refer to the web inter­face for the DSEE7 man­age­ment, but I have not seen some­thing which tells you first have to set­up an appli­ca­tion serv­er (this was bet­ter in the DSEE6 instructions).
  • When using the Glass­fish appli­ca­tion serv­er which comes with Solaris 10 for the web inter­face, you will get an excep­tion after deploy­ing the dscc7.war, as it is using an out­dat­ed JVM. After some fight­ing and Googling, I found that I have to change the AS_JAVA val­ue in /usr/appserver/config/asenv.conf to a more recent JVM as it is point­ing to the very out­dat­ed j2se 1.4.x. I point­ed it to /usr/java (which is a sym­link to the most recent ver­sion installed as a pack­age). Instead of the orig­i­nal excep­tion I got anoth­er one now (after a redi­rec­tion in the web-browser), some­thing that it can not find the AntMain class (Glass­fish uses ANT from /usr/sfw, this is the one which comes with Solaris 10 update 9). I tried with Java 5 instead of Java 6, but I get the same error. In the net there are some dis­cus­sions about such errors (it is even a FAQ at the ANT site), but this Glassfish/DSEE7 thing is a black box for me, so what am I sup­posed to do here (I do not want to put the sys­tem into an unof­fi­cial state by installing my own ANT for Glassfish/DSEE7)?
    It was not men­tioned in the Appen­dix of the DSEE7 install instruc­tions which explains how to install the .war in Glass­fish that you have to change to a more recent JVM, and I still fight with the AntMain prob­lem (hey Ora­cle, there is room for improve­ment in the prod­uct com­pat­i­bil­i­ty test­ing and doc­u­men­ta­tion ver­i­fi­ca­tion process).

I will update this post­ing when I make some advance­ments. For now I let the web inter­face in the bad state as it is and con­cen­trate on fin­ish­ing the LDAP move to the new sys­tem (installing an DSEE on a back­up sys­tem, con­fig­ur­ing repli­ca­tion, switch­ing the clients to them). The web inter­face is inde­pen­dent enough to han­dle it lat­er (hints wel­come, that is the main pur­pose why I write this pos­ing in the mid­dle of the work).