Monday, April 23, 2007

[Linux] ต้องการ install ผ่าน network โดย boot ผ่าน PXE

เรื่องมีอยู่ว่าผมจะ install CentOS แต่ Download มาเป็น DVD แต่ว่าตัว server ดันไม่มี dvd drive เลยต้องลำบากหาวิธีที่จะ install เห็นมี install ผ่าน network โดยให้ server มัน boot ผ่าน PXE แล้ว install ผ่าน http (ไม่รู้ว่างานนี้ทำเวอร์เกินไปหรือเปล่า?)
ต้องมี
Notebook ผมเก็บตัว installer ต้อง enable service ดังนี้
interface eth0
$sudo ifconfig eth0 10.10.10.1 netmask 255.255.255.0 up

Web server (lighttpd)
$sudo apt-get install lighttpd
$sudo /etc/init.d/lighttpd start

download image ของ CentOS ชื่อ /tmp/CentOS-5.0-i386-bin-DVD.iso
$sudo mkdir -p /var/www/installer
$sudo mount -t iso9660 -o loop /tmp/CentOS-5.0-i386-bin-DVD.iso /var/www/installer

DHCP Service
$sudo apt-get install dhcpd3-server
$sudo vi /etc/dhcp3/dhcpd.conf
ddns-update-style none;
subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.100 10.10.10.200;
option routers 10.10.10.1;
filename="pxeboot/pxelinux.0";
}
$sudo /etc/init.d/dhcp3-server start

PXE Service
$sudo apt-get install pxe
$sudo /etc/init.d/pxe start

SYSLINUX
$sudo apt-get install syslinux

TFTP Service
$sudo apt-get install atftpd
$sudo mkdir -p /tftpboot/pxeboot
$sudo mkdir -p /tftpboot/pxeboot/CentOS_5.0_i386
$sudo cp /var/www/installer/images/pxeboot/vmlinuz /tftpboot/pxeboot/CentOS_5.0_i386
$sudo cp /var/www/installer/images/pxeboot/initrd.img /tftpboot/pxeboot/CentOS_5.0_i386
$sudo cp /usr/lib/syslinux/pxelinux.0 /tftpboot/pxeboot/ <-- file นี้เอามาจาก syslinux พอดีเครื่องผมใช้ ubuntu
$sudo mkdir -p /tftpboot/pxeboot/pxelinux.cfg

# config file สำหรับเลือก boot แยกแต่ล่ะ mac address หรือค่า default
$sudo vi /tftpboot/pxeboot/pxelinux.cfg/00-E0-4C-03-1D-08 <--- mac address ของ server
หรือ
$sudo vi /tftpboot/pxeboot/pxelinux.cfg/default

default CentOS_5.0_i386
timeout 10
prompt 1
display display.msg
label CentOS_5.0_i386
kernel CentOS_50_i386/vmlinuz
append initrd=CentOS_50_i386/initrd.img
หรือถ้ามี script kickstart
# append initrd=CentOS_50_i386/initrd.img ks=http://10.10.10.1/installer/anaconda.cfg
$sudo vi /tftpboot/pxeboot/display.msg
Linux installer via PXE boot:
CentOS_5.0_i386

$sudo chown -R nobody:nobody /tftpboot
$sudo /etc/init.d/atftpd start

ตอนนี้จัดเตรียมตัว install ไว้แล้ว
จากนั้นก็เอา server มาต่อ สาย lan แล้วให้ boot จาก lan card โดยให้ set ที่ bios
status มันก็จะ request DHCP แล้วก็จะได้ ip กลับไป
Linux installer via PXE boot:
CentOS_5.0_i386
boot:
ให้พิมพ์ดังนี้
boot: CentOS_5.0_i386 แล้ว enter
มันก็จะ boot แล้วเข้าสู่กระบวนการ install แล้วให้เราเลือก source ที่จะใช้ ผมเลือกใช้ http
มันจะถาม ip ของ web server และ directory
ip or name server: 10.10.10.1
directory: /installer/
แล้ว OK