labunix's blog

labunixのラボUnix

稼働中のLinuxにnetinstallerのイメージを置いて再起動、USBメモリにインストール

■稼働中のLinuxにnetinstallerのイメージを置いて再起動、USBメモリにインストール

 CDに焼くのは問題外だし、
 USBメモリにddすればインストーラ起動するのは素敵だけど、
 USBメモリにインストールするんだし、
 インストーラをわざわざUSBメモリに入れるのはちょっとと思っているそこのあなた。。。

 GRUB2のとLinuxが稼働して、インターネットにつながればOKです。
 プロキシ経由の場合でも、インストーラのウイザード内で設定出来ます。

 何を言っているか分からないのであれば、そっとページを閉じてくださいw。。。

■試した環境は以下。ツッコミは受け付けませんw。

$ cat /etc/debian_version 
7.6
$ sudo update-grub2 --version
grub-mkconfig (GRUB) 1.99-27+deb7u2

■既存のgrub2のエントリを確認

$ grep "menuentry" /boot/grub/grub.cfg | nl -w2 -v0 | sed s/"--"/"\n\t&"/g
 0	menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64' 
	--class debian 
	--class gnu-linux 
	--class gnu 
	--class os {
 1	menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)' 
	--class debian 
	--class gnu-linux 
	--class gnu 
	--class os {

■必要な情報は以下。

$ WHEEZY="http://http.us.debian.org/debian/dists/wheezy/main"; \
  AMD64="installer-amd64/current/images/netboot/debian-installer/amd64"; \
  wget $WHEEZY/$AMD64/initrd.gz && \
  wget $WHEEZY/$AMD64/linux && \
  sudo mv {linux,initrd.gz} /boot/new/ && \
  ls /boot/new/; \
  unset WHEEZY AMD64
initrd.gz  linux

■GRUB2メニューの設定変更、最終の5行を追加。
 ※grub.cfgを直接編集しない。

$ cat /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 "Wheezy Installer" {
        set root=(hd0,1)
        linux /boot/new/linux noeject noprompt
        initrd /boot/new/initrd.gz
}

■例えば「08_custom」に名前を変えれば、
 GRUBメニューで選択しなくてもインストーラが優先的に起動する。

 今回は3台目のバックアップ稼働マシンに設定したため、
 GRUBメニューでキーボードを使って選択することにする。

$ ls /etc/grub.d/
00_header        10_linux      30_os-prober  41_custom
05_debian_theme  20_linux_xen  40_custom     README

■GRUB2の設定反映と確認
 0,1,2はGRUBメニューの表示順。

$ sudo update-grub2
$ grep "menuentry" /boot/grub/grub.cfg | nl -w2 -v0 | sed s/"--"/"\n\t&"/g
 0	menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64' 
	--class debian 
	--class gnu-linux 
	--class gnu 
	--class os {
 1	menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)' 
	--class debian 
	--class gnu-linux 
	--class gnu 
	--class os {
 2	menuentry "Wheezy Installer" {

■後は普通のネットワークインストール。
 インストール先のディスクの選択はだいぶ後になって出てくるので間違えないようにご注意を。