Geek magazine hacker daily blog

4 years, 7 months ago
FAQ: What is OS Inferno and why it is necessary?

So, we just set hosted OS Inferno in the house directory, and we can start setup of system.

Contents



For impatient


Article turned out not small since in it it is described not only "what" to do, but also why why and what else there are options, plus additional explanations on work with inferno for beginners. If you want just on - to customize system quicker, then just download recommended / lib/sh/profile, plus if at you Linux or by FreeBSD make to yourself scripts wrappers for start inferno.

Start and output from inferno


Hosted is inferno started by command emu or emu-g (without support of a graphics mode). It is by default started sh also outputs the command line prompt";":
$ emu
;

It is possible to leave sh command exit or having designated the end of input by a combination Ctrl-D (under Windows later Ctrl-D it is necessary to click in addition Enter). It is possible to leave from inferno command shutdown -h or (only under Linux/Win) having interrupted work on Ctrl-C.

Right now you will not notice any difference between all these methods — all of them stop work inferno. The matter is that inferno works so far there are active processes, and at present such process only one — sh. If to start additional processes, for example ndb/cs (the service-resolver necessary for work with a network), after an output from sh inferno will continue to work, but you will not be able to influence it any more. Under Linux/Win still it will turn out to switch off inferno on Ctrl-C, and under FreeBSD/MacOSX it will be necessary only to kill process of emu with means of the main OS. Of course, if you at first start the rstyx service (analog of ssh for remote access), then it will be possible to be connected to this emu from another and to execute far off shutdown -h.

One more difference is under Linux and FreeBSD — after end inferno in the console the message of "Killed" is displayed:
powerman@Ubuntu:~$ emu-g echo ok
ok
Убито
powerman@Ubuntu:~$
[powerman@freebsd ~]$ emu-g echo ok
ok
Killed: 9
[powerman@freebsd ~]$
Harm from it any, there is also a method of a solution of this problem. For this purpose it will be required to start emu and emu-g through scripts wrappers ~ / bin/emu and ~ / bin/emu-g:
powerman@Ubuntu:~$ cat ~/bin/emu-g
#!/bin/bash
$INFERNO_ROOT/Linux/386/bin/emu-g "$@" </dev/stdin &
wait 2>/dev/null
[powerman@freebsd ~]$ cat bin/emu-g
#!/usr/local/bin/bash
$INFERNO_ROOT/FreeBSD/386/bin/emu-g "$@" </dev/stdin &
wait 2>/dev/null
Under Linux it is enough to create these scripts and to make them feasible, and under FreeBSD it is necessary to set in addition bash and to modify value PATH in ~/.bash_profile so that directory /home/имя_пользователя/bin faced the directory with inferno.

Emu parameters


Some parameters are specified at start inferno. They can be specified or it is explicit in the command line, or to register in an environment variable EMU. Obligatory among these parameters only one: -r/путь/к/корню/инферно and it at us was already registered in a variable EMU in installation process of system. From useful option parameters it is worth mentioning the following:
  • -g<b>X</b>x<b>Y</b> sets permission of a graphical environment inferno, napr: -g1024x768
  • -с1 includes JIT (it makes sense in the prodakena and when testing performance)
  • -p <b>pool</b>=<b>maxsize</b> allows to control memory sizes available inferno, pool value can be main, heap or image, for example if it is necessary to process large volumes of data it is possible to increase heap to 128MB: -p heap=134217728
In more detail about the emu parameters it is possible to esteem in the emu (1) man-page.

The current values of some parameters can be learned inside inferno:
; echo $emuroot
/home/powerman/inferno
; echo $emuargs
emu -g1024x768 -c1
; cat /dev/memory
 277568  33554432    328032    3303    1490       1  33276852 main
  52544  33554432     78496    1650    1271       1  33501876 heap
      0  33554688         0       0       0       0  33554676 image
As you can see (a penultimate column) by default inferno uses no more than 32MB for each pool of memory.
; cat /dev/jit
0; echo 1 >/dev/jit
; cat /dev/jit
1; echo 0 >/dev/jit
; cat /dev/jit
0;
Though JIT can be included/disconnected dynamically, the changed JIT value will affect only modules (in there is inferno no difference between programs and libraries, all of them are just loaded modules) which will be loaded after this change. Therefore it is better to specify JIT value by parameter emu.

/ lib/sh/profile


When it is started inferno, by default started emuinit, which in turn starts sh -l. Parameter -l says sh that it is necessary to execute commands from /lib/sh/profile. This file is analog of boot scripts * NIX, and exactly there we will add command for setup and initialization inferno (now in this file there are no commands).

Keep in mind that if at start inferno to enter the emu parameter a name of the started application, then commands from /lib/sh/profile will not be executed (if only you obviously do not load them). Example:
$ emu-g 
; cat /lib/sh/profile
# emu sh initialisation here
; echo 'echo executing /lib/sh/profile' >> /lib/sh/profile
; shutdown -h

$ emu-g 
executing /lib/sh/profile
; shutdown -h

$ emu-g sh
; shutdown -h

$ emu-g sh -l
executing /lib/sh/profile
; shutdown -h

$ emu-g sh -c 'run /lib/sh/profile; echo ok; shutdown -h'
executing /lib/sh/profile
ok

Taymzona

The current zone is defined by the file /locale/timezone, available options can be seen having browsed names of other files in the directory /locale/. In traditional OS we just would copy the file /locale/наша_зона atop /locale/timezone. In inferno too it is possible to make so, but for inferno method of change of a taymzona modification of namespace by means of bind(1) will be more natural:
; date
Sun Jun 17 19:00:28 BST 2012
; bind /locale/EET /locale/timezone
; date
Sun Jun 17 21:00:39 EEST 2012
So we find the zone and we add in /lib/sh/profile:
bind /locale/выбранная_зона /locale/timezone


/ chan

One more useful command which should be added in /lib/sh/profile, it:
bind -b '#s' /chan
It connects the srv (3) driver to directory/chan. On accepted in inferno agreement, in this directory virtual files which reading/record will be transformed by the srv driver to messages, transferred via the channel in the process servicing these files are created. Use of such files (created through file2chan(2) from Limbo or file2chan(1) from sh) is the easiest way to implement the file server in inferno.

House directory

House directories of users inferno are in the directory /usr/. By default there only one subdirectory inferno/, which is in fact a template for creation of house directories of other users. Therefore if only your account in the main OS is called not inferno, :) then in inferno you have no house directory yet:
$ emu
; pwd
/
; cd
cd: /usr/powerman: '/usr/powerman' does not exist
;
It to create the easiest way — it is simple to copy /usr/inferno/ in /usr/имя_вашего_аккаунта/ (actually, it is also a method of adding of the new user account in inferno). But we will go in other, more flexible and effective way — we will connect as the house directory of the user in inferno real house directory of the user in the main OS (and files and subdirectories from / usr/inferno/can be copied in the real house directory in the main OS).
$ pwd
/home/powerman
$ emu
; mount {mntgen&} /usr
; bind -c '#U*/home/powerman' /usr/powerman
; cd
; pwd
/usr/powerman
The mntgen (4) file server is necessary not to create directories (mount points), they will automatically appear in the directory where mntgen is connected while someone addresses them. In our case (when Inferno's OS is set in our house directory) it would be possible just to create the directory instead of use of mntgen ~/inferno/usr/powerman/, but if it was inferno set root-ohm obshchesistemno in /usr/local/inferno/, we would not have enough access rights for creation of the directory /usr/local/inferno/usr/powerman/ also root rights for adding in inferno new user would be required. And mntgen allowed to solve this problem without root and creation of physical directories where it is possible to manage virtual.

For bigger flexibility we will add support of a variable of an environment of INFERNO_HOME — if it not empty, then in the house directory the way specified in this variable will be connected. So, we add in /lib/sh/profile:

… * NIX

( home unused ) := `{os sh -c 'echo $INFERNO_HOME $HOME' </dev/null}
home = '#U*'^$home

user := `{cat /dev/user}
mount {mntgen&} /usr
bind -c $home /usr/$user

cd

… Win

home := `{os cmd /C 'IF DEFINED INFERNO_HOME ( echo %INFERNO_HOME:\=/% ) ELSE ( echo %USERPROFILE:\=/% )'}
home = '#U'^$home

user := `{cat /dev/user}
mount {mntgen&} /usr
bind -c $home /usr/$user

cd

User preferences

The last that it makes sense to add in /lib/sh/profile, it support of additional settings of the user:
load std
and {ftest -d tmp}          {bind -c tmp /tmp}
and {ftest -e namespace}    {nsbuild}
and {ftest -e profile}      {run profile}
The module of a shell std needs to be loaded that it was possible to use the and command (analog if-and and &&). If in the house directory of the user there is a subdirectory tmp/ — it will be connected to system /tmp/ (in our case in it there is no special need, but at general-system installation inferno in /usr/local/inferno/ we would have no rights to record in /usr/local/inferno/tmp/ and this command would be necessary). In the presence in the house directory of the user of files namespace and profile they will be executed.

Download

For convenience you can download recommended /lib/sh/profile: * NIX, Win (do not forget to change in it a zone with GMT to the).

GUI (wm/wm)


At start of wm/wm it will execute /lib/wmsetup and, if is, ./lib/wmsetup in the house directory of the user. The plumber settings are in ./lib/plumbing in the house directory of the user (do not forget to copy them in the house directory from /usr/inferno/). Right now nothing to configure in these files there is no need, I mentioned them just that you knew where they are and looked that in them).

Keys for authentication


Keys will register and be used by default from the subdirectory ./keyring/ in the house directory. In old article I already told as in authentication is inferno arranged and to kopipastit all this here I do not see sense.

Network


In principle, in hosted inferno the network is not required to be configured. For example, we will download ya.ru (on IP):
$ emu
; webgrab -rv -o /dev/null 87.250.251.3
connecting to 87.250.251.3
writing request: GET / HTTP/1.0
Host: 87.250.251.3
User-agent: Inferno/webgrab
Cache-Control: no-cache
Pragma: no-cache

response: HTTP/1.1 200 Ok
created /dev/null, 7383 bytes

And here for support of conversion of names in IP, it is necessary to start service ndb/cs:
; ndb/cs
; webgrab -rv -o /dev/null ya.ru
connecting to ya.ru
writing request: GET / HTTP/1.0
Host: ya.ru
User-agent: Inferno/webgrab
Cache-Control: no-cache
Pragma: no-cache

response: HTTP/1.1 200 Ok
created /dev/null, 7689 bytes

The cs (8) service uses files /lib/ndb/common (analog /etc/services in * NIX), /lib/ndb/inferno (supplements /lib/ndb/common specific for inferno ports) and /lib/ndb/local.

File /lib/ndb/local is the basic — in it not only local settings are described, but also the others are connected the mentioned files are higher. In the section infernosite= it is possible to configure compliances between short names of servers and their real names or IP addresses. The short names SIGNER and registry for the indication of servers with CA (certificate authority) and registry (4) services are most often used. For connection on a short name before it it is necessary to add the character"$". For example, let's add a name for Yandex:
$ emu
; cat /lib/ndb/local
...
infernosite=
...
        Yandex=www.yandex.ru
; ndb/cs
; webgrab -rv -o /dev/null '$Yandex'
connecting to $Yandex
writing request: GET / HTTP/1.0
Host: $Yandex
User-agent: Inferno/webgrab
Cache-Control: no-cache
Pragma: no-cache

response: HTTP/1.1 200 Ok
created /dev/null, 7378 bytes

File /lib/ndb/services contains the description specific to inferno ports in a format * NIX /etc/services. It makes sense to add it to /etc/services in the main OS that it was more convenient to be connected from the main OS to infernovsky services:
cat ~/inferno/lib/ndb/services | sudo bash -c 'cat >>/etc/services'

OS Inferno updating


For updating of system just it is necessary to repeat the same commands which were used at installation:

… * NIX

cd ~/inferno
hg pull -uv
mk nuke
mk install          # пропустите эту команду на серверах без X-ов и GUI
mk CONF=emu-g install

… Win

We start "Windows SDK 7.1 Command Prompt" (or "Visual Studio Command Prompt (2010)" — depending on what you set).
cd \inferno
hg pull -uv
mk nuke
mk install

This article is a translation of the original post at geektimes.ru/post/145986/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog geektimes.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.