Me pehea te tiimata ki te whakamahi Aratau Kaiwhakamahi i Linux

He kupu whakataki mai i te kaiwhakamaori: I runga i te ahua o te urunga nui ki roto i o tatou oranga o nga momo ipu, he mea tino pai me te whai hua ki te mohio he aha nga hangarau i timata katoa. Ko etahi o enei ka taea te whakamahi pai tae noa ki tenei ra, engari kaore nga tangata katoa e mahara ki enei tikanga (me te mohio ranei mena kaore i mau i te wa o to ratau whanaketanga tere). Ko tetahi o enei hangarau ko te Aratau Kaiwhakamahi Linux. He maha nga mahi keri a te kaituhi o te taketake, me te whakaaro ko wai o nga whanaketanga tawhito kei te mahi tonu me te kore e mahi, me te whakakotahi i tetahi mea penei i te tohutohu taahiraa-i-te-taahiraa me pehea e whiwhi ai koe i te UML homebrew i 2k19. Ae, i powhirihia e matou te kaituhi o te panui tuatahi ki a Habr Cadey, na mena kei a koe etahi patai - patai ki te reo Ingarihi i roto i nga korero.

Me pehea te tiimata ki te whakamahi Aratau Kaiwhakamahi i Linux

Ko te Aratau Kaiwhakamahi i roto i te Linux, he pono, he tauranga o te kernel Linux ki a ia ano. Ma tenei aratau ka taea e koe te whakahaere i te kakano Linux katoa hei mahinga kaiwhakamahi me te whakamahia e nga kaihanga ki te whakamatautau i nga taraiwa. Engari he pai ano hoki tenei aratau hei taputapu wehewehe whanui, ko te kaupapa he rite ki te mahi a nga miihini mariko. Ko tenei aratau ka nui ake te wehe atu i a Docker, engari he iti ake i te miihini mariko katoa penei i te KVM, Pouaka Mariko ranei.

I te nuinga o te waa, ko te ahua o te Aratau Kaiwhakamahi he taputapu kee me te uaua ki te whakamahi, engari kei a ia ano ona whakamahinga. I muri i nga mea katoa, he kakano Linux tonu tenei e rere ana mai i tetahi kaiwhakamahi kore. Ko tenei ahuatanga ka taea te whakahaere i nga waehere kore pono ki te kore he riri ki te miihini manaaki. A, i te mea he kakano katoa tenei, ka wehea ana tukanga mai i te miihini manaaki, ara Ko nga tukanga e rere ana i roto i te Aratau Kaiwhakamahi e kore e kitea e te kaihautu. Kaore tenei i te rite ki te ipu Docker o mua, na te mea ka kite tonu te miihini manaaki i nga mahi kei roto i te putunga. Titiro ki tenei waahanga pstree mai i tetahi o aku tūmau:

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

A whakatauritea tenei ki te pstree o te kernel Linux i te Aratau Kaiwhakamahi:

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

I te wa e mahi ana me nga ipu Docker, ka kitea e au mai i te kaihautu nga ingoa o nga tukanga e rere ana i roto i te manuhiri. Ma te Aratau Kaiwhakamahi Linux, kaore e taea. He aha te tikanga? Ko te tikanga ko nga taputapu aroturuki e rere ana i roto i te punaha arotake a Linux kaua e kite nga tukanga e rere ana i roto i te punaha manuhiri. Engari i etahi ahuatanga, ka taea e tenei waahanga te hoari matarua.

I te nuinga o te waa, ko te panui katoa i raro nei he kohinga rangahau me nga ngana uaua ki te whakatutuki i te hua e hiahiatia ana. Ki te mahi i tenei, me whakamahi au i nga momo taputapu tawhito, te panui i nga puna kakano, te mahi patuiro i nga waehere i tuhia i nga ra i ahau i te kura tuatahi, me te tarai ano ki nga hangahanga a Heroku ma te whakamahi i te rua motuhake hei rapu i nga taputapu e hiahiatia ana e au. . Ko enei mahi katoa i arahi nga taangata o taku IRC ki te kii mai he makutu. Te ti'aturi nei au he tuhinga pono tenei pou mo tetahi ki te whakamatau i taua mea me nga kakano hou me nga putanga OS.

whakatikatikanga

Ko te whakarite i te Aratau Kaiwhakamahi Linux he maha nga waahanga:

  • te whakauru i nga whakawhirinaki ki te kaihautu;
  • te tango i te kernel Linux;
  • whirihoranga hanga kernel;
  • hui kernel;
  • whakaurunga rua;
  • te whirihora i te punaha konae manuhiri;
  • te kowhiringa o nga tawhā whakarewanga kernel;
  • te whakarite whatunga manuhiri;
  • timata i te kakano manuhiri.

Ki taku whakaaro mena ka whakatau koe ki te mahi i a koe ano, ka mahi pea koe i nga mea katoa e whakaahuatia ana i roto i etahi punaha rite Ubuntu, Debian ranei. I ngana ahau ki te whakatinana i nga mea katoa i runga ake nei i roto i taku tohatoha tino pai - Alpine, engari kaore he mea i puta mai, na te mea ko te kernel Linux he glibc-isms uaua mo nga taraiwa i te Aratau Kaiwhakamahi. Ka whakaaro ahau ki te tuku korero ki te taha whakarunga i muri i taku mohiotanga ki te raruraru.

Te whakauru i nga whakawhirinaki ki te kaihautu

Kei te hiahia a Ubuntu ki nga kohinga e whai ake nei hei hanga i te pata Linux (mehemea he pai te whakaurunga):

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

Ka taea e koe te whakauru i a raatau me te whakahau e whai ake nei (hei pakiaka me te sudo ranei):

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

Kia mahara ko te whakahaere i te kaupapa tatūnga tahua kernel Linux ka hiahia te whakaurunga o libncurses-dev. Me mohio kei te whakauruhia me te whakahau e whai ake nei (hei pakiaka me te sudo ranei):

apt-get -y install libncurses-dev

Tikina Kernel

Whakatauhia te wahi hei tango ake ka hanga ai i te kernel. Mo tenei mahi, ka hiahia koe ki te toha i te 1,3 GB o te mokowā kōpae mārō, no reira kia mohio kei a koe.

I muri haere ki kernel.org me te tiki i te URL ki te tango i te kernel pumau hou. I te wa e tuhi ana ko: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz

Tikiake tenei kōnae ma te whakamahi 'wget':

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

A unu ki te 'tar':

tar xJf linux-5.1.16.tar.xz

Inaianei ka uru matou ki te raarangi i hangaia i te wa e wetewete ana te tarball:

cd linux-5.1.16

Tatūnga hanga Kernel

He huinga te punaha hanga kernel Makefiles с maha taputapu ritenga me nga tuhinga tuhi hei whakaaunoa i te mahi. Tuatahi, whakatuwheratia te kaupapa tatūnga tauwhitiwhiti:

make ARCH=um menuconfig

Ka hangaia he waahanga ka whakaatu i tetahi pouaka korero mo koe. Ina '[Select]', ka taea e koe te whirihora ma te whakamahi i nga taviri Mokowā, Whakauru ranei. Whakaterehia te matapihi, pera i mua, me nga pere papapātuhi "runga" me "iho", ka kowhiri i nga huānga - "maui" ranei "matau".

Ko te atatohu tirohanga —> te tikanga kei roto koe i te tahuaroto, ka uru atu ki te taviri Whakauru. Ko te huarahi ki waho ko te maarama ma te '[Exit]'.

Whakauruhia nga whiringa e whai ake nei ki '[Select]' kia mohio kei a ratou he '[*]' ki te taha o ratou:

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

Koia, ka taea e koe te puta atu i tenei matapihi ma te kowhiri i te '[Exit]'. Me mohio ka akihia koe ki te tiaki i te whirihoranga i te mutunga ka kowhiri '[Yes]'.

Ka tūtohu ahau kia takaro koe me nga whiringa hanga kernel i muri i te panui i tenei panui. Ma enei whakamatautau, ka taea e koe te ako nui mo te maarama ki nga mahi a nga miihini kakano taumata-iti me te paanga o nga momo haki ki tana huihuinga.

Te hanga i te kakano

Ko te kernel Linux he kaupapa nui e mahi ana i nga mahi maha. Ahakoa te iti o te whirihoranga i runga i nga taputapu tawhito, ka roa pea te hanga. Na hanga te kernel me te whakahau e whai ake nei:

make ARCH=um -j$(nproc)

Hei aha? Ma tenei whakahau e korero ki ta maatau kaihanga ki te whakamahi i nga waahanga CPU katoa e waatea ana me nga miro i roto i te mahi hanga. Kapa $(nproc) i te mutunga o Hanga ka whakakapi i te putanga o te whakahau nproc, he wahanga o coreutils i roto i te hanga Ubuntu paerewa.

Whai muri i etahi wa, ka whakahiatohia to tatou kernel ki tetahi konae ka taea te whakahaere ./linux.

Te whakauru i te rua

Mai i te mea ka hangaia e te Aratau Kaiwhakamahi i Linux he taarua auau, ka taea e koe te whakauru pera me etahi atu taputapu. Anei taku mahi:

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

He mea tika ano kia tino mohio ~/bin kei roto i to $PATH:

export PATH=$PATH:$HOME/bin

Te whakarite i te punaha konae manuhiri

Waihangahia he whaiaronga mo te punaha konae manuhiri:

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

Whakatuwherahia te alpinelinux.org me roto wāhanga tango kitea te hono download tūturu MINI ROOT FILESYSTEM. I te wa i tuhia ai ko:

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

Tangohia tenei tarball ma te whakamahi i te 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

Inaianei whakauruhia te raarangi o te punaha konae manuhiri me te tango i te puranga:

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

Ko nga mahi kua whakaahuatia ka hangaia he tauira punaha konae iti. Na te ahua o te punaha, ka tino uaua ki te whakauru i nga kete ma te kaiwhakahaere Alpine apk. Engari ko tenei FS ka nui ki te arotake i te whakaaro whanui.

Kei te hiahia hoki matou ki tetahi taputapu tini ki te aukati i te kai mahara nga tukanga zombie to tatou kakano manuhiri.

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

Te hanga raina whakahau kernel

Ko te kernel Linux, pera i te nuinga atu o nga papatono, he tohenga rarangi whakahau ka taea te uru atu ma te tohu i te ki --help.

Ko ia ano — awhina

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.

Ko tenei roopu e whakaatu ana i nga tawhā matua o te whakarewatanga. Me whakahaere te kernel me nga huinga whiringa iti e hiahiatia ana:

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

Ko nga rarangi i runga ake nei e korero ana ki ta maatau kernel e whai ake nei:

  • Whakaarohia he taputapu pseudo te punaha konae pakiaka /dev/root.
  • Kōwhiri hostfs hei taraiwa pūnaha kōnae pakiaka.
  • Whakanuia te punaha konae manuhiri i hangaia e matou ki runga i te taputapu pakiaka.
  • Ae, i roto i te aratau panui-tuhi.
  • Whakamahia te 64 MB anake o te RAM (ka taea e koe te whakamahi kia iti ake i runga i nga mea e whakamahere ana koe ki te mahi, engari ko te 64 MB te ahua o te moni tino pai).
  • Ka timata aunoa te kernel /bin/sh pehea init- tukanga.

Whakahaerehia tenei whakahau ka whiwhi koe i tetahi mea penei:

Kotahi atu pepa

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

Ko nga raweke i runga ake nei ka homai pūnaha manuhiri i te iti rawa, kaore he mea penei /proc ingoa kaihautū kua tohua ranei. Hei tauira, ngana nga whakahau e whai ake nei:

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

Hei takiputa i te manuhiri, pato exit ranei press mana-d. Ma tenei ka mate te anga ka whai i te panic kernel:

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

I raru matou i tenei kakano na te mea e whakaaro ana te kernel Linux kei te haere tonu te mahi arawhiti. Ki te kore, ka kore e taea e te punaha te mahi me te pakaru. Engari i te mea he tukanga aratau-kaiwhakamahi tenei, ko te putanga ka tukuna ki a ia ano SIGABRT, ka puta he putanga.

Tatūnga whatunga manuhiri

Na konei ka timata nga mahi he. Whatunga i roto i te Aratau Kaiwhakamahi Linux kei reira te katoa o te ariā o te "aratau kaiwhakamahi" iti ka timata ki te taka. I muri i nga mea katoa, ko te tikanga i te taumata o te punaha, he iti te whatunga whai mana tikanga mahi mo tatou katoa nga take e marama ana.

Tuhipoka. per .: ka taea e koe te panui atu mo nga whiringa rereke mo te mahi me te whatunga i UML konei.

Haerenga ki Slirp

Heoi, he taputapu tawhito me te tata kore tautoko e kiia ana Slirp, ka taea e te Aratau Kaiwhakamahi Linux te taunekeneke me te whatunga. He rite tonu te mahi ki te paparanga TCP/IP taumata-kaiwhakamahi me te kore e hiahiatia he whakaaetanga punaha hei whakahaere. Ko tenei taputapu i tukuna i te tau 1995, a ko te whakahōutanga hou he rā 2006. He tawhito rawa a Slirp. I roto i te wa kaore he tautoko me nga whakahou, kua tae noa atu nga kaitoi i tenei wa ka taea te korero ko tenei taputapu anake pirau waehere.

Na me tango a Slirp mai i nga putunga Ubuntu ka ngana ki te whakahaere:

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)

Aue te atua. Tāutahia te patuiro a Slirp ka kite mena ka taea e tatou te mohio he aha kei konei:

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.

Ko te hapa e pa ana ki roto i a tatou tenei raina. Me titiro ki te stacktrace, tera pea tetahi mea hei awhina i a tatou ki reira:

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

I konei ka kite tatou ka puta te tukinga i te wa o te tiimata o te koowhiti matua i te wa e ngana ana a slirp ki te tirotiro mo nga waahi. I tenei wa, me mutu taku ngana ki te patuiro. Engari kia kite mena he mea hanga a Slirp mai i nga momo mahi. I tikina ano e ahau te puranga mai i te pae Pūtake Pūtake, na te mea he mamae te toia i tetahi mea mai i reira ma te raina whakahau:

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

I konei ka kite matou i nga matohi mo nga mahi hanga-i roto, ara, mo te kore e taea te hono i te konae rua. Te ahua nei i waenganui i te tau 2006 me tenei wa, ka mutu te hanga a gcc i nga tohu e whakamahia ana i roto i nga mahi whakauru o nga konae kua whakahiato waenga. Me ngana ki te whakakapi i te kupu matua inline i runga i te korero kau ka titiro ki te hua:

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

Kao. Kare hoki tenei e mahi. Kaore ano kia kitea nga tohu mo enei mahi.

I tenei wa, ka mutu ahau ka tiimata ki te titiro ki a Github Heroku hanga pōkai. Ko taku ariā ko etahi o nga kohinga hanga a Heroku kei roto nga rua e hiahiatia ana e au. I te mutunga, na te rapu i arahi ahau i konei. I tikina ake e ahau ka wetewete uml.tar.gz ka kitea e whai ake nei:

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*

Koinei te slirp rua! E mahi ana ia?

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

Kaore e pakaru - na me mahi! Kia whakatōhia tenei rua ki roto ~/bin/slirp:

cp slirp ~/bin/slirp

Mena ka tangohia e te kaihanga kete, ka tangohia e ahau hanga he whakaata.

Tatūnga whatunga

Inaianei me whakarite te whatunga ki runga i ta tatou kakano manuhiri. Whakahou i nga whiringa whakarewatanga:

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

Inaianei kia whakakāhia te whatunga:

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

Ko nga whakahau whirihoranga tuatahi e rua /proc и /sys e tika ana mo te mahi ifconfig, e whakatakoto ana i te atanga whatunga ki te korero ki a Slirp. Kapa route ka whakatakoto i te ripanga ararere kernel kia kaha te tuku waka katoa ma te kauhanga Slirp. Kia tirohia tenei me tetahi patai 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

Mahi ana!

Note per .: Te ahua nei, i tuhia te pou taketake ki runga papamahi me te kaari whatunga waea, etahi atu whirihoranga ranei kaore e hiahiatia he taraiwa taapiri. I runga i te pona me te WiFi 8265 mai i Intel, ka puta he hapa i te wa e whakaarahia ana te whatunga

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

Ko te ahua, kaore e taea e te kernel te korero ki te taraiwa kaari whatunga. Ko te ngana ki te whakahiato i te firmware ki roto i te kernel, engari kaore i whakatikahia te ahuatanga. I te wa o te whakaputanga, kaore i kitea he otinga i tenei whirihoranga. I runga i nga whirihora ngawari ake (hei tauira, i roto i te Virtualbox), ka piki tika te atanga.

Me whakaaunoa i te anga ki te tuhinga anga e whai ake nei:

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

A tohu ka taea te whakahaere:

chmod +x init.sh

Na ka huri taatau ki te raina whakahau kernel:

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

A kia tuaruatia ano:

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

He pūmau te whatunga!

kōnae docker

Kia ngawari ake te tirotiro i enei mea katoa, kua kohia e au Dockerfile, e whakaaunoa ana i te nuinga o nga hikoinga kua whakaahuatia, me hoatu he whirihoranga mahi. Kei a au ano kakano kua whirihorahia, kei a ia nga mea katoa e whakaahuatia ana i te panui. Engari he mea nui ki te maarama i konei kua whakaatuhia e au te waahi iti rawa.

Te ti'aturi nei au kua awhina tenei panui ki a koe ki te mohio me pehea te whakaara i te kakano manuhiri. I puta mai he momo taniwha, engari i whakaarohia te whakaputanga hei aratohu matawhānui mo te hanga, te whakauru me te whirihora i te Aratau Kaiwhakamahi ki Linux i raro i nga putanga hou o nga punaha whakahaere o tenei whanau. Ko nga mahi ka whai ake me whakauru i nga ratonga me etahi atu rorohiko kei roto i te punaha manuhiri. I te mea ko nga whakaahua ipu Docker he panui panui noa, ka taea e koe te tango i te ahua ma docker export, ka whakatau i tana ara whakaurunga ki te putake o te punaha konae a te kakano manuhiri. Na, ka mahia te tuhinga anga.

Nga mihi nui ki a Rkeene mai i te #lobsters i runga Freenode. Mehemea kaore tana awhina ki te patuiro i a Slirp, kare au e tae ki tenei tawhiti. Kaore au i te mohio ki te mahi tika o tana punaha Slackware me te slirp, engari karekau aku punaha Ubuntu me Alpine i whakaae ki te slirp me te Rkeene rua i kii mai ki ahau. Engari he mea nui ki ahau ko tetahi mea e pai ana mo au.

Source: will.com

Tāpiri i te kōrero