Otu esi amalite iji ọnọdụ onye ọrụ na Linux

Okwu mmalite sitere n'aka onye ntụgharị: N'azụ azụ nke nnukwu ntinye nke ụdị arịa dị iche iche na ndụ anyị, ọ nwere ike ịbụ ihe na-adọrọ mmasị ma bara uru iji chọpụta teknụzụ ndị a malitere otu oge. Ụfọdụ n'ime ha nwere ike ịba uru ruo taa, ma ọ bụghị onye ọ bụla na-echeta ụzọ ndị dị otú ahụ (ma ọ bụ mara, ma ọ bụrụ na ejideghị ha n'oge mmepe ngwa ngwa). Otu teknụzụ dị otú ahụ bụ Linux Mode User. Onye edemede nke mbụ mere nke ọma nke igwu ala, na-achọpụta nke n'ime mmepe ochie ka na-arụ ọrụ na nke na-adịghị, ma tinye ọnụ ihe dịka ntụziaka nzọụkwụ site na otu esi emepụta UML nke ụlọ maka onwe gị na. 2k19. Ma ee, anyị kpọrọ onye dere akwụkwọ ozi mbụ na Habr Cadey, Ya mere ọ bụrụ na ị nwere ajụjụ, jụọ na English na nkọwa.

Otu esi amalite iji ọnọdụ onye ọrụ na Linux

Ọnọdụ onye ọrụ na Linux bụ, n'ezie, ọdụ ụgbọ mmiri nke Linux kernel n'onwe ya. Ụdị a na-enye gị ohere ịme kernel Linux zuru ezu dị ka usoro onye ọrụ na ndị mmepe na-ejikarị nwalee ndị ọkwọ ụgbọala. Ma nke a mode dịkwa uru dị ka ngwá ọrụ maka izugbe iche, ụkpụrụ nke yiri ọrụ nke mebere igwe. Ọnọdụ a na-enye ikewapụ karịa Docker, mana ihe na-erughị igwe mebere zuru oke dị ka KVM ma ọ bụ igbe mebere.

N'ozuzu, ọnọdụ onye ọrụ nwere ike ịdị ka ngwa ngwa dị egwu na nke siri ike iji, mana ọ nwere ojiji ya. E kwuwerị, nke a bụ kernel Linux zuru oke na-agba ọsọ dị ka onye ọrụ na-enweghị ohere. Njirimara a na-enye ohere ka koodu enweghị ntụkwasị obi na-agba ọsọ n'enweghị ihe iyi egwu na igwe nnabata. Ma ebe ọ bụ na nke a bụ kernel zuru oke, usoro ya dịpụrụ adịpụ na igwe nnabata, ya bụ Usoro na-agba ọsọ n'ime ọnọdụ onye ọrụ agaghị ahụ onye ọbịa ahụ. Nke a adịghị ka akpa Docker ọdịnala, nke igwe nnabata na-ahụ mgbe niile usoro n'ime nchekwa ahụ. Lee mpempe pstree a sitere na otu sava m:

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

Ma tụnyere nke a na pstree nke Linux kernel na ọnọdụ onye ọrụ:

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

Mgbe ị na-arụ ọrụ na igbe Docker, enwere m ike ịhụ site na onye ọbịa aha nke usoro na-agba ọsọ na onye ọbịa. Nke a agaghị ekwe omume na ọnọdụ onye ọrụ Linux. Kedu ihe ọ pụtara? Nke a pụtara na ngwaọrụ nleba anya na-aga site na sistemụ nyocha nke Linux ahụla usoro na-agba ọsọ na usoro ndị ọbịa. Mana n'ọnọdụ ụfọdụ njirimara a nwere ike ịbụ mma agha ihu abụọ.

N'ozuzu, post dum dị n'okpuru bụ nchịkọta nyocha na mgbalị siri ike iji nweta nsonaazụ achọrọ. Iji mee nke a, aghaghị m iji ngwá ọrụ oge ochie dị iche iche, gụọ isi mmalite kernel, na-etinye aka na nbibi nke koodu edere mgbe m ka nọ n'ụlọ akwụkwọ elementrị, nakwa tinker na Heroku na-ewu site na iji ọnụọgụ abụọ pụrụ iche na-achọ ngwá ọrụ m chọrọ. Ọrụ a niile mere ka ụmụ okorobịa nọ na IRC m na-akpọ m onye dibịa afa. Enwere m olileanya na post a ga-abụ akwụkwọ a pụrụ ịdabere na ya maka mmadụ ime otu ihe ahụ, mana na kernels na ụdị OS ọhụrụ.

ukpụhọde

Ịtọlite ​​​​ụdị onye ọrụ Linux gụnyere ọtụtụ usoro:

  • wụnye ịdabere na onye ọbịa;
  • nbudata Linux kernel;
  • nhazi nhazi kernel;
  • mgbakọ kernel;
  • wụnye ọnụọgụ abụọ;
  • ịtọlite ​​​​usoro faịlụ ndị ọbịa;
  • nhọrọ nke kernel launch parameters;
  • ịtọlite ​​​​netwọọdụ ndị ọbịa;
  • ịmalite kernel ọbịa.

Echere m na ọ bụrụ na ị kpebie ime ihe a niile n'onwe gị, o yikarịrị ka ị ga-eme ihe niile akọwara na ụfọdụ Ubuntu ma ọ bụ Debian-dị ka usoro. Agbalịrị m itinye ihe niile dị n'elu na nkesa ọkacha mmasị m - Alpine, mana ọ nweghị ihe na-arụ ọrụ, o doro anya na Linux kernel jikọtara ya na glibc-isms maka ndị ọkwọ ụgbọ ala na ọnọdụ onye ọrụ. M na-eme atụmatụ ịkọ nke a n'elu elu ka m mechara chọpụta nsogbu ahụ.

Ịwụnye dabere na onye ọbịa

Ubuntu chọrọ opekata mpe ngwugwu ndị a iji wuo kernel Linux (na-eche na ọ dị ọcha):

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

Ị nwere ike iwunye ha site na iji iwu na-esonụ (dị ka mgbọrọgwụ ma ọ bụ iji sudo):

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

Biko mara na ịme mmemme nhazi menu maka kernel Linux ga-achọ nrụnye libncurses-dev. Biko hụ na etinyere ya site na iji iwu a (dị ka mgbọrọgwụ ma ọ bụ iji sudo):

apt-get -y install libncurses-dev

Nbudata kernel

Kpebie ebe ị ga-ebudata wee wuo kernel. Ị ga-ekenye ihe dịka 1,3 GB nke ohere draịvụ ike maka ọrụ a, yabụ jide n'aka na ị nwere ya.

Mgbe ahụ gaa na kernel.org wee nweta URL ka ibudata ụdị kernel kwụsiri ike kachasị ọhụrụ. N'oge ị na-ede post a: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.16.tar.xz

Jiri ya budata faịlụ a 'wget':

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

Wepụta ya na 'tar':

tar xJf linux-5.1.16.tar.xz

Ugbu a, anyị na-abanye akwụkwọ ndekọ aha emepụtara mgbe ị na-ebupu tarball:

cd linux-5.1.16

Ịtọlite ​​ihe nrụpụta kernel

Sistemụ nrụpụta kernel bụ set Mepụta faịlụ с ọtụtụ ngwá ọrụ omenala na edemede iji megharịa usoro ahụ. Iji malite, mepee mmemme ntọlite ​​​​n'ịntanetị:

make ARCH=um menuconfig

Ọ ga-emecha mgbakọ ahụ n'otu akụkụ wee gosi gị igbe mkparịta ụka. Mgbe ìhè pụtara na ala nke windo[Select]', ị nwere ike hazie ntọala site na iji Spacebar ma ọ bụ Tinye igodo. Ịchọgharị gburugburu mpio dị ka ọ na-adị na-eji akụ ahụ igodo “elu” na “ala”, na ịhọrọ ihe bụ “aka ekpe” ma ọ bụ “nri”.

Ihe nleba anya -> pụtara na ịnọ na nhọpụta nke obere nhọrọ, nke enwere ike ịnweta site na iji igodo Tinye. O doro anya na ụzọ ọpụpụ si '[Exit]'.

Tinye nhọrọ ndị a na '[Select]' ma hụ na e nwere akara ''[*]' n'akụkụ ha:

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

Nke ahụ bụ ya, ị nwere ike ịpụ na mpio a site n'ịhọrọ usoro n'usoro.[Exit]'. Naanị jide n'aka na na njedebe a kpaliri gị ịchekwa nhazi ahụ wee họrọ '[Yes]'.

Ana m akwado ka ị jiri nhọrọ nrụpụta kernel gwuo egwu mgbe ị gụsịrị akwụkwọ a. Site na nnwale ndị a, ị ga-amụta ọtụtụ ihe gbasara ka arụ ọrụ kernel dị ala si arụ ọrụ yana etu ọkọlọtọ dị iche iche si emetụta ka esi arụ kernel.

Iwuli kernel

Linux kernel bụ nnukwu mmemme na-eme ọtụtụ ihe. Ọbụlagodi na nhazi a pere mpe na ngwaike ochie, mgbakọ nwere ike were obere oge. Ya mere wuo kernel site na iji iwu a:

make ARCH=um -j$(nproc)

Maka gịnị? Iwu a ga-agwa onye nrụpụta anyị ka o jiri cores na eri CPU niile dị n'oge a na-arụ ọrụ. Otu $(nproc) na njedebe nke Mee tinye mmepụta nke iwu ahụ nproc, nke bụ akụkụ coreutils na ọkọlọtọ Ubuntu wuru.

Mgbe oge ụfọdụ gachara, a ga-achịkọta kernel anyị n'ime faịlụ enwere ike ime ya ./linux.

Ịwụnye ọnụọgụ abụọ

Ebe ọ bụ na ọnọdụ onye ọrụ na Linux na-emepụta ọnụọgụ abụọ mgbe niile, ị nwere ike ịwụnye ya dị ka ihe ọ bụla ọzọ. Nke a bụ ka m mere ya:

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

Ọ dịkwa mma ijide n'aka na ~/bin dị n'ime gị $PATH:

export PATH=$PATH:$HOME/bin

Na-ahazi Sistemụ Njikwa Ọbịa

Mepụta ndekọ maka sistemụ faịlụ ndị ọbịa:

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

Mepee alpinelinux.org wee banye ngalaba download chọta njikọ nbudata ugbu a MINI ROOT FILESYSTEM. N'oge edere nke a bụ:

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

Budata tarball a site na iji 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

Ugbu a tinye ndekọ sistemụ faịlụ ndị ọbịa wee bupụ ebe nchekwa ahụ:

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

Nzọụkwụ ndị a kọwara ga-emepụta obere template usoro faịlụ. N'ihi otu usoro ahụ si arụ ọrụ, ịwụnye ngwugwu site na njikwa ngwa Alpine ga-esi ezigbo ike. Mana FS a ga-ezuru iji nyochaa echiche izugbe.

Anyị chọkwara ngwá ọrụ tini ịkwụsị oriri ebe nchekwa usoro zombie onye ọbịa anyị kernel.

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

Ịmepụta ahịrị iwu kernel

Linux kernel, dị ka ọtụtụ mmemme ndị ọzọ, nwere arụmụka ahịrị iwu nke enwere ike ịnweta site na ịkọwa igodo --help.

Onwe ya - enyemaka

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.

Ogwe a na-egosipụta parampat mmalite mmalite. Ka anyị jiri nhọrọ kacha nta achọrọ mee kernel:

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

Ahịrị ndị dị n'elu na-agwa kernel anyị ihe ndị a:

  • Ka anyị were na sistemụ faịlụ mgbọrọgwụ bụ ngwaọrụ pseudo /dev/root.
  • Họrọ ndị ọbịa dị ka onye na-anya usoro faịlụ mgbọrọgwụ.
  • Wụnye sistemụ faịlụ ndị ọbịa anyị mepụtara na ngwaọrụ mgbọrọgwụ.
  • Ma ee, n'ụdị agụ-ede.
  • Jiri naanị 64 megabytes nke RAM (ị nwere ike iji obere ihe dabere na ihe ị na-eme atụmatụ ime, mana 64 MB yiri ka ọ bụ ego kacha mma).
  • Mkpụrụ ndụ na-amalite na-akpaghị aka /bin/sh otú init-usoro.

Gbaa iwu a ma ị ga-enweta ihe dịka ndị a:

Mpempe akwụkwọ ọzọ

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

Nghọta ndị dị n'elu ga-enye anyị obere usoro ọbịa, na-enweghị ihe ndị dị ka /proc ma ọ bụ aha nnabata ekenyere. Dịka ọmụmaatụ, nwaa iwu ndị a:

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

Iji pụọ na sistemụ ndị ọbịa, tinye exit ma ọ bụ pịa control-d. Nke a ga-eme ka shei ahụ gbaa egwu kernel sochiri ya:

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

Anyị nwetara ụjọ kernel a n'ihi na Linux kernel na-eche na usoro mmalite na-agba ọsọ mgbe niile. Na-enweghị ya, usoro ahụ agaghịzi arụ ọrụ ma mechie. Mana ebe nke a bụ usoro ọnọdụ onye ọrụ, nsonaazụ ya na-ezigara onwe ya SIGABRT, nke na-eduga na ọpụpụ.

Ịtọlite ​​​​netwọọdụ ndị ọbịa

Ma nke a bụ ebe ihe na-amalite na-adịghị mma nye anyị. ịkparịta ụka n'Ịntanet n'ụdị onye ọrụ Linux bụ ebe echiche niile nke oke "ọnọdụ onye ọrụ" na-amalite dawa. A sị ka e kwuwe, netwọk na-ejikarị na ọkwa usoro ihe ùgwù ụdị igbu egbu maka ihe doro anya kpatara anyị niile.

Rịba ama per.: Ị nwere ike ịgụtakwuo maka nhọrọ dị iche iche maka ịrụ ọrụ na netwọk na UML ebe a.

Njem na-amị amị

Agbanyeghị, enwere ngwa ochie na nke anaghị akwado ya Ntupu, nke Onye ọrụ Linux nwere ike imekọrịta na netwọkụ. Ọ na-arụ ọrụ dịka ọkwa ọkwa TCP/IP na-achọghị ikike sistemụ ọ bụla iji na-agba ọsọ. Ngwá ọrụ a bụ ewepụtara na 1995, na mmelite ikpeazụ bụ ụbọchị 2006. Slirp adịla agadi. N'oge na-enweghị nkwado na mmelite, compilers abịarute ugbu a na ngwá ọrụ a nwere ike ịkọwa dị ka "Code ire ere".

Yabụ, ka anyị budata Slirp site na ebe nchekwa Ubuntu wee gbalịa mee ya:

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)

Chi m. Ka anyị wụnye Slirp debugger wee hụ ma anyị nwere ike ịchọpụta ihe na-eme ebe a:

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.

Njehie ahụ na-eti anyị ihe ahịrị a. Ka anyị leba anya na stacktrace, ikekwe ọ nwere ihe ga-enyere anyị aka ebe ahụ:

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

N'ebe a, anyị na-ahụ na okuku na-eme n'oge mmalite nke isi loop, mgbe slirp na-agbalị ịlele oge nkwụsị. Ọ bụ n'oge a ka m ga-akwụsị ịgbalị imezi ihe. Ma ka anyị hụ ma Slirp, nke e wuru site na ụdị, ọ na-arụ ọrụ. Ebudataghachiri m ebe nchekwa ahụ ozugbo na saịtị ahụ Isi mmalite, n'ihi na ịdọrọ ihe site n'ebe ahụ site na akara iwu bụ ihe mgbu:

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

N'ebe a, anyị na-ahụ ọkwa banyere ọrụ arụnyere na-akọwaghị ya, ya bụ, banyere enweghị ike ijikọ faịlụ ọnụọgụ abụọ na-esi na ya pụta. Ọ dị ka n'etiti 2006 na ugbu a gcc kwụsịrị imepụta akara ejiri rụọ ọrụ etiti. Ka anyị gbalịa dochie isiokwu inline n'okwu efu wee lelee nsonaazụ ya:

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

Mba. Nke a anaghịkwa arụ ọrụ. Enweghị ike ịhụ akara maka ọrụ ndị a.

N'oge a a kwụsịrị m wee malite ịchọ Github Heroku wu ngwugwu. Echiche m bụ na ụfọdụ ngwugwu Heroku ga-enwe ọnụọgụ abụọ m chọrọ. N'ikpeazụ, ọchụchọ m dugara m ebe a. M budata wee bupụ ya uml.tar.gz wee hụ ihe ndị a:

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*

Nke a bụ ọnụọgụ abụọ slirp! Ọ na-arụ ọrụ?

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

Ọ naghị ada - ya mere ọ kwesịrị ịrụ ọrụ! Ka anyị kụọ ọnụọgụ abụọ a n'ime ~/bin/slirp:

cp slirp ~/bin/slirp

Ọ bụrụ na onye mepụtara ngwugwu ahụ wepụrụ ya, I mere mirror.

Mbido network

Ugbu a, ka anyị hazie netwọk na isi ndị ọbịa anyị. Ka anyị melite parameters mmalite:

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

Ugbu a, ka anyị mee ka netwọk ahụ nwee ike:

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

Iwu nhazi abụọ mbụ /proc и /sys dị mkpa maka ọrụ ifconfig, nke na-edozi interface netwọk iji kparịta ụka na Slirp. Otu route na-edobe tebụl ntụgharị kernel iji mee ka okporo ụzọ niile ziga site na ọwara Slirp. Ka anyị jiri ajụjụ DNS lelee nke a:

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

Ọ na-arụ ọrụ!

Rịba ama per.: O doro anya na edere akwụkwọ ozi mbụ na desktọpụ nwere kaadị netwọk wired, ma ọ bụ nhazi ọzọ nke na-achọghị ndị ọkwọ ụgbọala ọzọ. Na laptọọpụ nwere WiFi 8265 sitere na Intel, njehie na-eme mgbe ị na-ebuli netwọk ahụ

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

N'ụzọ doro anya, kernel enweghị ike ikwurịta okwu na ọkwọ ụgbọala netwọk. Mgbalị ịchịkọta firmware n'ime kernel, ọ dị mwute ikwu, emezighị ọnọdụ ahụ. N'oge mbipụta, ọnweghị ihe ngwọta enweghị ike ịchọta na nhazi a. Na nhazi dị mfe (dịka ọmụmaatụ, na Virtualbox), a na-ebuli interface ahụ nke ọma.

Ka anyị were edemede shei na-esote megharịa ntụgharị ahụ:

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

Ma kaa ya ka ọ bụrụ nke enwere ike ime ya:

chmod +x init.sh

Ma ka anyị mee mgbanwe na ahịrị iwu kernel:

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

Ka anyị kwugharịa:

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

Netwọk kwụsiri ike!

docker faịlụ

Iji mee ka ọ dịrị gị mfe ịlele ihe a niile, anakọtara m dockerfile, nke na-eme ka ọtụtụ n'ime usoro ndị akọwapụtara ma kwesị inye gị nhazi nhazi. Enwekwara m nhazi kernel dị njikere, nke nwere ihe niile akọwara na post. Mana ọ dị mkpa ịghọta na ebe a akọwapụtala m naanị ntọala kacha nta.

Enwere m olileanya na ọkwa a nyeere gị aka ịghọta otu esi ewelite kernel ọbịa. Ọ tụgharịrị bụrụ ụdị anụ ọhịa ụfọdụ, mana e bu n'obi bipụta ya ka ọ bụrụ ntụzịaka zuru oke na isiokwu gbasara mkpokọta, ịwụnye na ịhazi ọnọdụ onye ọrụ na Linux n'okpuru ụdị sistemụ arụmọrụ nke ezinụlọ a nke oge a. Usoro ndị na-esote kwesịrị ịgụnye ịwụnye ọrụ na ngwanrọ ndị ọzọ ugbua n'ime usoro ndị ọbịa. Ebe ọ bụ na ihe onyonyo Docker na-akwalite naanị tarballs, ị ga-enwe ike wepụta onyonyo a site na docker export, wee chọpụta ụzọ ị ga-esi tinye ya na mgbọrọgwụ nke sistemụ faịlụ kernel ọbịa. Ọfọn, wee mee ihe odide shei.

Ekele pụrụ iche nye Rkeene sitere na #lobsters na Freenode. Na-enweghị enyemaka ya n'imebi Slirp, agaraghị m erute ebe a. Amaghị m ka usoro Slackware ya si arụ ọrụ nke ọma na slirp, mana sistemụ Ubuntu na Alpine anabataghị slirp na ọnụọgụ abụọ Rkene tụrụ aro m. Ma o zuru m na ọ dịkarịa ala ihe na-arụ ọrụ maka m.

isi: www.habr.com

Tinye a comment