LoginSignup
7
8

More than 5 years have passed since last update.

DHCPサーバ無しでArchLinuxをiPXEブートに挑戦

Last updated at Posted at 2015-12-10

この記事はArch Linux Advent Calender 2015の10日目です。

  • DHCPサーバ無しでArchLinuxをiPXEでブートすることはできないようで、この壁を乗り越える!

参考

ipxeビルド

  • 公式のipxeがダメならビルドすればいいじゃないの
git clone git://git.ipxe.org/ipxe.git
cd ipxe/src
パッケージが不足している場合以下を入れる
apt-get install -y liblzma-dev genisoimage syslinux isolinux
make
make
  • Pingを有効にする場合Ping commandを参考にconfig/general.hを修正する。
config/general.h
- //#define PING_CMD              /* Ping command */
+ #define PING_CMD              /* Ping command */
bin/ipxe.usbにmyscript.ipxeを含めて生成
make bin/ipxe.lkrn EMBED=myscript.ipxe
make bin/ipxe.usb EMBED=myscript.ipxe
make bin/ipxe.iso EMBED=myscript.ipxe

myscript.ipxe

myscript.ipxe
#!ipxe

#################
#network settings
#################
set dns 8.8.8.8
set net0/netmask 255.255.255.0
echo -n IP address: && read net0/ip
echo -n Default gateway: && read net0/gateway

#################
:boot_menu
#################
menu
    item arch_jp      ArchLinux x86_64 jp mirror
    item arch_us      ArchLinux x86_64 us mirror
    item ipxe_dhcp    DHCP
    item ipxe_ifopen  ifopen net0 (for static ip.)
    item ipxe_config  Enter iPXE config
    item ipxe_shell   Enter iPXE shell

choose --default config --timeout 30000 target && goto ${target}

#################
# menu
#################
:ipxe_dhcp
    dhcp
    goto boot_menu

:ipxe_ifopen
    ifopen net0
    goto boot_menu

:ipxe_config
    config
    goto boot_menu

:ipxe_shell
    shell
    goto boot_menu

:arch_jp
    echo ip=${net0/ip}::${net0/gateway}:${net0/netmask}
    # ftp.jaist.ac.jp => 150.65.7.130
    set source http://150.65.7.130/pub/Linux/ArchLinux/iso/latest
    kernel ${source}/arch/boot/x86_64/vmlinuz archiso_http_srv=${source}/ archisobasedir=arch ip=${net0/ip}::${net0/gateway}:${net0/netmask}
    initrd ${source}/arch/boot/x86_64/archiso.img
    boot

:arch_us
    echo ip=${net0/ip}::${net0/gateway}:${net0/netmask}
    # mirrors.abscission.net => 107.191.116.135
    set source http://107.191.116.135/archlinux/iso/latest
    kernel ${source}/arch/boot/x86_64/vmlinuz archiso_http_srv=${source}/ archisobasedir=arch ip=${net0/ip}::${net0/gateway}:${net0/netmask}
    initrd ${source}/arch/boot/x86_64/archiso.img
    boot

インターネットに接続できない場合はifopen net0が必要。
iPXE - open source boot firmware [cmd:ifopen]

initrd.imgを解読する方法

archiso.imgのダウンロード
wget http://ftp.jaist.ac.jp/pub/Linux/ArchLinux/iso/latest/arch/boot/x86_64/archiso.img
archiso.imgの展開
mv archiso.img archiso.cpio.gz
xz -d archiso.cpio.gz
mkdir tmp && cd tmp
cpio -id < ../archiso.cpio

Grub2で起動確認

/etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

menuentry 'Arch Linux Netboot Environment' {
  set root='(hd0,1)'
  linux16 /ipxe.lkrn
}
update-grub

Qemuで動作確認

ipxe.lkrnからブートする場合
qemu-system-x86_64 -m 1G -kernel bin/ipxe.lkrn \
  -net nic -net user
ISOイメージからブートする場合
qemu-system-x86_64 -boot d -cdrom bin/ipxe.iso \
 -net nic -net user

pxe1.png

pxe2.png

pxe3.png

pxe4.png

  • dnsが0.0.0.0になるんだよね・・・

pxe5.png

  • boot完了
起動完了したらresolv.confを作る。
echo nameserver 8.8.8.8 > /etc/resolv.conf

まとめ

  • iPXEイメージはたったの1MB
  • ipxe.usbイメージを/dev/sdaにddすればブートする手軽さ。
7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8