Ahoana no hanombohana mampiasa fomba mpampiasa amin'ny Linux
Fampidirana avy amin'ny mpandika teny: Manoloana ny fidiran'ny karazana kaontenera isan-karazany eo amin'ny fiainantsika, dia mety ho tena mahaliana sy mahasoa ny mahafantatra ny teknolojia natomboka taloha. Ny sasany amin'izy ireo dia azo ampiasaina tsara mandraka androany, saingy tsy ny rehetra no mahatsiaro ny fomba toy izany (na mahafantatra, raha tsy tratra nandritra ny fivoarany haingana). Iray amin'izany ny teknolojia User Mode Linux. Ny mpanoratra ny tany am-boalohany dia nanao fandavahana ara-drariny, mamantatra hoe iza amin'ireo fivoarana taloha no mbola miasa ary iza no tsy mandeha, ary nanangona zavatra toy ny toromarika tsikelikely momba ny fomba hamoronana UML ho an'ny tenanao ao an-trano. 2k19. Ary eny, nanasa ny mpanoratra ny lahatsoratra tany am-boalohany ho any Habr Cadey, koa raha manana fanontaniana ianao dia manontania amin'ny teny anglisy ao amin'ny fanehoan-kevitra.
User Mode amin'ny Linux dia, raha ny marina, seranan-tsambo ny Linux kernel ho azy. Ity fomba ity dia ahafahanao mampandeha kernel Linux feno ho toy ny fizotry ny mpampiasa ary matetika ampiasain'ny mpamorona hitsapana mpamily. Fa ity fomba ity koa dia ilaina ho toy ny fitaovana ho an'ny fitokana-monina ankapobeny, ny fitsipiky ny izay mitovy amin'ny fiasan'ny milina virtoaly. Ity fomba ity dia manome fitokana-monina bebe kokoa noho ny Docker, fa latsaky ny milina virtoaly feno toa ny KVM na Virtual Box.
Amin'ny ankapobeny, ny User Mode dia mety ho toy ny fitaovana hafahafa sy sarotra ampiasaina, saingy misy ny fampiasana azy. Raha ny marina, ity dia kernel Linux feno izay miasa ho mpampiasa tsy manana tombontsoa. Ity endri-javatra ity dia ahafahan'ny kaody tsy azo itokisana mandeha tsy misy fandrahonana ny milina mpampiantrano. Ary satria kernel feno io, ny fizotrany dia mitoka-monina amin'ny milina mpampiantrano, izany hoe Ny dingana mandeha ao anatin'ny User Mode dia tsy ho hitan'ny mpampiantrano. Tsy toy ny container Docker nentim-paharazana izany, izay ahitan'ny milina mpampiantrano foana ny fizotran'ny fitahirizana. Jereo ity pstree ity avy amin'ny iray amin'ireo mpizarako:
Ary ampitahao amin'ny pstree an'ny kernel Linux amin'ny User Mode:
linux─┬─5*[linux]
└─slirp
Rehefa miasa miaraka amin'ny container Docker aho dia hitako avy amin'ny mpampiantrano ny anaran'ireo dingana izay mandeha ao amin'ny vahiny. Tsy azo atao izany amin'ny Linux User Mode. Inona no dikan'izany? Midika izany fa fitaovana fanaraha-maso mandeha amin'ny subsystem fanaraha-maso an'ny Linux tsy mahita dingana mandeha ao amin'ny rafitra vahiny. Saingy amin'ny toe-javatra sasany dia mety ho sabatra roa lela io endri-javatra io.
Amin'ny ankapobeny, ny lahatsoratra manontolo eto ambany dia fitambarana fikarohana sy fiezahana mafy mba hahazoana ny vokatra tadiavina. Mba hanaovana izany dia tsy maintsy nampiasa fitaovana tranainy isan-karazany aho, namaky loharano kernel, nanao debugging mahery vaika tamin'ny kaody nosoratana fony aho mbola tany amin'ny sekoly ambaratonga fototra, ary koa nitsambikina tamin'ny fananganana Heroku mampiasa binary manokana amin'ny fitadiavana ireo fitaovana ilaiko. Izany asa rehetra izany dia nahatonga ireo lehilahy tao amin'ny IRC niantso ahy ho mpanao ody. Manantena aho fa ity lahatsoratra ity dia ho toy ny antontan-taratasy azo antoka ho an'ny olona iray hanao zavatra mitovy amin'izany, fa miaraka amin'ny kernel vaovao sy dikan-teny OS.
fanitsiana
Ny fametrahana Linux User Mode dia misy dingana maromaro:
fametrahana miankina amin'ny mpampiantrano;
misintona ny kernel Linux;
fananganana kernel;
fanangonana kernel;
fametrahana ny binary;
fametrahana ny rafitra rakitra vahiny;
fifantenana ny masontsivana fandefasana kernel;
fametrahana tambajotra vahiny;
manomboka ny kernel vahiny.
Heveriko fa raha manapa-kevitra ny hanao izany rehetra izany ianao, dia azo inoana fa hanao izay rehetra voalaza ao amin'ny rafitra sasany Ubuntu na Debian ianao. Niezaka nampihatra ireo rehetra voalaza etsy ambony ireo aho tamin'ny fizarana tiako indrindra - Alpine, saingy tsy nisy nahomby, toa satria ny kernel Linux dia mifamatotra mafy amin'ny glibc-isms ho an'ny mpamily amin'ny User Mode. Mikasa ny hitatitra izany any amin'ny faritra ambony aho rehefa avy nahita ny olana.
Fametrahana miankina amin'ny mpampiantrano
Ny Ubuntu dia mitaky farafaharatsiny ireto fonosana manaraka ireto mba hananganana ny kernel Linux (mihevitra ny fametrahana madio):
Mariho fa ny fampandehanana ny programa fanamboarana sakafo ho an'ny kernel Linux dia mitaky fametrahana libncurses-dev. Azafady, ataovy azo antoka fa apetraka amin'ny fampiasana ity baiko manaraka ity (ho root na mampiasa sudo):
apt-get -y install libncurses-dev
Misintona ny kernel
Farito ny toerana hisintonana ary amboary ny kernel. Mila manokana 1,3 GB amin'ny habaka kapila mafy ianao ho an'ity asa ity, koa ataovy izay hahazoanao izany.
Ankehitriny dia miditra amin'ny lahatahiry noforonina isika rehefa mamoaka ny tarball:
cd linux-5.1.16
Mametraka fananganana kernel
Ny rafitra fananganana kernel dia napetraka Manaova rakitra с MARO fitaovana manokana sy sora-baventy hanamarihana ny fizotrany. Hanombohana, sokafy ny programa fananganana an-tserasera:
make ARCH=um menuconfig
Hamita amin'ny ampahany ny fivoriambe izy io ary hampiseho boaty fifampiresahana ho anao. Rehefa miseho eo amin'ny faran'ny varavarankely ny hazavana[Select]', azonao atao ny manamboatra ny fika amin'ny alàlan'ny Spacebar na Enter. Ny fitetezana manodidina ny varavarankely dia toy ny mahazatra amin'ny fampiasana ny zana-tsipìka fitendry "miakatra" sy "midina", ary ny fisafidianana singa dia "ankavia" na "ankavanana".
Ny famantarana ny fijerena -> dia midika fa ao anaty submenu ianao, izay azo idirana amin'ny fampiasana ny fanalahidy Enter. Mazava ho azy fa amin'ny alalan'ny '[Exit]'.
Ampidiro ao amin'ny '[Select]' ary ataovy azo antoka fa misy marika '[*]' eo akaikin'izy ireo:
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
Izay ihany, azonao atao ny miala amin'ity varavarankely ity amin'ny fisafidianana ny '[Exit]'. Ataovy azo antoka fa amin'ny farany dia asaina mitahiry ny fanamafisana ianao ary safidio '[Yes]'.
Manoro hevitra anao aho hilalao miaraka amin'ireo safidy fananganana kernel rehefa avy mamaky ity lahatsoratra ity. Avy amin'ireo andrana ireo dia afaka mianatra betsaka momba ny fomba fiasan'ny mekanika kernel ambany sy ny fiantraikan'ny saina samihafa amin'ny fananganana ny kernel ianao.
Manorina ny kernel
Ny kernel Linux dia programa lehibe izay manao zavatra maro. Na dia amin'ity fanamafisana kely indrindra amin'ny fitaovana tranainy ity aza, dia mety haharitra ela ny fivoriambe. Noho izany dia manangana kernel amin'ny fampiasana ity baiko manaraka ity:
make ARCH=um -j$(nproc)
Hatao inona? Ity baiko ity dia hilaza amin'ny mpanamboatra anay mba hampiasa ireo cores sy kofehy CPU rehetra misy mandritra ny dingana fananganana. Ekipa $(nproc) eo amin'ny faran'ny Build dia mampiditra ny fivoahan'ny baiko nproc, izay ampahany coreutils ao amin'ny fananganana Ubuntu mahazatra.
Rehefa afaka kelikely, ny kernel dia hatambatra ho rakitra azo tanterahana ./linux.
Fametrahana ny binary
Satria ny User Mode amin'ny Linux dia mamorona binary mahazatra, azonao atao ny mametraka azy toy ny fitaovana hafa rehetra. Toy izao no nataoko:
mkdir -p ~/bin
cp linux ~/bin/linux
Mendrika koa ny hahazoana antoka izany ~/bin dia ao anatinao $PATH:
export PATH=$PATH:$HOME/bin
Fametrahana ny Rafitra fichier Guest
Mamorona lahatahiry ho an'ny rafi-drakitra vahiny:
mkdir -p $HOME/prefix/uml-demo
cd $HOME/prefix
Sokafy ny alpinelinux.org ary miditra fizarana download tadiavo ny rohy fampidinana ankehitriny MINI ROOT FILESYSTEM. Tamin'ny fotoana nanoratana dia:
Ampidiro izao ny lahatahiry rafitra rakitra vahiny ary esory ny rakitra:
cd uml-demo
tar xf ../alpine-rootfs.tgz
Ny dingana voalaza dia hamorona môdely rafitra fichier kely. Noho ny fomba fiasan'ny rafitra dia ho sarotra be ny fametrahana fonosana amin'ny alàlan'ny mpitantana Alpine apk. Saingy ity FS ity dia ho ampy hanombanana ny hevitra ankapobeny.
Mila fitaovana koa isika tini hampitsahatra ny fanjifana fahatsiarovana dingana zombie kernel vahiny.
wget -O tini https://github.com/krallin/tini/releases/download/v0.18.0/tini-static
chmod +x tini
Mamorona Kernel Command Line
Ny kernel Linux, toy ny ankamaroan'ny programa hafa, dia manana tohan-kevitry ny baiko izay azo idirana amin'ny famaritana ny fanalahidy --help.
Ny tenany — fanampiana
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.
Ity tontonana ity dia manasongadina ireo mari-pamantarana fanombohana lehibe. Andeha hojerentsika ny kernel miaraka amin'ireo safidy kely indrindra ilaina:
linux
root=/dev/root
rootfstype=hostfs
rootflags=$HOME/prefix/uml-demo
rw
mem=64M
init=/bin/sh
Ireo andalana etsy ambony dia milaza izao manaraka izao ny kernel:
Andeha hatao hoe fitaovana pseudo ny rafitra fichier root /dev/root.
Mifidiana hostfs amin'ny maha mpamily rafitra fichier root.
Apetaho amin'ny fitaovana fakany ny rafitra fichier vahiny noforoninay.
Ary eny, amin'ny fomba mamaky-manoratra.
Mampiasà RAM 64 megabytes ihany (afaka mampiasa kely kokoa ianao arakaraka ny zavatra kasainao hatao, fa ny 64 MB no tena mety indrindra).
Manomboka ho azy ny kernel /bin/sh Ahoana no init- dingana.
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
/ #
Ireo manipulations etsy ambony dia hanome antsika rafitra vahiny kely indrindra, tsy misy zavatra toy izany /proc na nomena anarana mpampiantrano. Ohatra, andramo ireto baiko manaraka ireto:
- uname -av
- cat /proc/self/pid
- hostname
Raha hivoaka ny rafitra vahiny dia midira exit na fanaovan-gazety mifehy-d. Izany dia handrehitra ny akorandriaka arahin'ny kernel panic:
/ # exit
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000
fish: “./linux root=/dev/root rootflag…” terminated by signal SIGABRT (Abort)
Nahazo an'ity kernel ity izahay satria ny kernel Linux dia mihevitra fa mandeha foana ny dingana fanombohana. Raha tsy misy izany dia tsy afaka miasa intsony ny rafitra ary mihidy. Saingy satria fomba fizotry ny mpampiasa ity, ny vokatra azo dia alefa any SIGABRT, izay mitondra mankany amin'ny fivoahana.
Fametrahana tambajotra vahiny
Eo anefa no manomboka tsy mety amintsika. Tambajotra amin'ny User Mode Linux no manomboka ny foto-kevitra iray manontolo momba ny "mode mpampiasa" voafetra. Rehefa dinihina tokoa, ny tambajotra dia matetika voafetra amin'ny rafitra rafitra manana tombontsoa fomba famonoana noho ny antony mazava ho antsika rehetra.
Fanamarihana per .: Azonao atao ny mamaky bebe kokoa momba ny safidy samihafa amin'ny fiaraha-miasa amin'ny tambajotra amin'ny UML eto.
Dia slirp
Na izany aza, misy fitaovana tranainy sy saika tsy tohanana antsoina hoe Slirp, izay ahafahan'ny User Mode Linux mifandray amin'ny tambajotra. Miasa sahala amin'ny stack TCP/IP an'ny mpampiasa izy io ary tsy mitaky fahazoan-dàlana amin'ny rafitra. Ity fitaovana ity dia nivoaka tamin'ny 1995, ary misy daty ny fanavaozana farany 2006. Efa antitra be ny Slirp. Nandritra ny fotoana tsy nisy fanohanana sy fanavaozam-baovao dia tonga lavitra ireo mpanangom-bokatra ka izao fitaovana izao ihany no azo lazaina ho "code rot".
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)
Andriamanitro ô. Andao hametraka ny Slirp debugger ary hojerentsika raha afaka mamantatra ny zava-mitranga eto isika:
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.
Mamely antsika ny fahadisoana andalana ity. Andeha hojerentsika ny stacktrace, mety hisy hanampy antsika any:
(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.
Eto isika dia mahita fa ny fianjerana dia mitranga mandritra ny fanombohan'ny loop lehibe, rehefa manandrana manamarina ny fotoana fiafaran'ny fotoana ny slirp. Tamin'io fotoana io aho no tsy maintsy nilavo lefona tamin'ny fiezahana hanao debug. Fa andeha hojerentsika raha miasa ny Slirp, namboarina avy amin'ny karazana. Naveriko indray ilay arisiva mivantana avy amin'ilay tranokala sourceforge, satria fanaintainana ny fisintonana zavatra avy any amin'ny alàlan'ny baiko:
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
Eto isika dia mahita fampandrenesana momba ny fiasa naorina tsy voafaritra, izany hoe momba ny tsy fahafahana mampifandray ny rakitra binary vokatra. Hita fa teo anelanelan'ny taona 2006 ka hatramin'izao, ny gcc dia nijanona tamin'ny famoronana marika ampiasaina amin'ny asa mpanelanelana natsangana. Andeha isika hanolo ny teny fototra inline amin'ny fanehoan-kevitra poakaty ary jereo ny valiny:
vi slirp.h
:6
a
<enter>
#define inline /**/
<escape>
:wq
make
Tamin'io fotoana io dia nilavo lefona aho ary nanomboka nikaroka tao amin'ny Github Heroku manorina fonosana. Ny hevitro dia hoe misy fonosana fananganana Heroku sasany dia ahitana ny binary ilaiko. Tamin'ny farany dia nitarika ahy ny fikarohana nataoko eto mihitsy. Noraisiko sy novahako uml.tar.gz ary nahita ireto manaraka ireto:
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*
Ity dia slirp binary! Mety ve izany?
./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 ...
Fanamarihana isaky ny.: Toa nosoratana teo amin'ny birao misy karatra tambajotra misy tariby ny lahatsoratra tany am-boalohany, na fanitsiana hafa tsy mila mpamily fanampiny. Ao amin'ny solosaina misy WiFi 8265 avy amin'ny Intel, misy hadisoana mitranga rehefa manangana ny tambajotra
/ # 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
/ #
Toa tsy afaka mifandray amin'ny mpamily fiarandalamby ny kernel. Ny fikasana hanangona ny firmware ao amin'ny kernel, indrisy, tsy nanitsy ny toe-javatra. Tamin'ny fotoana namoahana azy dia tsy mbola nisy vahaolana hita tamin'ity fanamboarana manokana ity. Amin'ny configs tsotra kokoa (ohatra, ao amin'ny Virtualbox) dia atsangana tsara ny interface.
linux
root=/dev/root
rootfstype=hostfs
rootflags=$HOME/prefix/uml-demo
rw
mem=64M
eth0=slirp,,$HOME/bin/slirp
init=/init.sh
Ary andeha averina indray:
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
Marin-toerana ny tambazotra!
docker rakitra
Mba hanamora ny fanarahanao izany rehetra izany dia nanangona aho dockerfile, izay manao automatique ny ankamaroan'ny dingana voalaza ary tokony hanome anao ny fanefena miasa. Izaho koa manana vonona kernel configuration, izay ahitana ny zava-drehetra voalaza ao amin'ny lahatsoratra. Saingy zava-dehibe ny mahatakatra fa eto aho dia tsy nanasongadina afa-tsy ny toe-javatra faran'izay kely indrindra.
Manantena aho fa ity lahatsoratra ity dia nanampy anao hahatakatra ny fomba hananganana kernel vahiny. Nivadika ho karazana biby goavam-be izany, fa ny famoahana dia natao ho torolàlana feno momba ny lohahevitra momba ny fanangonana, ny fametrahana ary ny fanamafisana ny User Mode amin'ny Linux amin'ny dikan-teny maoderina amin'ny rafitra fiasan'ity fianakaviana ity. Ny dingana manaraka dia tokony ahitana ny fametrahana serivisy sy rindrambaiko hafa efa ao anatin'ny rafitra vahiny. Satria ny sarin'ny container Docker dia fampiroboroboana tarballs fotsiny, tokony ho azonao atao ny manala ny sary amin'ny alàlan'ny docker export, ary fantaro avy eo ny lalana hametrahana azy ao amin'ny fototry ny rafitra rakitra kernel vahiny. Eny ary, tanteraho ny script shell.
Misaotra manokana an'i Rkeene avy amin'ny #lobsters amin'ny Freenode. Raha tsy nisy ny fanampiany tamin'ny famahana ny Slirp dia tsy ho tonga amin'izany aho. Tsy fantatro ny fomba fiasan'ny rafitra Slackware amin'ny slirp, fa ny rafitra Ubuntu sy Alpine dia tsy nanaiky ny slirp ary nanoro ahy ny binary Rkeene. Saingy ampy ho ahy fa farafaharatsiny misy zavatra miasa amiko.