Ungaqala Kanjani Ukusebenzisa Imodi Yomsebenzisi ku-Linux

Isingeniso esivela kumhumushi: Ngokumelene nokwasemuva kokungena okukhulu kwezinhlobo ezahlukene zeziqukathi ezimpilweni zethu, kungaba mnandi futhi kube wusizo ukuthola ukuthi yiziphi ubuchwepheshe lokhu konke kwaqala kanye ngesikhathi. Ezinye zazo zingasetshenziswa ngokunenzuzo kuze kube yilolu suku, kodwa akuwona wonke umuntu okhumbula izindlela ezinjalo (noma uyazi ukuthi azizange zibanjwe ngesikhathi sokukhula kwazo ngokushesha). Obunye ubuchwepheshe obunjalo yi-User Mode Linux. Umbhali wencwadi yokuqala wenze umsebenzi omningi wokumba, ethola ukuthi iyiphi intuthuko yakudala esasebenza nokuthi iyiphi engasebenzi, futhi wahlanganisa okuthile okufana nomyalelo wesinyathelo ngesinyathelo wokuthi ungathola kanjani i-UML ye-homebrew ngo-2k19. Futhi yebo, simeme umbhali wokuthunyelwe kwangempela ku-Habr I-Cadey, ngakho-ke uma unemibuzo - buza ngesiNgisi kumazwana.

Ungaqala Kanjani Ukusebenzisa Imodi Yomsebenzisi ku-Linux

Imodi Yomsebenzisi ku-Linux, empeleni, iyichweba le-Linux kernel ngokwayo. Le modi ikuvumela ukuthi usebenzise i-Linux kernel egcwele njengenqubo yomsebenzisi futhi ivamise ukusetshenziswa onjiniyela ukuhlola abashayeli. Kodwa le modi iyasiza futhi njengethuluzi elijwayelekile lokuzihlukanisa, isimiso esifana nokusebenza kwemishini ebonakalayo. Le modi ihlinzeka ngokuzihlukanisa kakhulu kune-Docker, kodwa ngaphansi komshini ogcwele ogcwele we-virtual njenge-KVM noma i-Virtual Box.

Sekukonke, Imodi Yomsebenzisi ingase ibonakale iyithuluzi elixakile futhi elinzima ukulisebenzisa, kodwa inakho ukusetshenziswa kwayo. Phela, lena i-Linux kernel egcwele ngokugcwele egijima kumsebenzisi ongenalungelo. Lesi sici sivumela ikhodi okungenzeka ayithenjwa ukuthi isebenze ngaphandle kokusongela umshini wokusingatha. Futhi njengoba lokhu kuyi-kernel egcwele, izinqubo zayo zihlukanisiwe nomshini wokubamba, okungukuthi izinqubo ezisebenza ngaphakathi Kwemodi Yomsebenzisi ngeke zibonakale kumsingathi. Lokhu akufani nesitsha se-Docker sendabuko, lapho umshini wokusingathwa uhlala ubona izinqubo ngaphakathi kwesitoreji. Bheka lesi siqeshana se-ptree kwenye yeziphakeli zami:

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

Futhi qhathanisa lokhu ne-psree ye-Linux kernel kuModi Yomsebenzisi:

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

Lapho ngisebenza neziqukathi ze-Docker, ngiyabona kumsingathi amagama ezinqubo ezisebenza kusivakashi. Nge-Linux User Mode, lokhu akunakwenzeka. Kusho ukuthini? Lokhu kusho ukuthi amathuluzi okuqapha asebenza ngohlelo oluncane lokuhlola lwe-Linux ungaboni izinqubo ezisebenza kusistimu yesivakashi. Kodwa kwezinye izimo lesi sici singaba inkemba esika nhlangothi zombili.

Ngokuvamile, konke okuthunyelwe ngezansi kuyiqoqo locwaningo nemizamo enzima yokufinyelela umphumela oyifunayo. Ukuze ngenze lokhu, kwakudingeka ngisebenzise amathuluzi ahlukahlukene asendulo, ngifunde imithombo ye-kernel, ngihlanganyele ekulungiseni amaphutha okujulile kwekhodi ebhalwe ngisesikoleni samabanga aphansi, futhi ngiphinde ngisebenzise i-Heroku yokwakha ngisebenzisa kanambambili ekhethekile ngifuna amathuluzi engangiwadinga. Wonke lo msebenzi uholele abafana ku-IRC yami ukuthi bangibize ngomlingo. Ngethemba ukuthi lokhu okuthunyelwe kusebenza njengemibhalo ethembekile yokuthi othile azame into efanayo ngama-kernel amasha nezinguqulo ze-OS.

Yenza ngokwezifiso

Ukusetha i-Linux User Mode kwenziwa ngezinyathelo ezimbalwa:

  • ukufaka okuncike kumsingathi;
  • ukulanda i-Linux kernel;
  • ukucushwa kwe-kernel ukwakha;
  • ukuhlanganiswa kwe-kernel;
  • ukufakwa kanambambili;
  • ukusetha uhlelo lwefayela lesivakashi;
  • ukukhethwa kwemingcele yokuqalisa i-kernel;
  • ukusetha inethiwekhi yesivakashi;
  • ukwethula i-kernel yesivakashi.

Ngicabanga ukuthi uma unquma ukuzenza ngokwakho, cishe uzokwenza konke okuchazwe kuhlelo oluthile lwe-Ubuntu noma lwe-Debian. Ngizamile ukusebenzisa konke lokhu okungenhla ekusabalaliseni engikuthandayo - i-Alpine, kodwa akwenzekanga lutho, ngokusobala ngenxa yokuthi i-Linux kernel ine-glibc-isms ebopha kanzima kubashayeli kuModi Yomsebenzisi. Ngihlela ukubika lokhu enhla nomfula ngemva kokuthi ekugcineni ngiqonde inkinga.

Ifaka okuncikile kumsingathi

Ubuntu budinga okungenani amaphakheji alandelayo ukwakha i-Linux kernel (kuthatha ukufaka okuhlanzekile):

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

Ungawafaka ngomyalo olandelayo (njengempande noma nge-sudo):

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

Qaphela ukuthi ukusebenzisa uhlelo lokusetha imenyu ye-Linux kernel kuzodinga ukufakwa kwe libncurses-dev. Sicela uqiniseke ukuthi ifakiwe kusetshenziswa umyalo olandelayo (njengempande noma usebenzisa i-sudo):

apt-get -y install libncurses-dev

Landa i-Kernel

Nquma ukuthi uzolanda kuphi bese wakhe i-kernel. Uzodinga ukunikeza cishe u-1,3 GB wesikhala se-hard drive kulo msebenzi, ngakho qiniseka ukuthi unaso.

Bese uya ku kernel.org futhi uthole i-URL ukuze ulande i-kernel yakamuva ezinzile. Ngesikhathi sokubhala lokhu: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz

Landa leli fayela usebenzisa 'wget':

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

Futhi uyikhiphe nge 'tar':

tar xJf linux-5.1.16.tar.xz

Manje sifaka uhla lwemibhalo oludalwe lapho sikhipha i-tarball:

cd linux-5.1.16

Ukusetha i-kernel build

Isistimu yokwakha i-kernel iyisethi Yenza amafayela с abaningi amathuluzi wangokwezifiso kanye nemibhalo yokwenza inqubo ngokuzenzakalelayo. Ukuze uqalise, vula uhlelo lokusetha ku-inthanethi:

make ARCH=um menuconfig

Izoqedela ingxenye yokuhlanganisa futhi ikubonise ibhokisi lengxoxo. Nini '[Select]', uzokwazi ukulungisa usebenzisa i-Space noma okhiye be-Enter. Zulazula efasiteleni, njengenjwayelo, ngemicibisholo yekhibhodi "phezulu" kanye "phansi", bese ukhetha izakhi - "kwesokunxele" noma "kwesokudla".

Isikhombi sokubuka —> sisho ukuthi ukumenu encane, efinyelelwa ngokhiye u-Enter. Indlela yokuphuma ngokusobala idlula '[Exit]'.

Faka izinketho ezilandelayo kokuthi '[Select]' futhi uqiniseke ukuthi kukhona uphawu '[*]' eduze kwabo:

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

Yilokho kuphela, ungaphuma kuleli windi ngokukhetha ngokulandelana '[Exit]'. Vele uqiniseke ukuthi ekugcineni uyacelwa ukuthi ulondoloze ukucushwa bese ukhetha '[Yes]'.

Ngincoma ukuthi udlale ngezinketho zokwakha i-kernel ngemuva kokufunda lokhu okuthunyelwe. Ngalokhu kuhlolwa, ungafunda okuningi mayelana nokuqonda umsebenzi we-kernel mechanics esezingeni eliphansi kanye nomthelela wamafulegi ahlukahlukene ekuhlanganiseni kwawo.

Ukwakha i-kernel

I-Linux kernel wuhlelo olukhulu olwenza izinto eziningi. Ngisho nokucushwa okuncane okunjalo kuhadiwe endala, kungathatha isikhathi eside ukwakha. Ngakho yakha i-kernel usebenzisa umyalo olandelayo:

make ARCH=um -j$(nproc)

Kwani? Lo myalo uzotshela umakhi wethu ukuthi asebenzise wonke ama-CPU cores nemicu enqubweni yokwakha. Ithimba $(nproc) ekugcineni kwe-Build ifaka okukhiphayo komyalo nproc, okuyingxenye coreutils esakhiweni esijwayelekile se-Ubuntu.

Ngemva kwesikhathi esithile, i-kernel yethu izohlanganiswa ibe ifayela elisebenzisekayo ./linux.

Ifaka kanambambili

Njengoba Imodi Yomsebenzisi ku-Linux idala kanambambili evamile, ungayifaka njenganoma iyiphi enye insiza. Nansi indlela engikwenze ngayo:

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

Kuyafaneleka futhi ukuqinisekisa ukuthi ~/bin ikuwe $PATH:

export PATH=$PATH:$HOME/bin

Ilungiselela Isistimu Yefayela Lezivakashi

Dala uhla lwemibhalo lwesistimu yefayela yesivakashi:

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

Vula i-alpinelinux.org futhi ungene landa isigaba thola isixhumanisi sangempela sokulanda MINI ROOT FILESYSTEM. Ngesikhathi sokuloba lokhu bekuwukuthi:

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

Landa le tarball usebenzisa i-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

Manje faka umkhombandlela wesistimu yefayela lezivakashi futhi ukhiphe ingobo yomlando:

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

Izenzo ezichazwe zizodala isifanekiso sesistimu yefayela elincane. Ngenxa yemvelo yesistimu, kuzoba nzima kakhulu ukufaka amaphakheji ngomphathi we-apk we-Alpine. Kodwa le FS izokwanela ukuhlola umbono ojwayelekile.

Sidinga nethuluzi ithini ukumisa ukusetshenziswa kwenkumbulo izinqubo ze-zombie i-kernel yethu yesivakashi.

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

Ukudala I-Kernel Command Line

I-Linux kernel, njengezinye izinhlelo eziningi, inezimpikiswano zomugqa womyalo ezingafinyelelwa ngokucacisa ukhiye --help.

Yena ngokwakhe—usizo

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.

Leli phaneli ligqamisa amapharamitha okuqalisa ayinhloko. Masiqalise i-kernel ngesethi encane edingekayo yezinketho:

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

Imigqa engenhla itshela i-kernel yethu okulandelayo:

  • Cabanga ukuthi uhlelo lwefayela lwempande luyidivayisi mbumbulu /dev/root.
  • Khetha ama-hostfs njengomshayeli wesistimu yezimpande.
  • Khipha uhlelo lwefayela lesivakashi esiludalile kudivayisi yempande.
  • Futhi yebo, kumodi yokufunda-bhala.
  • Sebenzisa kuphela u-64 MB we-RAM (ungasebenzisa okuncane kakhulu kuye ngokuthi uhlela ukwenzani, kodwa u-64 MB ubonakala njengenani elifanele).
  • I-kernel iqala ngokuzenzakalelayo /bin/sh kanjani init- inqubo.

Qalisa lo myalo futhi kufanele uthole okuthile okufana nalokhu:

Elinye ishidi

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

Ukukhohlisa okungenhla kuzosinika isistimu yezivakashi encane, ngaphandle kwezinto ezifana /proc noma igama lomethuleli elinikeziwe. Isibonelo, zama imiyalo elandelayo:

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

Ukuze uphume kusivakashi, thayipha exit noma cindezela control-d. Lokhu kuzobulala igobolondo elilandelwa ukwethuka kwe-kernel:

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

Sithole lolu valo lwe-kernel ngoba i-Linux kernel icabanga ukuthi inqubo yokuqalisa isebenza njalo. Ngaphandle kwayo, isistimu ngeke isakwazi ukusebenza futhi iyacisha. Kodwa njengoba lokhu kuyinqubo yemodi yomsebenzisi, umphumela ophumayo uzithumela kuwo SIGABRT, okuholela ekuphumeni.

Ukusethwa kwenethiwekhi yesivakashi

Kodwa kulapho izinto ziqala khona ukungahambi kahle kithi. Inethiwekhi Kumodi Yomsebenzisi i-Linux yilapho wonke umqondo "wemodi yomsebenzisi" ekhawulelwe uqala ukubhidlika. Phela, inethiwekhi ngokuvamile ilinganiselwe ezingeni lesistimu nelungelo izindlela zokubulawa kwethu sonke izizathu eziqondakalayo.

Qaphela. ngokwe .: ungafunda kabanzi mayelana nezinketho ezahlukene zokusebenza nenethiwekhi ku-UML lapha.

Uhambo lokushelela

Nokho, kukhona ithuluzi lasendulo futhi cishe elingasekelwe okuthiwa Slirp, lapho Imodi Yomsebenzisi i-Linux ingahlanganyela nenethiwekhi. Isebenza njengesitaki sezinga lomsebenzisi le-TCP/IP futhi ayidingi izimvume zesistimu ukuze isebenze. Leli thuluzi kwaba ikhishwe ngo-1995, futhi isibuyekezo sokugcina sinedethi 2006. USlirp mdala kakhulu. Phakathi nesikhathi ngaphandle kokusekelwa nezibuyekezo, abahlanganisi baye bahamba kude kangangokuthi manje leli thuluzi lingachazwa kuphela ngokuthi ukubola kwekhodi.

Ngakho-ke, ake silande i-Slirp kumakhosombe e-Ubuntu bese sizame ukuyisebenzisa:

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 thixo. Masifake isilungisi sephutha sika-Slirp futhi sibone ukuthi singakwazi yini ukuthola ukuthi kwenzakalani lapha:

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.

Iphutha liyasishaya lo mugqa. Ake sibheke i-stacktrace, mhlawumbe kukhona okungasisiza lapho:

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

Lapha sibona ukuthi ukuphahlazeka kwenzeka ngesikhathi sokuqala kwe-loop enkulu lapho i-slirp izama ukuhlola ukuphela kwesikhathi. Kungalesi sikhathi lapho kwadingeka ngiyeke ukuzama ukulungisa iphutha. Kodwa ake sibone ukuthi i-Slirp, eyakhiwe ngezinhlobo, iyasebenza yini. Ngilande kabusha ingobo yomlando ngokuqondile kusuka kusayithi Sourceforge, ngoba ukudonsa okuthile lapho ngomugqa womyalo kubuhlungu:

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

Lapha sibona izexwayiso mayelana nemisebenzi eyakhelwe ngaphakathi engachazwanga, okungukuthi, mayelana nokungakwazi ukuxhumanisa ifayela kanambambili eliwumphumela. Kubonakala sengathi phakathi kuka-2006 naleli phuzu, i-gcc yayeka ukukhiqiza izimpawu ezisetshenziswa emisebenzini eyakhelwe ngaphakathi yamafayela ahlanganisiwe amaphakathi. Ake sizame ukufaka igama elingukhiye esikhundleni inline emazwaneni angenalutho bese ubheka umphumela:

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

Cha. Nalokhu akusebenzi. Namanje akakwazi ukuthola izimpawu zale misebenzi.

Ngalesi sikhathi, ngiyekile futhi ngaqala ukubuka i-Github Heroku ukwakha amaphakheji. Ithiyori yami bekungukuthi iphakheji yokwakha ye-Heroku izoqukatha okuhamba ngakubili engikudingayo. Ekugcineni, ukusesha kwangiholela lapho ke. Ngalanda ngakhipha uml.tar.gz futhi ngathola okulandelayo:

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*

Lena kanambambili eshelelayo! Ingabe iyasebenza?

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

Ayiphahlazeki - ngakho-ke kufanele isebenze! Masitshale lokhu kanambambili phakathi ~/bin/slirp:

cp slirp ~/bin/slirp

Uma ngabe umenzi wephakheji elisusa, I wenza isibuko.

Ukusethwa kwenethiwekhi

Manje ake simise inethiwekhi ku-kernel yethu yesivakashi. Masibuyekeze amapharamitha wokuqalisa:

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

Manje ake sivule inethiwekhi:

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

Imiyalo yokuqala emibili yokumisa /proc и /sys okudingekayo emsebenzini ifconfig, esetha isixhumi esibonakalayo senethiwekhi ukuthi sixhumane ne-Slirp. Ithimba route isetha ithebula le-kernel routing ukuze iphoqe yonke ithrafikhi ukuthi ithunyelwe ngomhubhe we-Slirp. Ake sihlole lokhu ngombuzo we-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

Работает!

Inothi . Kukhompyutha ephathekayo ene-WiFi 8265 evela ku-Intel, kwenzeka iphutha lapho kukhushulwa inethiwekhi

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

Ngokusobala, i-kernel ayikwazi ukuxhumana nomshayeli wedrayivu yenethiwekhi. Umzamo wokuhlanganisa i-firmware ku-kernel, ngeshwa, ayizange ilungise isimo. Ngesikhathi sokushicilela, akukwazanga ukuthola isisombululo kulokhu kulungiselelwa. Kuzilungiselelo ezilula (ngokwesibonelo, ku-Virtualbox), isixhumi esibonakalayo siphakanyiswa ngendlela efanele.

Ake siguqule ukuqondisa kabusha ngokuzenzakalelayo ngombhalo wegobolondo olandelayo:

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

Futhi imake ukuthi iyasebenziseka:

chmod +x init.sh

Bese sizokwenza izinguquko kulayini womyalo we-kernel:

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

Ake siphinde:

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

Inethiwekhi izinzile!

ifayela le-docker

Ukwenza kube lula kuwe ukuthi uhlole konke lokhu, ngiqoqile I-Dockerfile, eyenza ngokuzenzakalelayo iningi lezinyathelo ezichaziwe futhi okufanele ikunikeze ukucushwa okusebenzayo. Nami nginakho i-kernel elungiselelwe ngaphambili, equkethe konke okuchazwe kokuthunyelwe. Kodwa kubalulekile ukuqonda ukuthi lapha ngichaze kuphela izilungiselelo ezincane.

Ngethemba ukuthi lokhu okuthunyelwe kukusizile ukuthi uqonde indlela yokukhulisa i-kernel yesivakashi. Kuvele ukuthi kwakuwuhlobo oluthile lwesilo, kodwa ukushicilelwa kwaqanjwa njengomhlahlandlela ophelele wokwakha, ukufakwa kanye nokumisa Imodi Yomsebenzisi ku-Linux ngaphansi kwezinguqulo zesimanje zezinhlelo zokusebenza zalo mndeni. Izinyathelo ezilandelayo kufanele zibandakanye ukufaka amasevisi nenye isofthiwe esivele ingaphakathi kwesistimu yesivakashi. Njengoba izithombe zesitsha se-Docker zingama-tarball ashicilelwe nje, kufanele ukwazi ukukhipha isithombe nge docker export, bese unquma indlela yayo yokufaka empandeni yesistimu yefayela le-kernel yesivakashi. Hhayi-ke, bese ugijima iskripthi segobolondo.

Sibonga ngokukhethekile u-Rkeene ovela ku-#lobster ku-Freenode. Ngaphandle kosizo lwakhe lokususa iphutha ku-Slirp, bengingeke ngifinyelele kuleli zinga. Angazi ukuthi uhlelo lwakhe lwe-Slackware lusebenza kahle kanjani nge-slirp, kodwa izinhlelo zami ze-Ubuntu ne-Alpine azivumanga ukushelela futhi i-Rkeene kanambambili ingiphakamisele. Kodwa kwanele kimi ukuthi okungenani kukhona okungisebenzelayo.

Source: www.habr.com

Engeza amazwana