Upgrade to Pro — share decks privately, control downloads, hide ads and more …

小さいLinux環境の作り方

 小さいLinux環境の作り方

割と新しめのカーネルで、フロッピーディスク1枚に収まるLinuxディストリビューションを作る方法を解説します

Fadis

May 09, 2015
Tweet

More Decks by Fadis

Other Decks in Technology

Transcript

  1. େମͲͷυϥΠϒͰ΋ಡΊΔ ࠷େͷσΟεΫϑΥʔϚοτ͸,J#ͷ)% ΠϯνϑϩοϐʔσΟεΫͷ༰ྔ % ,J# % ,J# %% .BD ,J#

    %% ,J# %% .BD ,J# %% 1$ ,J# %% ,J# )% 1$ ,J# )% 1$"5 .BD ,J# &% ,J# 5% ,J#
  2.          

                   Y σϑΥϧτͷΧʔωϧίϯϑΟάͰ Ϗϧυͨ͠ΧʔωϧͷαΠζͷਪҠ CZUFT
  3.          

                 Y ϑϩοϐʔσΟεΫͷ༰ྔͷݶք ݱ࣮తͳΧʔωϧαΠζͷݶք -JOVY༨༟ -JOVY͍ۤ͠ -JOVYઈ๬త CZUFT
  4. Linux version 3.12.8 (root@Grueza) (gcc version 4.7.3 (Gentoo 4.7.3-r1 p1.4,

    pie-0.5.5) ) #2 Sat Feb 22 17:22:05 JST 2014 e820: BIOS-provided physical RAM map: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved BIOS-e820: [mem 0x0000000000100000-0x0000000007ffdfff] usable BIOS-e820: [mem 0x0000000007ffe000-0x0000000007ffffff] reserved BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved Notice: NX (Execute Disable) protection cannot be enabled: non- PAE kernel! SMBIOS 2.4 present. e820: last_pfn = 0x7ffe max_arch_pfn = 0x100000 PAT not supported by CPU. init_memory_mapping: [mem 0x00000000-0x000fffff] init_memory_mapping: [mem 0x07800000-0x07bfffff] init_memory_mapping: [mem 0x00100000-0x077fffff] init_memory_mapping: [mem 0x07c00000-0x07ffdfff] 0MB HIGHMEM available. 127MB LOWMEM available. mapped low ram: 0 - 07ffe000 low ram: 0 - 07ffe000 Zone ranges: DMA [mem 0x00001000-0x00ffffff] Normal [mem 0x01000000-0x07ffdfff] HighMem empty Movable zone start for each node Early memory node ranges node 0: [mem 0x00001000-0x0009efff] node 0: [mem 0x00100000-0x07ffdfff] e820: [mem 0x08000000-0xfeffbfff] available for PCI devices Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32412 Kernel command line: console=ttyS0 PID hash table entries: 512 (order: -1, 2048 bytes) Dentry cache hash table entries: 16384 (order: 4, 65536 bytes) $0/'*(@13*/5, Χʔωϧ͕ίϯιʔϧ౳ʹ৘ใΛग़ྗ͢Δػೳ ੾ΔͱΧʔωϧ͕ແޱʹͳΔ ͋Δ࣌ ͳ͍࣌
  5. $0/'*(@7.@&7&/5@$06/5&34 OS@EJSUZOS@XSJUFCBDLQHQHJOQHQHPVUQTXQJOQTXQPVUQHBMMPD@ENBQHBMMPD@ENB QHBMMPD@OPSNBMQHBMMPD@NPWBCMFQHGSFFQHBDUJWBUFQHEFBDUJWBUFQHGBVMUQHNBKGBVMU QHSFpMM@ENBQHSFpMM@ENBQHSFpMM@OPSNBMQHSFpMM@NPWBCMFQHTUFBM@LTXBQE@ENB QHTUFBM@LTXBQE@ENBQHTUFBM@LTXBQE@OPSNBMQHTUFBM@LTXBQE@NPWBCMF QHTUFBM@EJSFDU@ENBQHTUFBM@EJSFDU@ENBQHTUFBM@EJSFDU@OPSNBM QHTUFBM@EJSFDU@NPWBCMFQHTDBO@LTXBQE@ENBQHTDBO@LTXBQE@ENB QHTDBO@LTXBQE@OPSNBMQHTDBO@LTXBQE@NPWBCMFQHTDBO@EJSFDU@ENB QHTDBO@EJSFDU@ENBQHTDBO@EJSFDU@OPSNBMQHTDBO@EJSFDU@NPWBCMF QHTDBO@EJSFDU@UISPUUMF[POF@SFDMBJN@GBJMFEQHJOP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͠Ε ೥݄೔-JOVYMJCD։ൃऴྃ
  9. $ readelf -s a.out Symbol table '.dynsym' contains 13 entries:

    Num: Value Size Type Bind Vis Ndx 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (2) 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (3) 5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __cxa_atexit@GLIBC_2.2.5 (3) 6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE@GLIBCXX_3.4 (2) 8: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E@GLIBCXX_3.4 (2) 10: 00000000004007d0 0 FUNC GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait@GLIBCXX_3.4 (2) $ readelf -s a.out Symbol table '.dynsym' contains 13 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (2) 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (3) 5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __cxa_atexit@GLIBC_2.2.5 (3) 6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE@GLIBCXX_3.4 (2) 8: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E@GLIBCXX_3.4 (2) 10: 00000000004007d0 0 FUNC GLOBAL DEFAULT UND TUSJQTUSJQVOOFFEFEόΠφϦ ࣮ߦՄೳόΠφϦ͔ΒγϯϘϧςʔϒϧΛ࡟আ͢Δ TUSJQTUSJQVOOFFEFE ࣮ߦՄೳόΠφϦ͔Β γϯϘϧςʔϒϧΛ࡟আ͢Δ ΍Δલ ΍ͬͨޙ
  10. $ readelf -S a.out There are no sections in this

    file. $ readelf -S a.out There are 28 section headers, starting at offset 0x1180: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .interp PROGBITS 0000000000400270 00000270 000000000000001c 0000000000000000 A 0 0 1 [ 2] .note.ABI-tag NOTE 000000000040028c 0000028c 0000000000000020 0000000000000000 A 0 0 4 [ 3] .hash HASH 00000000004002b0 000002b0 0000000000000048 0000000000000004 A 5 0 TUSJQTUSJQVOOFFEFEόΠφϦ ࣮ߦՄೳόΠφϦ͔ΒγϯϘϧςʔϒϧΛ࡟আ͢Δ TTUSJQ ࣮ߦՄೳόΠφϦ͔Β ηΫγϣϯϔομΛ࡟আ͢Δ ΍Δલ ΍ͬͨޙ IUUQXXXNVQQFUMBCTDPNdCSFBECPYTPGUXBSFFMGLJDLFSTIUNM
  11. $ mkdir etc/ $ cat <<EOF >etc/init.d/rcS #!/bin/ash hostname Tiny

    mount -t proc none /proc mount -t sysfs none /sys ifconfig eth0 up udhcpc eth0 crond EOF $ cat <<EOF >etc/inittab ::sysinit:/etc/init.d/rcS tty1::respawn:/sbin/getty -L tty1 38400 linux tty2::respawn:/sbin/getty -L tty2 38400 linux ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 ::restart:/sbin/init ::shutdown:/bin/umount -a -r EOF
  12. $ mkdir -p proc sys dev root tmp var/spool/cron/ crontabs/

    usr/share/udhcpc/ cp -rpdf /dev/ {console,full,hpet,initctl,kmem,mem,null,nvram,port, ptya[0-9],ptya[a-f],random,rtc0,sda*,tty,tty [0-9],ttyS[0-1],urandom,zero} dev/ $ cp /usr/share/udhcpc/default.script usr/share/ udhcpc $ cat <<EOF >etc/group root:x:0:root bin:x:1:root,bin tty:x:5: kmem:x:9: uucp:x:14: EOF $ cat <<EOF >etc/passwd root:5vqD6957XLPg2:0:0:root:/root:/bin/ash bin:x:1:1:bin:/bin:/bin/false EOF $ ln -s bin/busybox init
  13. $ mkfs.minix /dev/fd0 $ mount -t auto /dev/fd0 /boot $

    cp initramfs.cpio.lzma /boot $ cp $(KERNEL_DIR)/arch/x86/boot/ bzImage /boot/vmlinuz $ cat <<EOF >/etc/lilo.conf boot = /dev/fd0 compact map = /boot/map vga = normal image = /boot/vmlinuz label = "Linux" initrd = /boot/initramfs.cpio.lzma EOF $ lilo -*-0ΛΠϯετʔϧ
  14. LILO 23.2 Loading Linux BIOS data check successful starting pid

    35, tty '/dev/tty1': '/ sbin/getty -L tty1 38400 linux' Tiny login: ಈ͍ͨ
  15.          

                ·ͱΊ -JOVYΧʔωϧ͸͜ͷ೥ͰڊେԽ͚ͨ͠Ͳ ࠓͷ-JOVYʹ͸ڊେԽʹ߅͏खஈ΋๛෋ʹ͋Δ͔Β ετϨʔδ͕ઈ๬తʹখͯ͘͞΋ ෛ͚ΔͳΨϯόϨʂ
  16. 44)ಉࠝ൛ *1W൛ (FOUPP൛ Thank you for listening. ઃఆ౳ IUUQUDPRG-Y[PL NETVNGECDGGFBE

    IUUQUDP:/24MFF NETVNECFBEBE IUUQUDPI'YZVTBLFO NETVNCBDEFEFCEBFFEDEEF IUUQXXXVTBLVSBOFKQEFOFCDPOpHT