标签归档:无盘系统

在家里做了个pxe服务器

参考:http://wiki.openwrt.org/doc/howto/tftp.pxe-server

https://wiki.archlinux.org/index.php/NFS_(简体中文)

http://archlinuxarm.org/forum/viewtopic.php?f=31&t=3854

https://wiki.archlinux.org/index.php/Tftpd_server

新到手了只pogoplug,只用来做samba的话感觉稍微有点浪费,偶尔看到了网络启动系统这种东西,于是也想做一个来玩。

材料:一个dhcp服务器,一个tftp服务器,一个nfs服务器。

网上很多教程都是让pxe服务器自己包揽全部工作,这让我不高兴,dhcp这东西就该由openwrt做,文件服务就该让pogo来做,但是网上相关的教程都没有分工的内容,于是看着很多教程,自己研究了一下,终于成功了。

pxe网络拓扑

 

首先,在openwrt上改动一下dnsmasq的配置

/etc/config/dhcp

在末尾加上一段

config boot linux
        option filename 'pxelinux.0'
        option serveraddress 'tftp服务器地址'
        option servername '服务器名称'

至于服务器名称有没有要求……这个没试过,就照着本地的DNS名称填好了。

好了之后,重启dnsmasq,openwrt端的服务就算完成了。

接下来是pogoplug这边:

首先,是tftp服务器。安装tftp-hpa软件包,然后修改

/usr/lib/systemd/system/tftpd.service

中的tftpd根目录

[Unit]
Description=hpa's original TFTP daemon

[Service]
ExecStart=/usr/sbin/in.tftpd -s /srv/tftp/
StandardInput=socket
StandardOutput=inherit
StandardError=journal

先用/srv/tftp/做例子,先去下载https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.02.tar.gz,然后解压。这里只需要里面的部分文件,包括这些:

syslinux-6.02/bios/core/pxelinux.0
syslinux-6.02/bios/com32/elflink/ldlinux/ldlinux.c32
syslinux-6.02/bios/com32/menu/vesamenu.c32
syslinux-6.02/bios/com32/lib/libcom32.c32
syslinux-6.02/bios/com32/libutil/libutil.c32

讲这几个文件拷贝到/srv/tftp/,然后在/srv/tftp/里面新建一个文件夹,来存放kernel和initrd。例如/srv/tftp/ubuntu,或者直接将ubuntu的镜像文件挂载到/srv/tftp/disks/ubuntu,可以让tftp客户端直接访问到。

然后,新建一个文件夹/srv/tftpd/pxelinux.cfg,在里面新建一个default的配置文件,内容如下:

DEFAULT vesamenu.c32
PROMPT 0
MENU TITLE OpenWRT PXE-Boot Menu

label Ubuntu
        MENU LABEL Ubuntu Live 13.10 64-Bit
        KERNEL disks/ubuntu/casper/vmlinuz.efi
        APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/extstorage/tftp/disks/ubuntu1310-64/ initrd=disks/ubuntu/casper/initrd.lz
        TEXT HELP
                Starts the Ubuntu Live-CD - Version 13.10 64-Bit
        ENDTEXT

说明文字可以自行更改,kernel和initrd会通过tftp获取,在获取到kernel和initrd之后,会通过nfs加载系统。

然后启动服务器

systemctl start tftpd.socket tftpd.service

如果需要自启动tftp服务器,则使用

systemctl enable tftpd.socket

至此,tftp服务器配置完成。

然后,是配置nfs服务器:

archlinux的nfs帮助似乎出了点问题,教程不是很完整,在网友的帮助下,发现原来服务没启动完成。

要安装nfs服务,需要安装nfs-utils。

然后,修改/etc/exports,这将会控制那些目录可以被访问,例如新增这段(根据上面pxelinnux的配置):

/mnt/extstorage/tftp/disks/ubuntu1310-64/ 192.168.1.0/24(ro,fsid=0,no_subtree_check)

将会允许192.168.1.*的客户端访问/mnt/extstorage/tftp/disks/ubuntu1310-64/。完成之后,用

systemctl enable nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service
systemctl start nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service

启动并自启动nfs服务器(吐槽:没密码真的大丈夫?)

配置过程中发生了许多问题,这里给后人稍微提供一下解决的思路:

1:openwrt的dnsmasq配置,有没有指向正确的tftp服务器,tftp服务器能不能访问;

2:nfs服务器的挂载有没有问题。

基本上都是权限或者配置文件出错……折腾了快2天……