Amazon Linux 2018.03のカーネルのソースコードを取得する

はじめに

AWSを触っていてちょっとAmazon Linuxのソースコードを見ようと思ってやり方を調べたときのメモ。

Amazon Linuxのカーネルのソースコード取得

ドキュメントやFAQを見るとCentOSと同じくyumdownloaderが使えて、そこからカーネルのソースを取得できるとのこと。

で、以下をやってみたら最新カーネルのRPMが取得できた。

現在のカーネルのバージョンを確認。4.14.62-65.117だった。

$ rpm -qa | grep kernel
kernel-4.14.62-65.117.amzn1.x86_64
kernel-tools-4.14.88-72.73.amzn1.x86_64

/tmpへ移動してyumdownloader でカーネルのソースRPMを取得。kernel-4.14.62-65.117.amzn1の指定は別になくても良い。

$ cd /tmp

$ sudo yumdownloader --source kernel kernel-4.14.62-65.117.amzn1
Loaded plugins: priorities, update-motd, upgrade-helper
Enabling amzn-updates-source repository
Enabling amzn-main-source repository
kernel-4.14.62-65.117.amzn1.src.rpm

RPMの中身を取得するために、まずはファイルを出力させるディレクトリを作成する。
そしてそのディレクトリへ移動する。

$ sudo mkdir -p /usr/src/kernels/4.14.62-65.117.amzn1

$ cd /usr/src/kernels/4.14.62-65.117.amzn1

rpm2cpioコマンドを使ってRPMからファイルを取得する。

$ sudo sh -c "rpm2cpio /tmp/kernel-4.14.62-65.117.amzn1.src.rpm | cpio -id"

以下のようなファイルが作成される。
パッチファイルがたくさんある…

$ ls
0001-kbuild-AFTER_LINK.patch                                     0045-x86-speculation-l1tf-Disallow-non-privileged-high-MM.patch  0089-x86-bugs-kvm-Introduce-boot-time-control-of-L1TF-mit.patch
0002-watchdog-Disable-watchdog-on-virtual-machines.patch         0046-x86-speculation-l1tf-Limit-swap-file-size-to-MAX_PA-.patch  0090-Documentation-Add-section-about-CPU-vulnerabilities.patch
0003-scsi-sd_revalidate_disk-prevent-NULL-ptr-deref.patch        0047-x86-bugs-Move-the-l1tf-function-and-define-pr_fmt-pr.patch  0091-x86-KVM-VMX-Initialize-the-vmx_l1d_flush_pages-conte.patch
0004-bump-the-default-TTL-to-255.patch                           0048-sched-smt-Update-sched_smt_present-at-runtime.patch         0092-Documentation-l1tf-Fix-typos.patch
0005-bump-default-tcp_wmem-from-16KB-to-20KB.patch               0049-x86-smp-Provide-topology_is_primary_thread.patch            0093-cpu-hotplug-detect-SMT-disabled-by-BIOS.patch
0006-force-perf-to-use-usr-bin-python-instead-of-usr-bin-.patch  0050-x86-topology-Provide-topology_smt_supported.patch           0094-x86-KVM-VMX-Don-t-set-l1tf_flush_l1d-to-true-from-vm.patch
0007-nvme-update-timeout-module-parameter-type.patch             0051-cpu-hotplug-Make-bringup-teardown-of-smp-threads-sym.patch  0095-x86-KVM-VMX-Replace-vmx_l1d_flush_always-with-vmx_l1.patch
0008-not-for-upstream-testmgr-config-changes-to-enable-FI.patch  0052-cpu-hotplug-Split-do_cpu_down.patch                         0096-x86-KVM-VMX-Move-the-l1tf_flush_l1d-test-to-vmx_l1d_.patch
0009-drivers-introduce-AMAZON_DRIVER_UPDATES.patch               0053-cpu-hotplug-Provide-knobs-to-control-SMT.patch              0097-x86-irq-Demote-irq_cpustat_t-__softirq_pending-to-u1.patch
0010-drivers-amazon-add-network-device-drivers-support.patch     0054-x86-cpu-Remove-the-pointless-CPU-printout.patch             0098-x86-KVM-VMX-Introduce-per-host-cpu-analogue-of-l1tf_.patch
0011-drivers-amazon-introduce-AMAZON_ENA_ETHERNET.patch          0055-x86-cpu-AMD-Remove-the-pointless-detect_ht-call.patch       0099-x86-Don-t-include-linux-irq.h-from-asm-hardirq.h.patch
0012-Importing-Amazon-ENA-driver-1.5.0-into-amazon-4.14.y.patch  0056-x86-cpu-common-Provide-detect_ht_early.patch                0100-x86-irq-Let-interrupt-handlers-set-kvm_cpu_l1tf_flus.patch
0013-xen-manage-keep-track-of-the-on-going-suspend-mode.patch    0057-x86-cpu-topology-Provide-detect_extended_topology_ea.patch  0101-x86-KVM-VMX-Don-t-set-l1tf_flush_l1d-from-vmx_handle.patch
0014-xen-manage-introduce-helper-function-to-know-the-on-.patch  0058-x86-cpu-intel-Evaluate-smp_num_siblings-early.patch         0102-Documentation-l1tf-Remove-Yonah-processors-from-not-.patch
0015-xenbus-add-freeze-thaw-restore-callbacks-support.patch      0059-x86-CPU-AMD-Do-not-check-CPUID-max-ext-level-before-.patch  0103-KVM-x86-Add-a-framework-for-supporting-MSR-based-fea.patch
0016-x86-xen-Introduce-new-function-to-map-HYPERVISOR_sha.patch  0060-x86-cpu-AMD-Evaluate-smp_num_siblings-early.patch           0104-KVM-SVM-Add-MSR-based-feature-support-for-serializin.patch
0017-x86-xen-add-system-core-suspend-and-resume-callbacks.patch  0061-x86-apic-Ignore-secondary-threads-if-nosmt-force.patch      0105-KVM-X86-Introduce-kvm_get_msr_feature.patch
0018-xen-blkfront-add-callbacks-for-PM-suspend-and-hibern.patch  0062-x86-speculation-l1tf-Extend-64bit-swap-file-size-lim.patch  0106-KVM-X86-Allow-userspace-to-define-the-microcode-vers.patch
0019-xen-netfront-add-callbacks-for-PM-suspend-and-hibern.patch  0063-x86-cpufeatures-Add-detection-of-L1D-cache-flush-sup.patch  0107-KVM-VMX-support-MSR_IA32_ARCH_CAPABILITIES-as-a-feat.patch
0020-xen-time-introduce-xen_-save-restore-_steal_clock.patch     0064-x86-CPU-AMD-Move-TOPOEXT-reenablement-before-reading.patch  0108-x86-speculation-Simplify-sysfs-report-of-VMX-L1TF-vu.patch
0021-x86-xen-save-and-restore-steal-clock.patch                  0065-x86-speculation-l1tf-Protect-PAE-swap-entries-agains.patch  0109-x86-speculation-Use-ARCH_CAPABILITIES-to-skip-L1D-fl.patch
0022-xen-events-add-xen_shutdown_pirqs-helper-function.patch     0066-x86-speculation-l1tf-Fix-up-pte-pfn-conversion-for-P.patch  0110-KVM-VMX-Tell-the-nested-hypervisor-to-skip-L1D-flush.patch
0023-x86-xen-close-event-channels-for-PIRQs-in-system-cor.patch  0067-Revert-x86-apic-Ignore-secondary-threads-if-nosmt-fo.patch  0111-cpu-hotplug-Fix-SMT-supported-evaluation.patch
0024-PM-hibernate-update-the-resume-offset-on-SNAPSHOT_SE.patch  0068-cpu-hotplug-Boot-HT-siblings-at-least-once.patch            0112-x86-speculation-l1tf-Invert-all-not-present-mappings.patch
0025-Not-for-upstream-PM-hibernate-Speed-up-hibernation-b.patch  0069-x86-KVM-Warn-user-if-KVM-is-loaded-SMT-and-L1TF-CPU-.patch  0113-x86-speculation-l1tf-Make-pmd-pud_mknotpresent-inver.patch
0026-xen-blkfront-resurrect-request-based-mode.patch             0070-x86-KVM-VMX-Add-module-argument-for-L1TF-mitigation.patch   0114-x86-mm-pat-Make-set_memory_np-L1TF-safe.patch
0027-xen-blkfront-add-persistent_grants-parameter.patch          0071-x86-KVM-VMX-Add-L1D-flush-algorithm.patch                   0115-x86-mm-kmmio-Make-the-tracer-robust-against-L1TF.patch
0028-ACPI-SPCR-Make-SPCR-available-to-x86.patch                  0072-x86-KVM-VMX-Add-L1D-MSR-based-flush.patch                   0116-tools-headers-Synchronise-x86-cpufeatures.h-for-L1TF.patch
0029-Revert-xen-dont-fiddle-with-event-channel-masking-in.patch  0073-x86-KVM-VMX-Add-L1D-flush-logic.patch                       config-generic
0030-locking-paravirt-Use-new-static-key-for-controlling-.patch  0074-x86-KVM-VMX-Split-the-VMX-MSR-LOAD-structures-to-hav.patch  config-x86_32-generic
0031-KVM-Introduce-paravirtualization-hints-and-KVM_HINTS.patch  0075-x86-KVM-VMX-Add-find_msr-helper-function.patch              config-x86_64-generic
0032-KVM-X86-Choose-qspinlock-when-dedicated-physical-CPU.patch  0076-x86-KVM-VMX-Separate-the-VMX-AUTOLOAD-guest-host-num.patch  cpupower.config
0033-x86-paravirt-Set-up-the-virt_spin_lock_key-after-sta.patch  0077-x86-KVM-VMX-Extend-add_atomic_switch_msr-to-allow-VM.patch  cpupower.init
0034-KVM-X86-Fix-setup-the-virt_spin_lock_key-before-stat.patch  0078-x86-KVM-VMX-Use-MSR-save-list-for-IA32_FLUSH_CMD-if-.patch  kconfig.py
0035-xen-blkfront-Fixed-blkfront_restore-to-remove-a-call.patch  0079-cpu-hotplug-Online-siblings-when-SMT-control-is-turn.patch  kernel.spec
0036-xen-netfront-Update-features-after-registering-netde.patch  0080-x86-litf-Introduce-vmx-status-variable.patch                linux-4.14.62-patches.tar
0037-x86-tsc-avoid-system-instability-in-hibernation.patch       0081-x86-kvm-Drop-L1TF-MSR-list-approach.patch                   linux-4.14.62.tar
0038-blk-mq-simplify-queue-mapping-schedule-with-each-pos.patch  0082-x86-l1tf-Handle-EPT-disabled-state-proper.patch             Makefile.config
0039-x86-speculation-l1tf-Increase-32bit-PAE-__PHYSICAL_P.patch  0083-x86-kvm-Move-l1tf-setup-function.patch                      mod-extra.list
0040-x86-speculation-l1tf-Change-order-of-offset-type-in-.patch  0084-x86-kvm-Add-static-key-for-flush-always.patch               mod-extra.sh
0041-x86-speculation-l1tf-Protect-swap-entries-against-L1.patch  0085-x86-kvm-Serialize-L1D-flush-parameter-setter.patch          mod-extra-sign.sh
0042-x86-speculation-l1tf-Protect-PROT_NONE-PTEs-against-.patch  0086-x86-kvm-Allow-runtime-control-of-L1D-flush.patch            split-man.pl
0043-x86-speculation-l1tf-Make-sure-the-first-page-is-alw.patch  0087-cpu-hotplug-Expose-SMT-control-init-function.patch          x509.genkey
0044-x86-speculation-l1tf-Add-sysfs-reporting-for-l1tf.patch     0088-cpu-hotplug-Set-CPU_SMT_NOT_SUPPORTED-early.patch

linux-4.14.62.tarを展開すればソースを参照できるようになる。

$ sudo tar -xf linux-4.14.62.tar
$ cd linux-4.14.62

$ ls -lth
total 720K
drwxrwxr-x  32 root root 4.0K Aug  9 10:16 arch
drwxrwxr-x   3 root root 4.0K Aug  9 10:16 block
drwxrwxr-x   2 root root 4.0K Aug  9 10:16 certs
-rw-rw-r--   1 root root  19K Aug  9 10:16 COPYING
-rw-rw-r--   1 root root  97K Aug  9 10:16 CREDITS
drwxrwxr-x   4 root root 4.0K Aug  9 10:16 crypto
drwxrwxr-x 121 root root  12K Aug  9 10:16 Documentation
drwxrwxr-x 131 root root 4.0K Aug  9 10:16 drivers
drwxrwxr-x   2 root root 4.0K Aug  9 10:16 firmware
drwxrwxr-x  74 root root 4.0K Aug  9 10:16 fs
drwxrwxr-x  27 root root 4.0K Aug  9 10:16 include
drwxrwxr-x   2 root root 4.0K Aug  9 10:16 init
drwxrwxr-x   2 root root 4.0K Aug  9 10:16 ipc
-rw-rw-r--   1 root root 2.3K Aug  9 10:16 Kbuild
-rw-rw-r--   1 root root  287 Aug  9 10:16 Kconfig
drwxrwxr-x  17 root root 4.0K Aug  9 10:16 kernel
drwxrwxr-x  13 root root  12K Aug  9 10:16 lib
-rw-rw-r--   1 root root 421K Aug  9 10:16 MAINTAINERS
-rw-rw-r--   1 root root  60K Aug  9 10:16 Makefile
drwxrwxr-x   3 root root 4.0K Aug  9 10:16 mm
drwxrwxr-x  69 root root 4.0K Aug  9 10:16 net
-rw-rw-r--   1 root root  722 Aug  9 10:16 README
drwxrwxr-x  28 root root 4.0K Aug  9 10:16 samples
drwxrwxr-x  14 root root 4.0K Aug  9 10:16 scripts
drwxrwxr-x  10 root root 4.0K Aug  9 10:16 security
drwxrwxr-x  24 root root 4.0K Aug  9 10:16 sound
drwxrwxr-x  30 root root 4.0K Aug  9 10:16 tools
drwxrwxr-x   2 root root 4.0K Aug  9 10:16 usr
drwxrwxr-x   4 root root 4.0K Aug  9 10:16 virt

おわりに

Amazon Linuxのカーネルのソースコードを取得してみた。
いろんなパッチが当てられていていろいろカスタマイズされているらしいというのはわかった。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です