独自のOSをXenに移植する

数年前、Mat-Mehで、Emboxをクラウド向けの理想的なプラットフォームに変えようとする学生プロジェクトがありました。 このタスクの明らかな部分の1つは、一部の仮想化プラットフォームへの移植であり、選択はXenに委ねられました。 この記事では、学生OSをXenに移植し、Emboxに新しいプラットフォームを追加するプロセスと、もちろん、これらすべてが開始された理由について説明します。



理想的なクラウドプラットフォームのアイデアは次のとおりです。

unikernelの概念があります。 つまり、単一のアプリケーションの開発者は、作業に必要な機能のセットを選択します。 この機能のみがオペレーティングシステムに含まれており、アプリケーションと共に単一のイメージにリンクされています。 このアプローチにより、リソースが明らかに節約されます。 もちろん、これは多くの機能を持たない唯一のアプリケーションですが、クラウドに多くの異なるアプリケーション(本質的にはサービス)を配置すると、非常に幅広い機能を利用できます。



Xenへの移植



Xenヘルスチェック



何かを何かに移植するには、まず既存のソリューションを確認する必要があります。 Xenでは、かなりの数のオペレーティングシステムがすでに動作しています。 もちろん、私たちは主にオープンLinuxに興味を持っています。 Xenには1つの特徴があります。何かを始める前に、まずこのプラットフォームのインスタンスを作成して管理する方法を学ぶ必要があります。 つまり、個別の仮想マシン(ドメイン)を作成する方法を学ぶ必要があります。



Xenを使用するには、適切なパッケージをインストールする必要があります。



sudo apt-get install xen-hypervisor-4.8-amd64 xen-tools
      
      





その後、再起動して、起動時にXen上のOSのバージョンを選択する必要があります(通常はデフォルトです)。



ハイパーバイザーの制御下にあることを確認するには、コマンドcat /proc/cpuinfo | grep hypervisor



出力を確認するだけで十分ですcat /proc/cpuinfo | grep hypervisor



cat /proc/cpuinfo | grep hypervisor



空でcat /proc/cpuinfo | grep hypervisor



ません。 同様に、 virt-what



コマンドの出力を確認できます。xen-dom0が含まれている必要があります



もう1つのテストオプションは、「xl」コマンドを使用することです。これは将来必要になります。



sudo xl list



コマンドは、次のようなものを出力するはずです。



 Name ID Mem VCPUs State Time(s) Domain-0 0 945 1 r----- 11.3
      
      





ドメイン管理



Xenには、仮想マシンを作成および管理する方法がいくつかあります。

1つ目は、サードパーティプログラム(virt-managerやoVirtなど)を使用したインストールです。 通常、それらはグラフィカルインターフェースを備えており、プログラム自体がシステムファイルを「掘り下げ」、必要な変更を加えます。



2番目の方法は、コンソールで作業することです。



Linux仮想化の場合、xen-tools + xl(またはxm)を使用します。 多くのLinuxディストリビューションは準仮想化の準備がすでに整っているため、これは便利です。



新しい仮想マシンの作成に使用されるパラメーターは/etc/xen-tools/xen-tools.conf



ファイルにあり、再定義できます。 マシンを作成するときに、すべてのパラメーターをオーバーライドすることもできます。



ネットワーク環境のセットアップ



ドメイン間のネットワークにはいくつかの方法があります。 最も簡単なものを選択します-ブリッジネットワーク(仮想マシンは、dom0と共に物理デバイスとしてローカルネットワーク上に表示されます)。



パッケージをインストールします。



 sudo apt-get install bridge-utils
      
      





次に、ファイル/etc/network/interfaces



編集します

だった



 # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug enp5s0 iface enp5s0 inet dhcp
      
      





になっています



 # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug enp5s0 iface enp5s0 inet manual auto xenbr0 iface xenbr0 inet dhcp bridge_ports enp5s0
      
      







仮想マシンのイメージを作成します。



Ubuntuで仮想マシンを作成する例:



 sudo xen-create-image --hostname test --dhcp --pygrub --dist precise --mirror="http://mirror.yandex.ru/ubuntu" --dir /srv/xen/test
      
      





--pygrub



フラグは、PyGrubローダーが仮想マシンで使用されることを示し、各仮想マシンがdom0のコアの代わりに独自のカーネルを使用できるようにします。 --dir



パラメーターは、以前にパーティション分割されたディスクの個別のセクションではなく、イメージにディレクトリを使用することを指定します。



出力はおよそ次のとおりです。
一般的な情報

-ホスト名:テスト

分布:正確な

ミラー: mirror.yandex.ru/ubuntu

パーティション:512Mのスワップ(スワップ)

/ 4G(ext4)

画像タイプ:スパース

メモリサイズ:256M

ブートローダー:pygrub



ネットワーク情報

-IPアドレス:DHCP [MAC:00:16:3E:8E:3C:E0]



パーティションイメージの作成:/srv/xen/test/domains/test/swap.img

完了



/srv/xen/test/domains/test/swap.imgでスワップを作成する

完了



パーティションイメージの作成:/srv/xen/test/domains/test/disk.img

完了



/srv/xen/test/domains/test/disk.imgにext4ファイルシステムを作成する

完了

インストール方法:debootstrap

完了



ランニングフック

完了



ロールスクリプトが指定されていません。 スキップしています



Xen構成ファイルの作成

完了



ロールスクリプトが指定されていません。 スキップしています

ルートパスワードの設定

新しいゲストのパスワードを生成します。

すべて完了



生成されるログファイル:

/var/log/xen-tools/test.log



インストールの概要

-ホスト名:テスト

分布:正確な

MACアドレス:00:16:3E:8E:3C:E0

IPアドレス(es):動的

SSHフィンガープリント:SHA256:H49PEnPv0k0tw2faq1CStkR6KFlHF0GkUOWvYaeiqOU(DSA)

SSHフィンガープリント:SHA256:5gIsrTAriqEiwdkVCygOtLOi9uOd2DJWFBlJKxdJfUw(ECDSA)

SSHフィンガープリント:SHA256:SB + bTbkIUr2Qn019xT8AFtAKO5f6xlkbt8juVBq6zTE(RSA)

ルートパスワード:RJpaLfBFseH9YJX77ScxRwP



次のコマンドを使用して、イメージが作成されたことを確認できます。



 sudo xen-list-images
      
      





私の場合、発行されたコマンド



 Name: test Memory: 256 MB Config: /etc/xen/test.cfg
      
      





起動(マシン作成)



 sudo xl create /etc/xen/test.cfg
      
      





「sudo xl list」コマンドが呼び出されると、テスト仮想マシンが表示されます。



 Name ID Mem VCPUs State Time(s) Domain-0 0 15356 8 r----- 4283.8 test 2 256 1 -b---- 1.5
      
      





彼女のコンソールに接続する必要があります:



 sudo xl console test
      
      





仮想マシンコンソールは、 "ctrl + ]"



組み合わせで終了します



結果の結論
 [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Linux version 3.2.0-126-virtual (buildd@lcy01-11) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #169-Ubuntu SMP Fri Mar 31 14:47:56 UTC 2017 (Ubuntu 3.2.0-126.169-virtual 3.2.79) [ 0.000000] Command line: root=/dev/xvda2 ro elevator=noop root=/dev/xvda2 ro [ 0.000000] KERNEL supported cpus: [ 0.000000] Intel GenuineIntel [ 0.000000] AMD AuthenticAMD [ 0.000000] Centaur CentaurHauls [ 0.000000] ACPI in unprivileged domain disabled [ 0.000000] Released 0 pages of unused memory [ 0.000000] Set 0 page(s) to 1-1 mapping [ 0.000000] BIOS-provided physical RAM map: [ 0.000000] Xen: 0000000000000000 - 00000000000a0000 (usable) [ 0.000000] Xen: 00000000000a0000 - 0000000000100000 (reserved) [ 0.000000] Xen: 0000000000100000 - 0000000010000000 (usable) [ 0.000000] NX (Execute Disable) protection: active [ 0.000000] DMI not present or invalid. [ 0.000000] No AGP bridge found [ 0.000000] last_pfn = 0x10000 max_arch_pfn = 0x400000000 [ 0.000000] init_memory_mapping: 0000000000000000-0000000010000000 [ 0.000000] RAMDISK: 0205c000 - 02c43000 [ 0.000000] NUMA turned off [ 0.000000] Faking a node at 0000000000000000-0000000010000000 [ 0.000000] Initmem setup node 0 0000000000000000-0000000010000000 [ 0.000000] NODE_DATA [000000000fffb000 - 000000000fffffff] [ 0.000000] Zone PFN ranges: [ 0.000000] DMA 0x00000010 -> 0x00001000 [ 0.000000] DMA32 0x00001000 -> 0x00100000 [ 0.000000] Normal empty [ 0.000000] Movable zone start PFN for each node [ 0.000000] early_node_map[2] active PFN ranges [ 0.000000] 0: 0x00000010 -> 0x000000a0 [ 0.000000] 0: 0x00000100 -> 0x00010000 [ 0.000000] SFI: Simple Firmware Interface v0.81 http://simplefirmware.org [ 0.000000] SMP: Allowing 1 CPUs, 0 hotplug CPUs [ 0.000000] No local APIC present [ 0.000000] APIC: disable apic facility [ 0.000000] APIC: switched to apic NOOP [ 0.000000] PM: Registered nosave memory: 00000000000a0000 - 0000000000100000 [ 0.000000] Allocating PCI resources starting at 10000000 (gap: 10000000:f0000000) [ 0.000000] Booting paravirtualized kernel on Xen [ 0.000000] Xen version: 4.8.3-pre (preserve-AD) [ 0.000000] setup_percpu: NR_CPUS:64 nr_cpumask_bits:64 nr_cpu_ids:1 nr_node_ids:1 [ 0.000000] PERCPU: Embedded 27 pages/cpu @ffff88000fc00000 s78848 r8192 d23552 u2097152 [ 0.000000] Built 1 zonelists in Node order, mobility grouping on. Total pages: 64395 [ 0.000000] Policy zone: DMA32 [ 0.000000] Kernel command line: root=/dev/xvda2 ro elevator=noop root=/dev/xvda2 ro [ 0.000000] PID hash table entries: 1024 (order: 1, 8192 bytes) [ 0.000000] xsave/xrstor: enabled xstate_bv 0x7, cntxt size 0x340 [ 0.000000] Checking aperture... [ 0.000000] No AGP bridge found [ 0.000000] Memory: 228408k/262144k available (6617k kernel code, 448k absent, 33288k reserved, 6579k data, 932k init) [ 0.000000] SLUB: Genslabs=15, HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 [ 0.000000] Hierarchical RCU implementation. [ 0.000000] RCU dyntick-idle grace-period acceleration is enabled. [ 0.000000] NR_IRQS:4352 nr_irqs:256 16 [ 0.000000] Console: colour dummy device 80x25 [ 0.000000] console [tty0] enabled [ 0.000000] console [hvc0] enabled [ 0.000000] allocated 2097152 bytes of page_cgroup [ 0.000000] please try 'cgroup_disable=memory' option if you don't want memory cgroups [ 0.000000] installing Xen timer for CPU 0 [ 0.000000] Detected 3194.398 MHz processor. [ 0.004000] Calibrating delay loop (skipped), value calculated using timer frequency.. 6388.79 BogoMIPS (lpj=12777592) [ 0.004000] pid_max: default: 32768 minimum: 301 [ 0.004000] Security Framework initialized [ 0.004000] AppArmor: AppArmor initialized [ 0.004000] Yama: becoming mindful. [ 0.004000] Dentry cache hash table entries: 32768 (order: 6, 262144 bytes) [ 0.004000] Inode-cache hash table entries: 16384 (order: 5, 131072 bytes) [ 0.004000] Mount-cache hash table entries: 256 [ 0.004000] Initializing cgroup subsys cpuacct [ 0.004000] Initializing cgroup subsys memory [ 0.004000] Initializing cgroup subsys devices [ 0.004000] Initializing cgroup subsys freezer [ 0.004000] Initializing cgroup subsys blkio [ 0.004000] Initializing cgroup subsys perf_event [ 0.004000] CPU: Physical Processor ID: 0 [ 0.004000] CPU: Processor Core ID: 0 [ 0.006575] SMP alternatives: switching to UP code [ 0.034623] Freeing SMP alternatives: 24k freed [ 0.034647] ftrace: allocating 26699 entries in 105 pages [ 0.036061] cpu 0 spinlock event irq 17 [ 0.036079] Performance Events: [ 0.036082] no APIC, boot with the "lapic" boot parameter to force-enable it. [ 0.036086] no hardware sampling interrupt available. [ 0.036094] Broken PMU hardware detected, using software events only. [ 0.036207] NMI watchdog disabled (cpu0): hardware events not enabled [ 0.036229] Brought up 1 CPUs [ 0.036343] devtmpfs: initialized [ 0.036844] EVM: security.selinux [ 0.036848] EVM: security.SMACK64 [ 0.036851] EVM: security.capability [ 0.037364] Grant table initialized [ 0.037410] print_constraints: dummy: [ 0.057265] RTC time: 165:165:165, date: 165/165/65 [ 0.057318] NET: Registered protocol family 16 [ 0.057508] Extended Config Space enabled on 0 nodes [ 0.057542] PCI: setting up Xen PCI frontend stub [ 0.057542] bio: create slab <bio-0> at 0 [ 0.057542] ACPI: Interpreter disabled. [ 0.057542] xen/balloon: Initialising balloon driver. [ 0.057542] xen-balloon: Initialising balloon driver. [ 0.057542] vgaarb: loaded [ 0.057542] i2c-core: driver [aat2870] using legacy suspend method [ 0.057542] i2c-core: driver [aat2870] using legacy resume method [ 0.057542] SCSI subsystem initialized [ 0.057542] usbcore: registered new interface driver usbfs [ 0.057542] usbcore: registered new interface driver hub [ 0.057542] usbcore: registered new device driver usb [ 0.057542] PCI: System does not support PCI [ 0.057542] PCI: System does not support PCI [ 0.057542] NetLabel: Initializing [ 0.057542] NetLabel: domain hash size = 128 [ 0.057542] NetLabel: protocols = UNLABELED CIPSOv4 [ 0.057542] NetLabel: unlabeled traffic allowed by default [ 0.057542] Switching to clocksource xen [ 0.061230] AppArmor: AppArmor Filesystem Enabled [ 0.061253] pnp: PnP ACPI: disabled [ 0.062521] NET: Registered protocol family 2 [ 0.065648] IP route cache hash table entries: 2048 (order: 2, 16384 bytes) [ 0.065807] TCP established hash table entries: 8192 (order: 5, 131072 bytes) [ 0.065861] TCP bind hash table entries: 8192 (order: 5, 131072 bytes) [ 0.065881] TCP: Hash tables configured (established 8192 bind 8192) [ 0.065885] TCP reno registered [ 0.065889] UDP hash table entries: 128 (order: 0, 4096 bytes) [ 0.065895] UDP-Lite hash table entries: 128 (order: 0, 4096 bytes) [ 0.065934] NET: Registered protocol family 1 [ 0.065967] platform rtc_cmos: registered platform RTC device (no PNP device found) [ 0.066094] Trying to unpack rootfs image as initramfs... [ 0.072210] audit: initializing netlink socket (disabled) [ 0.190742] type=2000 audit(1518793913.856:1): initialized [ 0.209702] Freeing initrd memory: 12188k freed [ 0.213726] VFS: Disk quotas dquot_6.5.2 [ 0.213770] Dquot-cache hash table entries: 512 (order 0, 4096 bytes) [ 0.213950] hugetlbfs: disabling because there are no supported hugepage sizes [ 0.214050] fuse init (API version 7.17) [ 0.214104] msgmni has been set to 469 [ 0.214342] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253) [ 0.214362] io scheduler noop registered (default) [ 0.214367] io scheduler deadline registered [ 0.214386] io scheduler cfq registered [ 0.214439] pci_hotplug: PCI Hot Plug PCI Core version: 0.5 [ 0.214454] pciehp: PCI Express Hot Plug Controller Driver version: 0.4 [ 0.214460] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5 [ 0.214672] Serial: 8250/16550 driver, 32 ports, IRQ sharing enabled [ 0.215413] Linux agpgart interface v0.103 [ 0.216235] brd: module loaded [ 0.216618] loop: module loaded [ 0.217745] blkfront device/vbd/51714 num-ring-pages 1 nr_ents 32. [ 0.218925] blkfront device/vbd/51713 num-ring-pages 1 nr_ents 32. [ 0.219299] Fixed MDIO Bus: probed [ 0.219322] tun: Universal TUN/TAP device driver, 1.6 [ 0.219329] tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com> [ 0.219390] PPP generic driver version 2.4.2 [ 0.219430] Initialising Xen virtual ethernet driver. [ 0.222394] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 0.222413] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 0.222423] uhci_hcd: USB Universal Host Controller Interface driver [ 0.222459] usbcore: registered new interface driver libusual [ 0.222477] i8042: PNP: No PS/2 controller found. Probing ports directly. [ 1.223457] i8042: No controller found [ 1.223625] mousedev: PS/2 mouse device common for all mice [ 1.263475] rtc_cmos rtc_cmos: rtc core: registered rtc_cmos as rtc0 [ 1.263520] rtc_cmos: probe of rtc_cmos failed with error -38 [ 1.263601] device-mapper: uevent: version 1.0.3 [ 1.263654] device-mapper: ioctl: 4.22.0-ioctl (2011-10-19) initialised: dm-devel@redhat.com [ 1.263664] EFI Variables Facility v0.08 2004-May-17 [ 1.263886] TCP cubic registered [ 1.263952] NET: Registered protocol family 10 [ 1.264555] NET: Registered protocol family 17 [ 1.264564] Registering the dns_resolver key type [ 1.264668] registered taskstats version 1 [ 1.273569] blkfront: xvda2: flush diskcache: enabled [ 1.274605] blkfront: xvda1: flush diskcache: enabled [ 1.368068] Magic number: 1:252:3141 [ 1.368107] /build/linux-JvAKgs/linux-3.2.0/drivers/rtc/hctosys.c: unable to open rtc device (rtc0) [ 1.368118] BIOS EDD facility v0.16 2004-Jun-25, 0 devices found [ 1.368121] EDD information not available. [ 1.368534] Freeing unused kernel memory: 932k freed [ 1.368687] Write protecting the kernel read-only data: 12288k [ 1.373188] Freeing unused kernel memory: 1556k freed [ 1.373812] Freeing unused kernel memory: 1172k freed Loading, please wait... Begin: Loading essential drivers ... done. [ 1.402645] udevd[82]: starting version 175 Begin: Running /scripts/init-premount ... done. Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done. Begin: Running /scripts/local-premount ... done. [ 1.506696] JBD2: Unrecognised features on journal [ 1.506706] EXT4-fs (xvda2): error loading journal mount: mounting /dev/xvda2 on /root failed: Invalid argument Begin: Running /scripts/local-bottom ... done. done. Begin: Running /scripts/init-bottom ... mount: mounting /dev on /root/dev failed: No such file or directory done. mount: mounting /sys on /root/sys failed: No such file or directory mount: mounting /proc on /root/proc failed: No such file or directory Target filesystem doesn't have requested /sbin/init. No init found. Try passing init= bootarg. BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash) Enter 'help' for a list of built-in commands. (initramfs)
      
      







それがどんなイメージなのか見てみましょう:



 (initramfs) uname -a Linux (none) 3.2.0-126-virtual #169-Ubuntu SMP Fri Mar 31 14:47:56 UTC 2017 x86_64 GNU/Linux (initramfs)
      
      





スモールOS(ミニOS)の起動



前の部分から、動作するにはドメイン(インスタンス)を作成する必要があることが明らかになりました。 これは、構成ファイルに基づいてxlユーティリティを使用して作成されます。



しかし、設定ファイルを見ると
 # # Configuration file for the Xen instance test, created # by xen-tools 4.7 on Fri Feb 16 18:09:35 2018. # # # Kernel + memory size # bootloader = '/usr/lib/xen-4.8/bin/pygrub' vcpus = '1' memory = '256' # # Disk device(s). # root = '/dev/xvda2 ro' disk = [ 'file:/srv/xen/test/domains/test/disk.img,xvda2,w', 'file:/srv/xen/test/domains/test/swap.img,xvda1,w', ] # # Physical volumes # # # Hostname # name = 'test' # # Networking # dhcp = 'dhcp' vif = [ 'mac=00:16:3E:8E:3C:E0' ] # # Behaviour # on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart'
      
      







次に、ディスクイメージの必要性、ネットワークの存在などを確認します。 おそらく、私たちの目的には複雑すぎます。 ただし、Xenは他のOSもサポートしています。 ベースはいわゆるMini-OSです。 さらに、 オペレーティングシステムをXENに移植するユーザーを対象としています。つまり、これは単なるオプションです。

gitコードはXENとは別のものです。



すぐにREADMEの手順を実行しましょう。



 make sudo xl create -c domain_config
      
      





結論を得る
 Parsing config from domain_config Xen Minimal OS (pv)! start_info: 0x7d000(VA) nr_pages: 0x2000 shared_inf: 0xdee73000(MA) pt_base: 0x80000(VA) nr_pt_frames: 0x5 mfn_list: 0x6d000(VA) mod_start: 0x0(VA) mod_len: 0 flags: 0x0 cmd_line: stack: 0x2c6a0-0x4c6a0 MM: Init _text: 0(VA) _etext: 0x18484(VA) _erodata: 0x1f000(VA) _edata: 0x1f252(VA) stack start: 0x2c6a0(VA) _end: 0x6cfd8(VA) start_pfn: 85 max_pfn: 2000 Mapping memory range 0x85000 - 0x2000000 setting 0-0x1f000 readonly skipped 1000 MM: Initialise page allocator for 93000(93000)-2000000(2000000) Adding memory range 94000-2000000 MM: done Demand map pfns at 100000000000-108000000000. Initialising timer interface Initialising console ... done. gnttab_table mapped at 0x100000000000. Initialising scheduler Thread "Idle": pointer: 0x0x96078, stack: 0x0xa0000 Thread "xenstore": pointer: 0x0x960d8, stack: 0x0xb0000 xenbus initialised on irq 1 Thread "shutdown": pointer: 0x0x96138, stack: 0x0xc0000 kernel.c: dummy main: par=0
      
      







通常どおり、ctrl +]コンソールを終了します



一部のマシンが起動したことを確認します。



 sudo xl list Name ID Mem VCPUs State Time(s) Domain-0 0 15455 8 r----- 5117.7 Mini-OS 2 32 1 -b---- 0.0
      
      





コンソールに戻るには



 sudo xl console Mini-OS
      
      





ドメインを削除するには



 sudo xl destroy Mini-OS
      
      





さて、プロジェクトのルートにあるdomain_configの内容を見てみましょう
 # -*- mode: python; -*- #============================================================================ # Python configuration setup for 'xm create'. # This script sets the parameters used when a domain is created using 'xm create'. # You use a separate script for each domain you want to create, or # you can set the parameters for the domain on the xm command line. #============================================================================ #---------------------------------------------------------------------------- # Kernel image file. kernel = "mini-os.gz" # Initial memory allocation (in megabytes) for the new domain. memory = 32 # A name for your domain. All domains must have different names. name = "Mini-OS" on_crash = 'destroy'
      
      







カーネルパラメーターを使用して、ディスクではなく直接イメージを指定し、最初の段階で不要なネットワーク設定やその他のパラメーターを指定しないこともできます。



EmboxをXenに移植する



構成ファイルの作成



まず、Emboxでドメインを起動するために、Mini-OSのイメージと似たような設定ファイルを作成します。



 name = "embox" memory = 256 kernel = "/tmp/xen_embox"
      
      





Emboxにアーキテクチャを追加する



Emboxには、Anton Kozlov( antonkozlov )の卒業証書があり、それを「モジュラーHALを備えたオペレーティングシステムをユーザーモードに移植する」という新しいプラットフォームに移行することができます 。 より正確には、卒業証書はEmboxの移植に関するものではなく、オペレーティングシステム全般の整理に関するものであり、Emboxはモルモットとして使用されていました。 特にXenについては、Andrei Golikov 「EmboxオペレーティングシステムをXenプラットフォームに移植する」というコースがあります 。 卒業証書とコースを再度語らないようにするために、Xenパーツに固有のいくつかの重要かつ特定のことに限定します。



ご想像のとおり、必要な情報はすべてMini-OSから取得できます。



移植が最初に始まるものの1つはメモリーカード(SDカードではなく、異なるメモリー領域-メモリーマップ)です。これは伝統的にldsスクリプトで記述されています。 リンカは、プログラムコード、データ、プログラムへのエントリポイントなどの場所を示す必要があります。 この場合、これは、イメージをダウンロードする前に、「。note.Xen」セクションの一部の機能、より正確にはELF PT_NOTE形式のヘッダーを読み取る必要があるという事実によって追加されます。 ここでは、メモリカードと機能について説明します



以下は、XenのEmboxリンカースクリプトに追加されます。



 PHDRS { xen PT_NOTE; } SECTIONS { .note : { *(.note) } :xen }
      
      





さて、このヘッダーのコンテンツを含む別のアセンブラーファイルが追加されました



 #include <xen/elfnote.h> .section ".note", "a" #define ELFNOTE(type, desc) \ .p2align 2; \ .long 1f - 0f; \ .long 3f - 2f; \ .long type; \ 0: .asciz "Xen"; \ 1: .p2align 2; \ 2: desc; \ 3: .p2align 2; ELFNOTE(XEN_ELFNOTE_XEN_VERSION, .asciz "xen-3.0") ELFNOTE(XEN_ELFNOTE_LOADER, .asciz "generic") ELFNOTE(XEN_ELFNOTE_PAE_MODE, .asciz "yes") ELFNOTE(XEN_ELFNOTE_VIRT_BASE, .long 0x100000) ELFNOTE(XEN_ELFNOTE_PADDR_OFFSET, .long 0x100000) ELFNOTE(XEN_ELFNOTE_HYPERCALL_PAGE, .long 0x100000)
      
      





さらに、イメージとXen struct start_infoおよびstruct shared_infoの間の相互作用に必要な構造がさらに2つあります。

struct start_infoは、イメージの開始時にマシンに関する情報を取得する場合、つまり、原則としてそれなしで実行できる場合に必要です。



 * * `incontents 200 startofday_shared Start-of-day shared data structure * Xen/kernel shared data -- pointer provided in start_info. * * This structure is defined to be both smaller than a page, and the * only data on the shared page, but may vary in actual size even within * compatible Xen versions; guests should not rely on the size * of this structure remaining constant. */ struct shared_info { struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS]; /* * A domain can create "event channels" on which it can send and receive * asynchronous event notifications. There are three classes of event that * are delivered by this mechanism: * 1. Bi-directional inter- and intra-domain connections. Domains must * arrange out-of-band to set up a connection (usually by allocating * an unbound 'listener' port and avertising that via a storage service * such as xenstore). * 2. Physical interrupts. A domain with suitable hardware-access * privileges can bind an event-channel port to a physical interrupt * source. * 3. Virtual interrupts ('events'). A domain can bind an event-channel * port to a virtual interrupt source, such as the virtual-timer * device or the emergency console. * * Event channels are addressed by a "port index". Each channel is * associated with two bits of information: * 1. PENDING -- notifies the domain that there is a pending notification * to be processed. This bit is cleared by the guest. * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING * will cause an asynchronous upcall to be scheduled. This bit is only * updated by the guest. It is read-only within Xen. If a channel * becomes pending while the channel is masked then the 'edge' is lost * (ie, when the channel is unmasked, the guest must manually handle * pending notifications as no upcall will be scheduled by Xen). * * To expedite scanning of pending notifications, any 0->1 pending * transition on an unmasked channel causes a corresponding bit in a * per-vcpu selector word to be set. Each bit in the selector covers a * 'C long' in the PENDING bitfield array. */ xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8]; xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8]; /* * Wallclock time: updated only by control software. Guests should base * their gettimeofday() syscall on this wallclock-base value. */ uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */ uint32_t wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */ uint32_t wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */ struct arch_shared_info arch; };
      
      





struct shared_info



struct shared_info



、相互作用に関する情報が含まれています。つまり、それを通じて、割り込み、データの到着などのイベントを受け取ります。

この構造は4kbオフセットで配置されています



リンカースクリプトは次のようになります



 SECTIONS { .text : { . = ALIGN(0x1000); hypercall_page = .; . += 0x1000; xen_shared_info = .; . += 0x1000; _traps_text_start = .; *(.traps.*) _traps_text_end = .; *(.text) *(.text.*) } }
      
      





実際、すべてのコードの分析は明らかに1つの記事の範囲を超えているため、ここで終了します。 現時点では、学生はデバッグ出力付きのマシン起動を実装しているとしか言えません。

これを確認するには、Emboxで次の操作を行います。



 make confload-xen/debug make ./scripts/xen/run_xen
      
      





ドメインが作成され、Embox自体の出力が送信されます。 いつものように、ctrl +]コンソールを終了し、マシンを削除することを忘れないでください: sudo destroy embox







当然、最初に環境を設定する必要があります。 しかし、簡単にするために、学生ではなく、私たちはすでに、すべてをバグランドで提供する機能を追加しました。 これはwikiで説明されています 。 VirtualBoxとvagrandのみが必要です。 Xenの下ではなくインストールする必要があります。



最後に、ITのトレーニングのトピックに再び触れたいと思います。 すでに記事で書いたように、 「プログラマーを不正行為に巻き込む方法と、それをやる価値があるかどうか」と書いたように 、私たちのプロジェクトでは、学生を実際のプロジェクトに没頭させています。 この場合、生徒は非常に野心的ではありますが、教育課題を実行するときよりもはるかに多くの経験を得ることができます。 そして最も重要なことは、彼らは特定の言語を学ぶだけでなく、製品を作り、自分で問題を解決し、単純に考えることができるようになることを学びます。 例として、理想的なクラウドプラットフォームに関するアイデアの著者であるAnton Kozlov( antonkozlov )を紹介します。これは、先に彼の卒業証書について言及したためです。 トレーニングの結果によると、彼はコードを書くだけでなく、彼自身のアイデアを提供し、それらを実装し、タスクをコンポーネントに分解し、学生を教育することができました。 多くの同様の例があります。



PS:その会議のビデオはこちらから入手できます



All Articles