Ubuntu8.04 on ML115をWake on LANで遠隔起動する

Ubuntuサーバを必要な時だけ起動するのであれば、Wake on LANで遠隔起動できるようにした方がいいだろう。常時起動しているCentOS5 on ML115なサーバから、Ubunt8.04 on ML115なサーバを遠隔起動させてみる。

まずUbuntu側の設定。ML115はBIOSのバージョンによってはWoLの有効/無効設定があるらしいが、うちの機材では特に設定項目はなかった。WoLはOSの機能ではなくてNICの機能であり、BIOSやOS上のツールからNICのレジスタ値を設定するかたちでの設定となる。Linuxではインターフェーススピードなどを指定する時につかうethtoolで設定する。ethtoolが入っていない場合は以下のようにしてインストールする。

ishii@ubuntu:~$ sudo aptitude install ethtool

WoLを有効にするコマンドは次の一行だ。

ishii@ubuntu:~$ sudo /usr/sbin/ethtool -s eth0 wol g

インターフェースの設定状態を見てみる。

ishii@ubuntu:~$ sudo ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x000000ff (255)
        Link detected: yes

Wake-on: gとあれば、Magic Packetを受け取ったときに起動する設定になっている。

この設定は起動するたびに再設定をしなければならない。そこでインターフェース設定の中にいっしょに書いてしまう。

ishii@ubuntu:~$ cat /etc/network/interfaces 
auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
gateway 192.168.0.2
ETHTOOL_OPTS="wol g"
auto eth0

ここまでできたらshutdown -h nowでUbuntuをシャットダウンする。

ではCentOSからUbuntuを遠隔起動しよう。ethtoolは標準でインストールされているはずだ。まずUbuntuのMACアドレスを調べる(一部伏せてます)。

[root@ml115 ~]# arp -a | grep 192.168.0.1
? (192.168.0.1) at 00:1E:0B:C1:XX:XX [ether] on eth0

そしてMACアドレスを引数にしてether-wakeコマンドをうつ。

[root@ml115 ~]# ether-wake 00:1E:0B:C1:XX:XX 

これだけでUbuntuは起動してくる。あとは上記のether-wakeコマンドを引数込みでスクリプトにしておけば、いちいちMACアドレスを調べなくてもコマンド一発で起動できるようになる。