Ki jan yo kòmanse sèvi ak User Mode nan Linux

Entwodiksyon nan tradiktè a: Nan seri a nan antre masiv nan lavi nou nan divès kalite resipyan, li ka byen enteresan ak itil yo chèche konnen ak ki teknoloji li tout te kòmanse yon fwa. Kèk nan yo ka itil nan jounen jodi a, men se pa tout moun sonje metòd sa yo (oswa konnen si yo pa te kenbe yo pandan devlopman rapid yo). Youn nan teknoloji sa yo se User Mode Linux. Otè orijinal la te fè anpil fouye, chèche konnen kilès nan ansyen devlopman yo toujou ap travay ak ki pa fè sa, epi mete ansanm yon bagay tankou yon enstriksyon etap pa etap sou kòman ou kapab jwenn tèt ou yon homebrew UML nan 2k19. Epi wi, nou envite otè pòs orijinal la nan Habr Cadey, Se konsa, si ou gen nenpòt kesyon - mande an angle nan kòmantè yo.

Ki jan yo kòmanse sèvi ak User Mode nan Linux

Mòd itilizatè nan Linux se, an reyalite, yon pò nan nwayo a Linux nan tèt li. Mòd sa a pèmèt ou kouri yon nwayo Linux konplè kòm yon pwosesis itilizatè epi li se souvan itilize pa devlopè yo teste chofè yo. Men, mòd sa a itil tou kòm yon zouti izolasyon jeneral, prensip la ki sanble ak operasyon an nan machin vityèl. Mòd sa a bay plis izolasyon pase Docker, men mwens pase yon machin vityèl konplè tankou KVM oswa Virtual Box.

An jeneral, User Mode ka sanble yon zouti etranj ak difisil pou itilize, men li toujou gen itilizasyon li yo. Apre yo tout, sa a se yon nwayo Linux konplè ki kouri soti nan yon itilizatè san privilèj. Karakteristik sa a pèmèt kòd ki pa gen konfyans nan kouri san okenn menas pou machin lame a. Epi depi sa a se yon nwayo plen véritable, pwosesis li yo izole nan machin lame a, se sa ki pwosesis k ap kouri andedan Mode Itilizatè pa pral vizib pou lame a. Sa a se pa tankou veso Docker abityèl la, nan ka sa a machin lame a toujou wè pwosesis yo andedan depo a. Gade moso pstree sa a ki soti nan youn nan sèvè mwen yo:

containerd─┬─containerd-shim─┬─tini─┬─dnsd───19*[{dnsd}]
           │                 │      └─s6-svscan───s6-supervise
           │                 └─10*[{containerd-shim}]
           ├─containerd-shim─┬─tini─┬─aerial───21*[{aerial}]
           │                 │      └─s6-svscan───s6-supervise
           │                 └─10*[{containerd-shim}]
           ├─containerd-shim─┬─tini─┬─s6-svscan───s6-supervise
           │                 │      └─surl
           │                 └─9*[{containerd-shim}]
           ├─containerd-shim─┬─tini─┬─h───13*[{h}]
           │                 │      └─s6-svscan───s6-supervise
           │                 └─10*[{containerd-shim}]
           ├─containerd-shim─┬─goproxy───14*[{goproxy}]
           │                 └─9*[{containerd-shim}]
           └─32*[{containerd}]

Epi konpare sa a ak pstree nan nwayo a Linux nan Mode Itilizatè:

linux─┬─5*[linux]
      └─slirp

Lè w ap travay ak resipyan Docker, mwen ka wè nan lame a non pwosesis ki ap kouri nan envite a. Sa a pa posib ak mòd itilizatè Linux. Sa sa vle di? Sa vle di ke zouti siveyans kouri atravè subsistèm odit Linux la pa wè pwosesis k ap kouri nan sistèm envite. Men, nan kèk sitiyasyon, karakteristik sa a ka vin yon nepe de bò.

An jeneral, tout pòs ki anba a se yon koleksyon rechèch ak tantativ ki graj pou reyalize rezilta a vle. Pou fè sa, mwen te oblije sèvi ak plizyè zouti ansyen, li sous nwayo yo, fè debogaj entansif nan kòd ki te ekri nan epòk mwen te toujou nan lekòl primè, epi tou brikole ak Heroku bati lè l sèvi avèk yon binè espesyal pou jwenn zouti mwen te bezwen yo. . Tout travay sa a te mennen mesye yo sou IRC mwen yo rele m 'majik. Mwen espere pòs sa a sèvi kòm dokimantasyon serye pou yon moun eseye menm bagay la ak nouvo nwayo ak vèsyon OS yo.

ajisteman

Konfigirasyon mòd itilizatè Linux fè nan plizyè etap:

  • enstale depandans sou lame a;
  • telechaje nwayo Linux la;
  • konfigirasyon konstriksyon nwayo;
  • asanble nwayo;
  • enstalasyon binè;
  • konfigirasyon sistèm fichye envite;
  • seleksyon paramèt lansman nwayo;
  • mete kanpe yon rezo envite;
  • kòmanse nwayo envite.

Mwen sipoze ke si ou deside fè li tèt ou, ou pral gen plis chans fè tout sa ki dekri nan kèk Ubuntu oswa Debian ki tankou sistèm. Mwen te eseye aplike tout sa ki anwo yo nan distribisyon pi renmen mwen an - Alpine, men pa gen anyen ki soti nan li, aparamman akòz lefèt ke nwayo Linux la gen yon glibc-isms difisil-obligatwa pou chofè nan Mode Itilizatè. Mwen planifye pou rapòte sa a en apre mwen finalman konprann pwoblèm nan.

Enstale depandans sou lame a

Ubuntu mande pou omwen pakè sa yo pou konstwi nwayo Linux la (asepte yon enstalasyon pwòp):

- 'build-essential'
- 'flex'
- 'bison'
- 'xz-utils'
- 'wget'
- 'ca-certificates'
- 'bc'
- 'linux-headers'

Ou ka enstale yo ak lòd sa a (kòm rasin oswa ak sudo):

apt-get -y install build-essential flex bison xz-utils wget ca-certificates bc 
                   linux-headers-$(uname -r)

Remake byen ke kouri pwogram konfigirasyon meni Linux Kernel la pral mande pou enstalasyon an libncurses-dev. Tanpri asire w ke li enstale lè l sèvi avèk lòd sa a (kòm rasin oswa lè l sèvi avèk sudo):

apt-get -y install libncurses-dev

Telechaje nwayo a

Deside ki kote yo telechaje ak Lè sa a, bati nwayo a. Pou operasyon sa a, w ap bezwen asiyen apeprè 1,3 GB nan espas ki gen kapasite difisil, kidonk asire w ke ou genyen li.

Apre ale nan kernel.org epi jwenn URL la pou telechaje dènye nwayo ki estab la. Nan moman ekri sa a se: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz

Telechaje fichye sa a lè l sèvi avèk 'wget':

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz

Epi ekstrè li ak 'tar':

tar xJf linux-5.1.16.tar.xz

Koulye a, nou antre nan anyè ki te kreye lè debake tarball la:

cd linux-5.1.16

Konfigirasyon Kernel bati

Sistèm bati nwayo a se yon seri Makefiles с anpil zouti koutim ak scripts pou otomatize pwosesis la. Premyèman, louvri pwogram konfigirasyon entèaktif la:

make ARCH=um menuconfig

Li pral pasyèlman bati epi montre yon bwat dyalòg pou ou. Kilè '[Select]', ou pral kapab konfigirasyon lè l sèvi avèk espas oswa antre kle yo. Navige fenèt la, kòm dabitid, ak flèch yo klavye "moute" ak "desann", epi chwazi eleman - "gòch" oswa "dwa".

Pointeur a gade —> vle di ke ou se nan yon sous-menu, aksè nan kle Antre nan. Wout la soti nan li se evidamman nan '[Exit]'.

Mete opsyon sa yo nan '[Select]' epi asire w ke yo gen yon '[*]' bò kote yo:

UML-specific Options:
  - Host filesystem
Networking support (enable this to get the submenu to show up):
  - Networking options:
    - TCP/IP Networking
UML Network devices:
  - Virtual network device
  - SLiRP transport

Sa a se li, ou ka sòti nan fenèt sa a lè w chwazi youn apre lòt.[Exit]'. Jis asire w ke nan fen a ou ap mande pou sove konfigirasyon an epi chwazi '[Yes]'.

Mwen rekòmande ke ou jwe otou ak opsyon yo bati nwayo apre ou fin li pòs sa a. Atravè eksperyans sa yo, ou ka aprann anpil bagay an tèm de konpreyansyon travay mekanik kernel ba nivo ak enpak divès kalite drapo sou asanble li yo.

Bati nwayo a

Kernel Linux la se yon gwo pwogram ki fè anpil bagay. Menm ak yon konfigirasyon minim sou ansyen pyès ki nan konpitè, li ka pran yon ti tan pou konstwi. Se konsa, bati nwayo a ak lòd sa a:

make ARCH=um -j$(nproc)

Pou kisa? Kòmandman sa a pral di mason nou an pou sèvi ak tout nwayo CPU ki disponib ak fil nan pwosesis konstriksyon an. Ekip $(nproc) nan fen Build ranplase pwodiksyon an nan lòd la nproc, ki fè pati coreutils nan yon estanda Ubuntu bati.

Apre kèk tan, nwayo nou an pral konpile nan yon dosye ègzèkutabl ./linux.

Enstale binè a

Depi User Mode nan Linux kreye yon binè regilye, ou ka enstale li tankou nenpòt lòt sèvis piblik. Men ki jan mwen te fè li:

mkdir -p ~/bin
cp linux ~/bin/linux

Li se tou vo asire w ke ~/bin se nan ou $PATH:

export PATH=$PATH:$HOME/bin

Mete kanpe sistèm dosye envite

Kreye yon anyè pou sistèm fichye envite:

mkdir -p $HOME/prefix/uml-demo
cd $HOME/prefix

Louvri alpinelinux.org epi antre telechaje seksyon jwenn lyen download aktyèl la MINI ROOT FILESYSTEM. Nan moman ekri sa a se te:

http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/x86_64/alpine-minirootfs-3.10.0-x86_64.tar.gz

Telechaje tarball sa a lè l sèvi avèk wget:

wget -O alpine-rootfs.tgz http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/x86_64/alpine-minirootfs-3.10.0-x86_64.tar.gz

Koulye a, antre nan anyè a nan sistèm nan dosye envite epi ekstrè achiv la:

cd uml-demo
tar xf ../alpine-rootfs.tgz

Aksyon ki dekri yo pral kreye yon ti modèl sistèm dosye. Akòz fason sistèm lan ap travay, enstale pakè atravè manadjè apk Alpine a pral trè difisil. Men, FS sa a pral ase pou evalye lide jeneral la.

Nou bezwen tou yon zouti tini pou redwi konsomasyon memwa pwosesis zonbi nwayo envite nou an.

wget -O tini https://github.com/krallin/tini/releases/download/v0.18.0/tini-static
chmod +x tini

Kreye yon liy kòmand Kernel

Kernel Linux la, tankou pifò lòt pwogram, gen agiman liy kòmand ki ka jwenn aksè lè w espesifye kle a. --help.

Li menm - ede

linux --help
User Mode Linux v5.1.16
        available at http://user-mode-linux.sourceforge.net/

--showconfig
    Prints the config file that this UML binary was generated from.

iomem=<name>,<file>
    Configure <file> as an IO memory region named <name>.

mem=<Amount of desired ram>
    This controls how much "physical" memory the kernel allocates
    for the system. The size is specified as a number followed by
    one of 'k', 'K', 'm', 'M', which have the obvious meanings.
    This is not related to the amount of memory in the host.  It can
    be more, and the excess, if it's ever used, will just be swapped out.
        Example: mem=64M

--help
    Prints this message.

debug
    this flag is not needed to run gdb on UML in skas mode

root=<file containing the root fs>
    This is actually used by the generic kernel in exactly the same
    way as in any other kernel. If you configure a number of block
    devices and want to boot off something other than ubd0, you
    would use something like:
        root=/dev/ubd5

--version
    Prints the version number of the kernel.

umid=<name>
    This is used to assign a unique identity to this UML machine and
    is used for naming the pid file and management console socket.

con[0-9]*=<channel description>
    Attach a console or serial line to a host channel.  See
    http://user-mode-linux.sourceforge.net/old/input.html for a complete
    description of this switch.

eth[0-9]+=<transport>,<options>
    Configure a network device.
    
aio=2.4
    This is used to force UML to use 2.4-style AIO even when 2.6 AIO is
    available.  2.4 AIO is a single thread that handles one request at a
    time, synchronously.  2.6 AIO is a thread which uses the 2.6 AIO
    interface to handle an arbitrary number of pending requests.  2.6 AIO
    is not available in tt mode, on 2.4 hosts, or when UML is built with
    /usr/include/linux/aio_abi.h not available.  Many distributions don't
    include aio_abi.h, so you will need to copy it from a kernel tree to
    your /usr/include/linux in order to build an AIO-capable UML

nosysemu
    Turns off syscall emulation patch for ptrace (SYSEMU).
    SYSEMU is a performance-patch introduced by Laurent Vivier. It changes
    behaviour of ptrace() and helps reduce host context switch rates.
    To make it work, you need a kernel patch for your host, too.
    See http://perso.wanadoo.fr/laurent.vivier/UML/ for further
    information.

uml_dir=<directory>
    The location to place the pid and umid files.

quiet
    Turns off information messages during boot.

hostfs=<root dir>,<flags>,...
    This is used to set hostfs parameters.  The root directory argument
    is used to confine all hostfs mounts to within the specified directory
    tree on the host.  If this isn't specified, then a user inside UML can
    mount anything on the host that's accessible to the user that's running
    it.
    The only flag currently supported is 'append', which specifies that all
    files opened by hostfs will be opened in append mode.

Panèl sa a mete aksan sou paramèt prensipal yo nan lansman an. Ann kouri nwayo a ak seri opsyon ki nesesè yo:

linux 
  root=/dev/root 
  rootfstype=hostfs 
  rootflags=$HOME/prefix/uml-demo 
  rw 
  mem=64M 
  init=/bin/sh

Liy ki anwo yo di nwayo nou an sa ki annapre yo:

  • Sipoze sistèm fichye rasin lan se yon aparèy pseudo /dev/root.
  • Chwazi hostfs kòm yon chofè sistèm fichye rasin.
  • Monte sistèm fichye envite nou te kreye sou aparèy rasin lan.
  • Epi wi, nan mòd lekti-ekri.
  • Sèvi ak sèlman 64 MB nan RAM (ou ka itilize anpil mwens depann sou sa ou planifye fè, men 64 MB sanble tankou kantite lajan an pi bon).
  • Kernel la kòmanse otomatikman /bin/sh kòm init-pwosesis.

Kouri lòd sa a epi ou ta dwe jwenn yon bagay tankou sa ki annapre yo:

Yon lòt fèy

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 32137216 bytes to physical memory to account for exec-shield gap
Linux version 5.1.16 (cadey@kahless) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #30 Sun Jul 7 18:57:19 UTC 2019
Built 1 zonelists, mobility grouping on.  Total pages: 23898
Kernel command line: root=/dev/root rootflags=/home/cadey/dl/uml/alpine rootfstype=hostfs rw mem=64M init=/bin/sh
Dentry cache hash table entries: 16384 (order: 5, 131072 bytes)
Inode-cache hash table entries: 8192 (order: 4, 65536 bytes)
Memory: 59584K/96920K available (2692K kernel code, 708K rwdata, 588K rodata, 104K init, 244K bss, 37336K reserved, 0K cma-reserved)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS: 15
clocksource: timer: mask: 0xffffffffffffffff max_cycles: 0x1cd42e205, max_idle_ns: 881590404426 ns
Calibrating delay loop... 7479.29 BogoMIPS (lpj=37396480)
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
random: get_random_bytes called from setup_net+0x48/0x1e0 with crng_init=0
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)
NET: Registered protocol family 16
clocksource: Switched to clocksource timer
NET: Registered protocol family 2
tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
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/cadey/.uml/tEwIjm/mconsole
Checking host MADV_REMOVE support...OK
workingset: timestamp_bits=62 max_order=14 bucket_order=0
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered (default)
io scheduler bfq registered
loop: module loaded
NET: Registered protocol family 17
Initialized stdio console driver
Using a channel type which is configured out of UML
setup_one_line failed for device 1 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 2 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 3 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 4 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 5 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 6 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 7 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 8 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 9 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 10 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 11 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 12 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 13 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 14 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 15 : Configuration failed
Console initialized on /dev/tty0
console [tty0] enabled
console [mc-1] enabled
Failed to initialize ubd device 0 :Couldn't determine size of device's file
VFS: Mounted root (hostfs filesystem) on device 0:11.
devtmpfs: mounted
This architecture does not have kernel memory protection.
Run /bin/sh as init process
/bin/sh: can't access tty; job control turned off
random: fast init done
/ # 

Manipilasyon ki anwo yo pral ban nou sistèm envite nan minimòm, san bagay tankou /proc oswa non host yo asiyen. Pou egzanp, eseye kòmandman sa yo:

- uname -av
- cat /proc/self/pid
- hostname

Pou dekonekte sistèm envite a, antre exit oswa peze kontwòl-d. Sa a pral touye koki a ki te swiv pa yon panik nwayo:

/ # exit
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000
fish: “./linux root=/dev/root rootflag…” terminated by signal SIGABRT (Abort)

Nou te resevwa panik nwayo sa a paske nwayo Linux la panse pwosesis inisyalizasyon an toujou ap kouri. San li, sistèm nan pa ka fonksyone ankò ak aksidan. Men, depi sa a se yon pwosesis itilizatè-mòd, pwodiksyon an ki kapab lakòz voye tèt li nan SIGABRT, ki mennen nan sòti an.

Konfigirasyon rezo envite

Epi sa a se kote bagay yo kòmanse ale mal. Rezo nan mòd itilizatè Linux se kote tout konsèp nan "mòd itilizatè" limite kòmanse tonbe apa. Apre yo tout, anjeneral nan nivo sistèm lan, rezo a limite privilejye mòd ekzekisyon pou tout moun nan nou rezon konprann.

Remak pa .: ou ka li plis sou diferan opsyon pou travay ak yon rezo nan UML isit la.

Sou entènèt jwèt Vwayaj nan Slirp

Sepandan, gen yon zouti ansyen ak prèske pa sipòte yo rele Slirp, ak ki User Mode Linux ka kominike avèk rezo a. Li opere apeprè tankou yon pile TCP/IP nan nivo itilizatè epi li pa bezwen okenn otorizasyon sistèm pou kouri. Zouti sa a te lage an 1995, ak dènye aktyalizasyon a gen dat 2006. Slirp gen anpil laj. Pandan tan an san sipò ak mizajou, konpilateur yo te rive twò lwen ke kounye a zouti sa a ka sèlman dekri kòm "kod pouri".

Se konsa, ann telechaje Slirp nan depo Ubuntu yo epi eseye kouri li:

sudo apt-get install slirp
/usr/bin/slirp
Slirp v1.0.17 (BETA)

Copyright (c) 1995,1996 Danny Gasparovski and others.
All rights reserved.
This program is copyrighted, free software.
Please read the file COPYRIGHT that came with the Slirp
package for the terms and conditions of the copyright.

IP address of Slirp host: 127.0.0.1
IP address of your DNS(s): 1.1.1.1, 10.77.0.7
Your address is 10.0.2.15
(or anything else you want)

Type five zeroes (0) to exit.

[autodetect SLIP/CSLIP, MTU 1500, MRU 1500, 115200 baud]

SLiRP Ready ...
fish: “/usr/bin/slirp” terminated by signal SIGSEGV (Address boundary error)

Oh bondye. Ann enstale debogaj Slirp a epi wè si nou ka konnen sa k ap pase isit la:

sudo apt-get install gdb slirp-dbgsym
gdb /usr/bin/slirp
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/slirp...Reading symbols from /usr/lib/debug/.build-id/c6/2e75b69581a1ad85f72ac32c0d7af913d4861f.debug...done.
done.
(gdb) run
Starting program: /usr/bin/slirp
Slirp v1.0.17 (BETA)

Copyright (c) 1995,1996 Danny Gasparovski and others.
All rights reserved.
This program is copyrighted, free software.
Please read the file COPYRIGHT that came with the Slirp
package for the terms and conditions of the copyright.

IP address of Slirp host: 127.0.0.1
IP address of your DNS(s): 1.1.1.1, 10.77.0.7
Your address is 10.0.2.15
(or anything else you want)

Type five zeroes (0) to exit.

[autodetect SLIP/CSLIP, MTU 1500, MRU 1500, 115200 baud]

SLiRP Ready ...

Program received signal SIGSEGV, Segmentation fault.
                                                    ip_slowtimo () at ip_input.c:457
457     ip_input.c: No such file or directory.

Erè a ap bat sou nou liy sa a. Ann gade nan stacktrace la, petèt yon bagay pral ede nou la:

(gdb) bt full
#0  ip_slowtimo () at ip_input.c:457
        fp = 0x55784a40
#1  0x000055555556a57c in main_loop () at ./main.c:980
        so = <optimized out>
        so_next = <optimized out>
        timeout = {tv_sec = 0, tv_usec = 0}
        ret = 0
        nfds = 0
        ttyp = <optimized out>
        ttyp2 = <optimized out>
        best_time = <optimized out>
        tmp_time = <optimized out>
#2  0x000055555555b116 in main (argc=1, argv=0x7fffffffdc58) at ./main.c:95
No locals.

Isit la nou wè ke aksidan an rive pandan bouk prensipal la kòmanse lè slirp eseye tcheke pou timeouts. Nan pwen sa a, mwen te oblije abandone eseye debogaj. Men, kite a wè si Slirp bati soti nan kalite travay. Mwen re-telechaje achiv la dirèkteman nan sit la sourceforge, paske trennen yon bagay soti nan la nan liy lòd la se yon doulè:

cd ~/dl
wget https://xena.greedo.xeserv.us/files/slirp-1.0.16.tar.gz
tar xf slirp-1.0.16.tar.gz
cd slirp-1.0.16/src
./configure --prefix=$HOME/prefix/slirp
make

Isit la nou wè alèt sou fonksyon entegre endefini, se sa ki, sou enkapasite a konekte dosye a binè ki kapab lakòz. Li sanble ke ant 2006 ak pwen sa a, gcc sispann pwodwi senbòl yo itilize nan fonksyon entegre nan dosye entèmedyè konpile. Ann eseye ranplase mo kle a inline sou yon kòmantè vid epi gade rezilta a:

vi slirp.h
:6
a
<enter>
#define inline /**/
<escape>
:wq
make

Non. Sa pa mache tou. Toujou pa ka jwenn senbòl pou fonksyon sa yo.

Nan pwen sa a, mwen te abandone e mwen te kòmanse gade sou Github Heroku bati pakè. Teyori mwen an te ke kèk pake Heroku bati ta gen binè mwen te bezwen yo. Nan fen a, rechèch la te mennen m ' isit la. Mwen telechaje ak depake uml.tar.gz epi li jwenn bagay sa yo:

total 6136
-rwxr-xr-x 1 cadey cadey   79744 Dec 10  2017 ifconfig*
-rwxr-xr-x 1 cadey cadey     373 Dec 13  2017 init*
-rwxr-xr-x 1 cadey cadey  149688 Dec 10  2017 insmod*
-rwxr-xr-x 1 cadey cadey   66600 Dec 10  2017 route*
-rwxr-xr-x 1 cadey cadey  181056 Jun 26  2015 slirp*
-rwxr-xr-x 1 cadey cadey 5786592 Dec 15  2017 uml*
-rwxr-xr-x 1 cadey cadey     211 Dec 13  2017 uml_run*

Sa a se yon binè slirp! Èske li travay?

./slirp
Slirp v1.0.17 (BETA) FULL_BOLT

Copyright (c) 1995,1996 Danny Gasparovski and others.
All rights reserved.
This program is copyrighted, free software.
Please read the file COPYRIGHT that came with the Slirp
package for the terms and conditions of the copyright.

IP address of Slirp host: 127.0.0.1
IP address of your DNS(s): 1.1.1.1, 10.77.0.7
Your address is 10.0.2.15
(or anything else you want)

Type five zeroes (0) to exit.

[autodetect SLIP/CSLIP, MTU 1500, MRU 1500]

SLiRP Ready ...

Pa fè aksidan - kidonk li ta dwe travay! Ann plante binè sa a nan ~/bin/slirp:

cp slirp ~/bin/slirp

Nan ka kreyatè pake a retire li, mwen te fè yon glas.

Rezo konfigirasyon

Koulye a, ann mete kanpe rezo a sou nwayo envite nou an. Mizajou opsyon lansman:

linux 
  root=/dev/root 
  rootfstype=hostfs 
  rootflags=$HOME/prefix/uml-demo 
  rw 
  mem=64M 
  eth0=slirp,,$HOME/bin/slirp 
  init=/bin/sh

Koulye a, ann vire sou rezo a:

mount -t proc proc proc/
mount -t sysfs sys sys/

ifconfig eth0 10.0.2.14 netmask 255.255.255.240 broadcast 10.0.2.15
route add default gw 10.0.2.2

De premye kòmandman konfigirasyon yo /proc и /sys nesesè pou travay ifconfig, ki mete koòdone rezo a pou kominike ak Slirp. Ekip route mete tab routage nwayo a pou fòse tout trafik yo dwe voye nan tinèl Slirp la. Ann tcheke sa a ak yon demann DNS:

nslookup google.com 8.8.8.8
Server:    8.8.8.8
Address 1: 8.8.8.8 dns.google

Name:      google.com
Address 1: 172.217.12.206 lga25s63-in-f14.1e100.net
Address 2: 2607:f8b0:4006:81b::200e lga25s63-in-x0e.1e100.net

Работает!

Remak pa .: Aparamman, pòs orijinal la te ekri sou yon Desktop ak yon kat rezo fil, oswa kèk lòt konfigirasyon ki pa mande pou chofè adisyonèl. Sou yon laptop ak WiFi 8265 soti nan Intel, yon erè rive lè ogmante rezo a

/ # ifconfig eth0 10.0.2.14 netmask 255.255.255.240 broadcast 10.0.2.15
slirp_tramp failed - errno = 2
ifconfig: ioctl 0x8914 failed: No such file or directory
/ #

Aparamman, nwayo a pa ka kominike ak chofè kat rezo a. Yon tantativ pou konpile firmwèr la nan nwayo a, malerezman, pa t 'ranje sitiyasyon an. Nan moman piblikasyon an, yo pa t kapab jwenn okenn solisyon ankò nan konfigirasyon patikilye sa a. Sou konfigirasyon ki pi senp (pa egzanp, nan Virtualbox), koòdone a leve kòrèkteman.

Ann otomatize redireksyon an ak script koki sa a:

#!/bin/sh
# init.sh

mount -t proc proc proc/
mount -t sysfs sys sys/
ifconfig eth0 10.0.2.14 netmask 255.255.255.240 broadcast 10.0.2.15
route add default gw 10.0.2.2

echo "networking set up"

exec /tini /bin/sh

Epi make li ègzekutabl:

chmod +x init.sh

Apre sa, nou pral fè chanjman nan liy kòmand nwayo a:

linux 
  root=/dev/root 
  rootfstype=hostfs 
  rootflags=$HOME/prefix/uml-demo 
  rw 
  mem=64M 
  eth0=slirp,,$HOME/bin/slirp 
  init=/init.sh

Epi ann repete:

SLiRP Ready ...
networking set up
/bin/sh: can't access tty; job control turned off

nslookup google.com 8.8.8.8
Server:    8.8.8.8
Address 1: 8.8.8.8 dns.google

Name:      google.com
Address 1: 172.217.12.206 lga25s63-in-f14.1e100.net
Address 2: 2607:f8b0:4004:800::200e iad30s09-in-x0e.1e100.net

Rezo a estab!

dosye docker

Pou fè li pi fasil pou ou tcheke tout bagay sa yo, mwen te kolekte dockerfile, ki otomatize pi fò nan etap ki dekri yo epi ki ta dwe ba ou yon konfigirasyon k ap travay. Mwen genyen tou nwayo prekonfigire, ki gen tout sa ki dekri nan pòs la. Men, li enpòtan pou w konprann ke isit la mwen te dekri sèlman anviwònman minimòm lan.

Mwen espere pòs sa a te ede w konprann ki jan yo ogmante yon nwayo envite. Li te tounen yon kalite mons, men piblikasyon an te vin ansent kòm yon gid konplè sou bati, enstale ak konfigirasyon Itilizatè Mode nan Linux anba vèsyon modèn nan sistèm opere nan fanmi sa a. Pwochen etap yo ta dwe gen ladan enstale sèvis ak lòt lojisyèl ki deja andedan sistèm envite a. Depi imaj veso Docker yo jis pibliye tarballs, ou ta dwe kapab ekstrè imaj la atravè docker export, ak Lè sa a, detèmine chemen enstalasyon li yo nan rasin nan sistèm fichye envite a. Oke, Lè sa a, egzekite script la koki.

Mèsi espesyal pou Rkeene ki soti nan #lobsters sou Freenode. San èd li debogaj Slirp, mwen pa ta rive sa lwen. Mwen pa gen okenn lide ki jan sistèm Slackware li a travay kòrèkteman ak slirp, men Ubuntu mwen ak sistèm Alpine pa t 'aksepte slirp ak binè Rkeene sijere m'. Men, li ase pou mwen ke omwen yon bagay mache pou mwen.

Sous: www.habr.com

Add nouvo kòmantè