Bii o ṣe le Bẹrẹ Lilo Ipo olumulo lori Lainos

Ifihan lati ọdọ onitumọ: Lodi si ẹhin ti iwọle nla ti awọn oriṣi awọn apoti sinu igbesi aye wa, o le jẹ ohun ti o nifẹ ati iwulo lati wa pẹlu kini awọn imọ-ẹrọ ti gbogbo eyi bẹrẹ lẹẹkan ni akoko kan. Diẹ ninu wọn le wulo titi di oni, ṣugbọn kii ṣe gbogbo eniyan ranti iru awọn ọna (tabi mọ, ti wọn ko ba mu wọn lakoko idagbasoke iyara wọn). Ọkan iru imọ-ẹrọ jẹ Linux Ipo olumulo. Onkọwe ti atilẹba ṣe iye ti o tọ ti n walẹ, ti n ṣalaye eyi ti awọn idagbasoke atijọ ti o tun ṣiṣẹ ati eyiti ko ṣe, ati papọ nkan bii awọn ilana igbesẹ-nipasẹ-igbesẹ lori bi o ṣe le ṣẹda UML ti ile-ile fun ararẹ ni 2k19. Ati bẹẹni, a pe onkọwe ti ifiweranṣẹ atilẹba si Habr Cadey, nitorina ti o ba ni awọn ibeere, beere ni ede Gẹẹsi ninu awọn asọye.

Bii o ṣe le Bẹrẹ Lilo Ipo olumulo lori Lainos

Ipo olumulo ni Lainos jẹ, ni otitọ, ibudo ti ekuro Linux si ararẹ. Ipo yii n gba ọ laaye lati ṣiṣẹ ekuro Linux ni kikun bi ilana olumulo ati pe awọn olupilẹṣẹ lo nigbagbogbo lati ṣe idanwo awakọ. Ṣugbọn ipo yii tun wulo bi ohun elo fun ipinya gbogbogbo, ipilẹ eyiti o jọra si iṣẹ ti awọn ẹrọ foju. Ipo yii n pese ipinya diẹ sii ju Docker, ṣugbọn o kere ju ẹrọ foju kan ni kikun bi KVM tabi Apoti Foju.

Lapapọ, Ipo Olumulo le dabi ohun elo ajeji ati ti o nira lati lo, ṣugbọn o ni awọn lilo rẹ. Lẹhinna, eyi jẹ ekuro Linux ti o ni kikun ti nṣiṣẹ bi olumulo ti ko ni anfani. Ẹya yii ngbanilaaye koodu ti ko ni igbẹkẹle lati ṣiṣẹ laisi eyikeyi irokeke ewu si ẹrọ agbalejo. Ati pe nitori eyi jẹ ekuro ti o ni kikun, awọn ilana rẹ ti ya sọtọ si ẹrọ agbalejo, iyẹn ni Awọn ilana ti nṣiṣẹ inu Ipo olumulo kii yoo han si agbalejo naa. Eyi kii ṣe bii eiyan Docker ibile, ninu eyiti ẹrọ agbalejo nigbagbogbo rii awọn ilana inu ibi ipamọ naa. Wo nkan pstree yii lati ọkan ninu awọn olupin mi:

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}]

Ati ṣe afiwe eyi si pstree ti ekuro Linux ni Ipo Olumulo:

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

Nigbati o ba n ṣiṣẹ pẹlu awọn apoti Docker, Mo le rii lati ọdọ agbalejo awọn orukọ ti awọn ilana ti o nṣiṣẹ ni alejo. Eyi ko ṣee ṣe pẹlu Ipo olumulo Linux. Kini o je? Eyi tumọ si pe awọn irinṣẹ ibojuwo ti n ṣiṣẹ nipasẹ ọna ṣiṣe iṣatunṣe Linux ma ri lakọkọ nṣiṣẹ ninu awọn alejo eto. Ṣugbọn ni awọn ipo miiran ẹya ara ẹrọ le jẹ idà oloju meji.

Ni gbogbogbo, gbogbo ifiweranṣẹ ti o wa ni isalẹ jẹ ikojọpọ ti iwadii ati awọn igbiyanju inira lati ṣaṣeyọri abajade ti o fẹ. Lati ṣe eyi, Mo ni lati lo ọpọlọpọ awọn irinṣẹ atijọ, ka awọn orisun kernel, ṣe ni ṣiṣatunṣe lekoko ti koodu ti a kọ nigbati Mo tun wa ni ile-iwe alakọbẹrẹ, ati tun tinker pẹlu Heroku kọ nipa lilo alakomeji pataki kan ni wiwa awọn irinṣẹ ti Mo nilo. Gbogbo iṣẹ yi yori si awọn enia buruku lori mi IRC pe mi a magician. Mo nireti pe ifiweranṣẹ yii yoo ṣiṣẹ bi iwe igbẹkẹle fun ẹnikan lati ṣe ohun kanna, ṣugbọn pẹlu awọn kernels tuntun ati awọn ẹya OS.

Ṣe akanṣe

Ṣiṣeto Ipo Olumulo Lainos ni awọn igbesẹ pupọ:

  • fifi sori ẹrọ awọn igbẹkẹle lori agbalejo;
  • gbigba lati ayelujara ekuro Linux;
  • ekuro Kọ setup;
  • apejọ ekuro;
  • fifi sori ẹrọ alakomeji;
  • eto eto faili alejo;
  • yiyan ti awọn aye ifilọlẹ kernel;
  • eto nẹtiwọki alejo;
  • ifilọlẹ ekuro alejo.

Mo ro pe ti o ba pinnu lati ṣe gbogbo eyi funrararẹ, o ṣee ṣe pe iwọ yoo ṣe ohun gbogbo ti a ṣalaye ni diẹ ninu awọn eto Ubuntu tabi Debian. Mo gbiyanju lati ṣe gbogbo nkan ti o wa loke ni pinpin ayanfẹ mi, Alpine, ṣugbọn ko si ohun ti o ṣiṣẹ, o han gbangba nitori ekuro Linux ti ni asopọ ni wiwọ si glibc-isms fun awọn awakọ ni Ipo olumulo. Mo gbero lati jabo eyi si oke lẹhin Mo ti pinnu iṣoro naa nipari.

Fifi sori ẹrọ lori ogun

Ubuntu nilo o kere ju awọn idii wọnyi lati kọ ekuro Linux (ti o ro pe fifi sori ẹrọ ti o mọ):

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

O le fi wọn sii pẹlu aṣẹ atẹle (bii gbongbo tabi pẹlu sudo):

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

Jọwọ ṣe akiyesi pe ṣiṣe eto isọdi akojọ aṣayan fun ekuro Linux yoo nilo fifi sori ẹrọ libncurses-dev. Jọwọ rii daju pe o ti fi sii nipa lilo aṣẹ atẹle (bii gbongbo tabi lilo sudo):

apt-get -y install libncurses-dev

Gbigba awọn ekuro

Pinnu ibiti o ti ṣe igbasilẹ ati lẹhinna kọ ekuro naa. Iwọ yoo nilo lati pin isunmọ 1,3 GB ti aaye dirafu lile fun iṣẹ yii, nitorinaa rii daju pe o ni.

Lẹhinna lọ si kernel.org ati gba URL lati ṣe igbasilẹ ẹya tuntun ti ekuro iduroṣinṣin. Ni akoko kikọ ifiweranṣẹ yii: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz

Ṣe igbasilẹ faili yii ni lilo 'wget':

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

Ati ki o jade pẹlu 'tar':

tar xJf linux-5.1.16.tar.xz

Bayi a tẹ iwe ilana ti o ṣẹda nigbati o ba n ṣii tarball:

cd linux-5.1.16

Ṣiṣeto kikọ ekuro kan

Eto kọ ekuro jẹ eto kan Ṣe awọn faili с ọpọlọpọ awọn aṣa irinṣẹ ati awọn iwe afọwọkọ lati automate awọn ilana. Lati bẹrẹ, ṣii eto iṣeto ori ayelujara:

make ARCH=um menuconfig

Yoo pari apejọ naa ni apakan ati ṣafihan apoti ibaraẹnisọrọ kan fun ọ. Nigbati imọlẹ ba han ni isalẹ ti window[Select]', o le tunto awọn eto nipa lilo Spacebar tabi Tẹ awọn bọtini. Lilọ kiri ni ayika window jẹ bi igbagbogbo nipa lilo awọn ọfa keyboard “oke” ati “isalẹ”, ati yiyan awọn eroja jẹ “osi” tabi “ọtun”.

Atọka wiwo -> tumọ si pe o wa ninu akojọ aṣayan, eyiti o le wọle si nipa lilo bọtini Tẹ. O han ni ọna jade nipasẹ '[Exit]'.

Fi awọn aṣayan wọnyi sinu '[Select]' ati rii daju pe aami '[*]' wa lẹgbẹẹ wọn:

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

Iyẹn ni, o le jade kuro ni window yii nipa yiyan lẹsẹsẹ '[Exit]' . Kan rii daju pe ni ipari o ti ṣetan lati ṣafipamọ iṣeto ni ki o yan '[Yes]'.

Mo ṣeduro pe ki o ṣiṣẹ ni ayika pẹlu awọn aṣayan kikọ ekuro lẹhin kika ifiweranṣẹ yii. Lati awọn adanwo wọnyi o le kọ ẹkọ pupọ nipa bii awọn oye ekuro ipele kekere ṣe n ṣiṣẹ ati bii awọn asia oriṣiriṣi ṣe ni ipa bi a ṣe kọ ekuro naa.

Ilé ekuro

Ekuro Linux jẹ eto nla ti o ṣe ọpọlọpọ awọn nkan. Paapaa pẹlu iṣeto kekere yii lori ohun elo agbalagba, apejọ le gba akoko diẹ. Nitorinaa kọ ekuro nipa lilo aṣẹ atẹle:

make ARCH=um -j$(nproc)

Fun kini? Aṣẹ yii yoo sọ fun akọle wa lati lo gbogbo awọn ohun kohun Sipiyu ti o wa ati awọn okun lakoko ilana kikọ. Egbe $(nproc) ni opin Kọ awọn ifibọ awọn ti o wu pipaṣẹ nproc, eyi ti o jẹ apakan coreutils ni boṣewa Ubuntu kọ.

Lẹhin akoko diẹ, ekuro wa yoo ṣe akojọpọ sinu faili ti o le ṣiṣẹ ./linux.

Fifi sori ẹrọ alakomeji

Niwọn igba ti Ipo Olumulo ni Lainos ṣẹda alakomeji deede, o le fi sii bi eyikeyi ohun elo miiran. Eyi ni bi mo ṣe ṣe:

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

O tun tọ lati rii daju pe ~/bin jẹ ninu rẹ $PATH:

export PATH=$PATH:$HOME/bin

Tito leto Guest File System

Ṣẹda itọsọna kan fun eto faili alejo:

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

Ṣii alpinelinux.org ati ninu download apakan ri awọn ti isiyi download ọna asopọ MINI ROOT FILESYSTEM. Ni akoko kikọ eyi ni:

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

Ṣe igbasilẹ tarball yii ni lilo 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

Bayi tẹ ilana eto faili alejo sii ki o si ṣii ile-ipamọ naa:

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

Awọn igbesẹ ti a ṣalaye yoo ṣẹda awoṣe eto faili kekere kan. Nitori ọna ti eto naa n ṣiṣẹ, fifi sori awọn idii nipasẹ oluṣakoso apk Alpine yoo nira pupọ. Ṣugbọn FS yii yoo to lati ṣe iṣiro imọran gbogbogbo.

A tun nilo ohun elo kan tini lati da agbara iranti duro Zombie lakọkọ ekuro alejo wa.

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

Ṣiṣẹda laini aṣẹ ekuro kan

Ekuro Linux, bii pupọ julọ awọn eto miiran, ni awọn ariyanjiyan laini aṣẹ ti o le wọle nipasẹ sisọ bọtini naa --help.

Ara – Iranlọwọ

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.

Igbimọ yii ṣe afihan awọn ipilẹ ifilọlẹ akọkọ. Jẹ ki a ṣiṣẹ ekuro pẹlu eto awọn aṣayan ti o kere julọ:

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

Awọn ila ti o wa loke sọ fun ekuro wa ni atẹle:

  • Jẹ ki a ro pe awọn root filesystem jẹ apseudo ẹrọ /dev/root.
  • Yan hostfs bi awakọ eto faili root.
  • Gbe eto faili alejo ti a ṣẹda lori ẹrọ gbongbo.
  • Ati bẹẹni, ni ipo kika-kikọ.
  • Lo awọn megabytes 64 ti Ramu nikan (o le lo pupọ kere si da lori ohun ti o gbero lati ṣe, ṣugbọn 64 MB dabi pe o jẹ iye to dara julọ).
  • Ekuro laifọwọyi bẹrẹ /bin/sh bi o init-ilana.

Ṣiṣe aṣẹ yii ati pe o yẹ ki o gba nkan bi atẹle:

Iwe miiran

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
/ # 

Awọn ifọwọyi loke yoo fun wa iwonba alejo eto, laisi awọn nkan bii /proc tabi sọtọ orukọ ogun. Fun apẹẹrẹ, gbiyanju awọn aṣẹ wọnyi:

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

Lati jade kuro ni eto alejo, tẹ sii exit tabi tẹ Iṣakoso-d. Eyi yoo tan ikarahun naa ti o tẹle pẹlu ijaaya kernel kan:

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

A ni ijaaya ekuro yii nitori ekuro Linux ro pe ilana ibẹrẹ n ṣiṣẹ nigbagbogbo. Laisi rẹ, eto naa ko le ṣiṣẹ mọ ati tiipa. Ṣugbọn niwọn igba ti eyi jẹ ilana ipo olumulo, abajade abajade fi ararẹ ranṣẹ si SIGABRT, eyiti o yori si ijade.

Ṣiṣeto nẹtiwọki alejo kan

Ṣugbọn eyi ni ibi ti awọn nkan bẹrẹ lati lọ si aṣiṣe fun wa. Nẹtiwọọki ni Ipo Olumulo Lainos wa nibiti gbogbo imọran ti “ipo olumulo” ti o lopin bẹrẹ lati ṣubu yato si. Lẹhinna, nẹtiwọọki nigbagbogbo ni opin ni ipele eto anfani awọn ipo ipaniyan fun awọn idi ti o han gbangba si gbogbo wa.

Akiyesi fun .: O le ka diẹ ẹ sii nipa orisirisi awọn aṣayan fun a ṣiṣẹ pẹlu nẹtiwọki kan ni UML nibi.

Irin ajo lati slirp

Sibẹsibẹ, ohun elo atijọ kan wa ti a ko ni atilẹyin ti a pe Rọra, pẹlu eyiti Ipo olumulo Linux le ṣe ajọṣepọ pẹlu nẹtiwọọki naa. O nṣiṣẹ ni aijọju bii akopọ TCP/IP ipele olumulo ati pe ko nilo eyikeyi awọn igbanilaaye eto lati ṣiṣẹ. Yi ọpa wà tu silẹ ni ọdun 1995, ati awọn ti o kẹhin imudojuiwọn ti wa ni dated Ọdun 2006. Slirp jẹ arugbo pupọ. Lakoko akoko laisi atilẹyin ati awọn imudojuiwọn, awọn olupilẹṣẹ ti wa titi di pe bayi ọpa yii le ṣe apejuwe bi "koodu rot".

Nitorinaa, jẹ ki a ṣe igbasilẹ Slirp lati awọn ibi ipamọ Ubuntu ati gbiyanju lati ṣiṣẹ:

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)

Ori mi o. Jẹ ká fi sori ẹrọ ni Slirp debugger ki o si ri ti o ba a le ro ero ohun ti n ṣẹlẹ nibi:

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.

Aṣiṣe naa n lu wa ila yii. Jẹ ká wo stacktrace, boya nkankan yoo ran wa nibẹ:

(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.

Nibi a rii pe jamba naa waye lakoko ibẹrẹ ti lupu akọkọ, nigbati slirp gbiyanju lati ṣayẹwo awọn akoko ipari. Ni akoko yii ni mo ni lati fi silẹ igbiyanju lati yokokoro. Ṣugbọn jẹ ki a wo boya Slirp, ti a ṣe lati oriṣi, ṣiṣẹ. Mo tun ṣe igbasilẹ igbasilẹ taara lati aaye naa Orisunforge, nitori fifa nkan lati ibẹ nipasẹ laini aṣẹ jẹ irora:

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

Nibi a rii awọn titaniji nipa awọn iṣẹ ti a ṣe sinu ti ko ṣe alaye, iyẹn ni, nipa aiṣeeṣe ti sisopọ faili alakomeji ti o mu abajade. O han pe laarin ọdun 2006 ati bayi gcc duro ṣiṣẹda awọn aami ti a lo ninu awọn iṣẹ agbedemeji ti a ṣe. Jẹ ki a gbiyanju lati rọpo ọrọ-ọrọ inline si asọye ofo ki o wo abajade:

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

Bẹẹkọ. Eyi ko ṣiṣẹ boya. Ko le wa awọn aami fun awọn iṣẹ wọnyi.

Ni aaye yii Mo fi silẹ ati bẹrẹ wiwa lori Github Heroku kọ jo. Ilana mi ni pe diẹ ninu awọn akopọ Heroku yoo ni awọn alakomeji ti Mo nilo. Ni ipari, wiwa mi yorisi mi nibi gangan. Mo ti gba lati ayelujara ati un packed uml.tar.gz o si ri awọn wọnyi:

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*

Eyi jẹ alakomeji slirp! Ṣe o ṣiṣẹ?

./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 ...

Ko ṣubu - nitorina o yẹ ki o ṣiṣẹ! Jẹ ki a gbin alakomeji yii sinu ~/bin/slirp:

cp slirp ~/bin/slirp

Ti o ba jẹ pe olupilẹṣẹ package naa yọkuro rẹ, I ṣe digi kan.

Iṣeto ni nẹtiwọki

Bayi jẹ ki ká tunto awọn nẹtiwọki lori wa alejo mojuto. Jẹ ki a ṣe imudojuiwọn awọn paramita ifilọlẹ:

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

Bayi jẹ ki a mu nẹtiwọki ṣiṣẹ:

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

Awọn pipaṣẹ iṣeto ni akọkọ meji /proc и /sys pataki fun iṣẹ ifconfig, eyi ti o ṣeto wiwo nẹtiwọki kan lati ṣe ibaraẹnisọrọ pẹlu Slirp. Egbe route ṣeto tabili afisona ekuro lati fi ipa mu gbogbo awọn ijabọ lati firanṣẹ nipasẹ eefin Slirp. Jẹ ki a ṣayẹwo eyi pẹlu ibeere DNS kan:

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

O ṣiṣẹ!

Akiyesi fun .: Nkqwe, ipolowo atilẹba ni a kọ sori tabili tabili pẹlu kaadi nẹtiwọọki ti a firanṣẹ, tabi iṣeto ni miiran ti ko nilo awakọ afikun. Lori kọǹpútà alágbèéká kan pẹlu WiFi 8265 lati Intel, aṣiṣe waye nigbati o ba gbe nẹtiwọki soke

/ # 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
/ #

Nkqwe, ekuro ko le ṣe ibasọrọ pẹlu awakọ nẹtiwọọki awakọ. Igbiyanju lati ṣajọ famuwia sinu ekuro, laanu, ko ṣe atunṣe ipo naa. Ni akoko ti ikede, ko si ojutu ti a le rii ni iṣeto ni pato yii. Lori awọn atunto ti o rọrun (fun apẹẹrẹ, ni Virtualbox), wiwo naa ti dide ni deede.

Jẹ ki a ṣe adaṣe adaṣe ni lilo iwe afọwọkọ ikarahun atẹle:

#!/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

Ki o si samisi rẹ bi ṣiṣe:

chmod +x init.sh

Ati lẹhinna jẹ ki a ṣe awọn ayipada si laini aṣẹ kernel:

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

Ati pe jẹ ki a tun:

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

Nẹtiwọọki naa jẹ iduroṣinṣin!

docker faili

Lati jẹ ki o rọrun fun ọ lati ṣayẹwo gbogbo eyi, Mo ti gba dockerfile, eyi ti o ṣe adaṣe pupọ julọ awọn igbesẹ ti a ṣalaye ati pe o yẹ ki o fun ọ ni iṣeto iṣẹ. Mo tun ni setan ekuro iṣeto ni, eyiti o ni ohun gbogbo ti a ṣalaye ninu ifiweranṣẹ. Ṣugbọn o ṣe pataki lati ni oye pe nibi Mo ti ṣe ilana awọn eto to kere julọ nikan.

Mo nireti pe ifiweranṣẹ yii ṣe iranlọwọ fun ọ lati loye bi o ṣe le mu ekuro alejo dide. O wa jade lati jẹ iru aderubaniyan kan, ṣugbọn atẹjade naa ni ipinnu lati jẹ itọsọna okeerẹ lori koko ti apejọ, fifi sori ẹrọ ati tunto Ipo olumulo ni Linux labẹ awọn ẹya ode oni ti awọn ọna ṣiṣe ti idile yii. Awọn igbesẹ ti o tẹle yẹ ki o pẹlu awọn iṣẹ fifi sori ẹrọ ati sọfitiwia miiran tẹlẹ ninu eto alejo. Niwọn bi awọn aworan apoti Docker jẹ igbega tarballs nikan, o yẹ ki o ni anfani lati jade aworan naa nipasẹ docker export, ati lẹhinna pinnu ọna lati fi sii ni gbongbo eto faili ekuro alejo. O dara, lẹhinna ṣiṣe iwe afọwọkọ ikarahun naa.

Ọpẹ pataki si Rkeene lati #lobsters lori Freenode. Laisi iranlọwọ rẹ ni n ṣatunṣe aṣiṣe Slirp, Emi kii yoo ti gba eyi jina. Emi ko ni imọran bii eto Slackware rẹ ṣe n ṣiṣẹ ni deede pẹlu slirp, ṣugbọn Ubuntu mi ati awọn eto Alpine ko gba slirp ati alakomeji Rkeene daba fun mi. Ṣugbọn o to fun mi pe o kere ju nkan kan ṣiṣẹ fun mi.

orisun: www.habr.com

Fi ọrọìwòye kun