Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6894895
  • 博文数量: 637
  • 博客积分: 10265
  • 博客等级: 上将
  • 技术积分: 6165
  • 用 户 组: 普通用户
  • 注册时间: 2004-12-12 22:00
文章分类

全部博文(637)

文章存档

2011年(1)

2010年(1)

2009年(3)

2008年(12)

2007年(44)

2006年(156)

2005年(419)

2004年(1)

分类: LINUX

2007-07-20 23:36:49

以前写过关于通过PXE启动PlanetLab的文章,可以在: http://blog.chinaunix.net/u/2389/showart_79066.html 找到,这篇文章是在上一篇文章的基础上修改的。

基本思路为:

使用闲置的eth1网卡用来网络启动,启动完毕后,通过dhcp client配置eth1的IP地址(dhcp服务器必须分配一个默认网关,通过默认网关的地址来判断tftp server的地址,方法比较土:P),然后从tftp根目录下载一个nodelist文件,主要包含节点配置文件的文件名和eth1网卡的MAC地址,下载完毕后根据本机eth1网卡的MAC来找到对应的配置文件位置所在,下载配置文件,命名成系统需要的文件名,关闭eth1网卡。

把上次弄好的initrd.img_PlanetLab复制到别的地方,然后改名为initrd.img_PlanetLab.gz
# cp initrd.img_PlanetLab /tmp/initrd.img_PlanetLab.gz
# cd /tmp
# gzip -d initrd.img_PlanetLab.gz
# mkdir initrd
# mount -o loop initrd.img_PlanetLab initrd
# cd initrd
# cat etc/redhat-release
Fedora Core release 2 (Tettnang) #从这里可以看出来,3.1是基于FC2的。
# cd etc/init.d
#  diff -u pl_netinit.org pl_netinit # 对pl_netinit的修改
--- pl_netinit.org      2007-07-17 11:16:24.000000000 +0800
+++ pl_netinit  2007-07-20 08:18:34.000000000 +0800
@@ -84,12 +84,55 @@
 # contain the validated contents
 find_node_config()
 {
+    # Getting IP address for eth1
+    echo "pl_netinit: Getting IP Address for eth1"
+
+    /sbin/ifconfig eth1 up
+
+    /sbin/dhclient eth1
+
     /bin/rm -f $TMP_OLD_FLOPPY_CONF_FILE 2>&1 > /dev/null

-    echo "pl_netinit: looking for node configuration file on floppy"
-
-    /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES /dev/fd0 \
-       $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
+    OLDPWD=`pwd`
+
+    cd $CONF_DEVICE_MOUNT_POINT
+
+    TFTPSERVER=`route -n | grep "^0.0.0.0" | tr -t '\t' ' ' | tr -s ' ' | cut -d ' ' -f 2`
+
+    /usr/bin/tftp -c get ${TFTPSERVER}:nodelist
+
+    if [ ! -s nodelist ]; then
+       echo "pl_netinit: Can't get nodelist file from TFTP server $TFTPSERVER"
+       /bin/sh
+       exit 1
+    fi
+
+    NODEID=`ifconfig eth1 | grep "HWaddr" | tr -t '\t' ' ' | tr -s ' ' | cut -d ' ' -f 5`
+
+    CONFFILE=`grep -i $NODEID nodelist | tr -t '\t' ' ' | tr -s ' ' | cut -d ' ' -f 2`
+
+    # Getting node conf file
+
+    /usr/bin/tftp -c get ${TFTPSERVER}:${CONFFILE}
+
+    CONFFILE=`basename $CONFFILE`
+
+    if [ ! -s "$CONFFILE" ]; then
+       echo "pl_netinit: Can't get node conf file from TFTP server $TFTPSERVER file $CONFFILE"
+       /bin/sh
+       exit 1
+    fi
+
+    # change file name
+    /bin/cp -f $CONFFILE $NEW_NODE_CONF_NAME
+    /bin/cp -f $CONFFILE /$NEW_NODE_CONF_NAME
+
+    # shutting down eth1
+
+    /sbin/ifconfig eth1 down
+
+    cd $OLDPWD
+
     if [[ $? -eq 0 ]]; then

         # 1. check for new named file first on the floppy disk
@@ -98,7 +141,6 @@

            conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
            /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
-           /bin/umount $CONF_DEVICE_MOUNT_POINT
            return 1

         # since we have the floppy mounted already, see if an old file
@@ -113,7 +155,6 @@
            echo "pl_netinit: floppy mounted, but no configuration file."
        fi

-       /bin/umount $CONF_DEVICE_MOUNT_POINT
     else
        echo "pl_netinit: no floppy could be mounted, continuing search."
     fi
@@ -149,13 +190,13 @@
                    conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
                    /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
                    echo "pl_netinit: found configuration"
-                   /bin/umount $CONF_DEVICE_MOUNT_POINT
+#                  /bin/umount $CONF_DEVICE_MOUNT_POINT
                    return 1
                fi

                echo "pl_netinit: not found"

-               /bin/umount $CONF_DEVICE_MOUNT_POINT
+#              /bin/umount $CONF_DEVICE_MOUNT_POINT
            fi
        done
     done
由于PlalnetLab的BootCD里面没有tftp客户端,所以我从FC2的系统中cp一个到/usr/bin目录下。

# cp /usr/bin/tftp /tmp/initrd/usr/bin/
# cd /tmp/initrd/etc/sysconfig/network-scripts/
# cat > ifcfg-eth1 <<__ELM__ #没有这个文件dhclinet eth1的时候会出错
DEVICE=eth1
ONBOOT=yes
__ELM__

呵呵,这个initrd文件就搞定了。
# cd /tmp/
# umount initrd
# gzip initrd.img_PlanetLab
# mv initrd.img_PlanetLab.gz /tftpboot/initrd.img_PlanetLab

下面准备tftp需要的文件吧。
# cd /tftpboot/
# cat > nodelist <<__ELM
00:11:85:5C:F2:60       conf/neu1.txt
00:11:85:5C:F2:8C       conf/neu2.txt
__ELM
# mkdir conf
# cd conf
neu1.txt neu2.txt 为从planetlab下载的pnode.txt,前面的MAC为eth1的MAC地址,通过MAC地址来判断该使用哪个配置文件。

呵呵,到这里就完事了,重新启动你的机器试试吧。
阅读(4921) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~