今天来说说 pxe,之前在Centos 安装 - 简书 (jianshu.com)中说过一些,但个人为这pxe的了解浅薄导致很多东西都不是很清楚,只是简单的描述,最近又看到了一些关于PXE的文章,对我有了很多的启发,现在将这些记录下来!
在pxe上intel有着一整套的定义,标准,之前一直没有找到相关的文档,今天看到一本pxespec,这中间将PXE启动做了详尽的描述:
PXE Boot
1. 2. 3. 4.
DHCP Discover ====> DHCP Offer ====> DHCP Request ======> DHCP Ack
4个步骤,看来和一般的DHCP是一样的,但却又多了不少的东西:
- PXE extension tags
- Other DHCP option tags
简单来说,就是在DHCP原有的基础上再加入了pxe相关的option
下面来看一下Proxy DHCP Service加入后的样子
1、在同一服务器上
The PXE DHCP options may be supplied by the DHCP service or a Proxy DHCP service. This Proxy DHCP service may reside on the same server as the DHCP service, or it may be located on a separate server. A Proxy DHCP service on the same server as the DHCP service is illustrated in Figure 2-3. In this case, the Proxy DHCP service is listening to UDP port (4011), and communication with the Proxy DHCP service occurs after completing the standard DHCP protocol. Proxy DHCP uses port (4011) because it cannot share port (67) with the DHCP service. The PXE client knows to interrogate the Proxy DHCP service because the DHCPOFFER from the DHCP service contains an Option #60 “PXEClient” tag without corresponding Option #43 tags or a boot file name.
==========================================
PXE DHCP选项可以由DHCP服务或代理DHCP服务提供。此代理DHCP服务可能与DHCP服务位于同一服务器上,也可能位于单独的服务器上。与DHCP服务位于同一服务器上的代理DHCP服务如图2-3所示。在这种情况下,代理DHCP服务正在侦听UDP端口(4011),并在完成标准DHCP协议后与代理DHCP服务进行通信。代理DHCP使用端口(4011),因为它无法与DHCP服务共享端口(67)。PXE客户端知道询问代理DHCP服务,因为DHCP服务的DHCPOFFER包含Option #60
“PXEClient”标记,而没有相应的Option #43
标记或引导文件名。
2、不在同一服务器上
Figure 2-4 illustrates the case of a Proxy DHCP service and the DHCP service on different servers. In this case, the Proxy DHCP service listens to UDP port (67) and responds in parallel with the DHCP service
===========================
图2-4说明了代理DHCP服务和不同服务器上的DHCP服务的情况。在这种情况下,代理DHCP服务侦听UDP端口(67),并与DHCP服务并行响应
一直...一直以来,我都使用着windows平台下的 Tiny PXE Server,它的集成度非常高,基本一站式的就能解决windows平台下使用PXE服务器的问题,而且十分的方便,现在的社会不是提倡以人(懒)为本(主)吗!在时代的召唤下, Tiny PXE Server就是我主要使用的工具,这个没毛病!!
在Centos 安装文章中提到了“代理dhcp”,说在liunx平台下,有一个pxe-pdhcp
的软件来提供Proxy DHCP功能,是我肤浅了,我都能想到的东西,在这个大神满地走的时代,怎么可能没有人想到呢?liunx下的dhcp服务程序早就提供了这样的功能,就像上面看到的一样,只是我....惭愧啊.....
之前对于dhcp服务程序没有什么了解,只有基本的认识,只知道它是一个分发ip地址的工具,对于DHCP-OPTION就更是没有一点的认识,今天我就要站在这里大声的说:“我还是不认识它!爱怎么招怎么招...”
Tiny PXE Server (mistyprojects.co.uk)这个东东过于强大,这里不做描述
Tiny PXE Server 好用是没有什么好说的( So easy! “完全就是哪里不会点哪里”)
- 在一个没有服务器的公司,直接一个压缩加上相应的共享就能使用 pxe 带来的快乐
- 在一个临时的地方,有几十台计算机要安装系统,
Tiny PXE Server
绝对是不二的选择 - 测试网络启动相关的功能,一通胡乱的修改,没有一点问题,有问题就重新解压一个
配置简单,操作可视,一个鼠标就搞出高大上的PXE server,老夫得此佳软,夫复何求啊! 啊!~
完
这就完了,当然不可能,开个小玩笑,要是这样我不用写这篇了
Tiny PXE Server 这么好用,那我又在这儿写这些干嘛呢?这就和我很早听过的一名话一样“每个你憧憬而又得不到的女神背后都有一个CTCDXT的男人”,它就是再好也有它的不足之处。
在企业应用中,服务器平台首选就是Linux,不是人为的设置壁垒,而是在真正的应用中,Linux有着Windows不能比拟的稳定性,君不见巨硬的发布会蓝屏事件,还有生活中无处不在的尴尬瞬间;
上面也说了,在一个临时的环境中,Tiny PXE Server是最佳的选择,但在一个固定的场景中,使用Linux平台就要好很多,我可不想开一个Windows服务器在那里,几十天后当我要用网启的时候,却发现怎么也启动不了,找了一圈的才找到原来是Windows出了问题,重启就好了,这看起来好像没有什么问题,但尴尬是一定的,方便更是无从说起了。
在这个环境下,要的就是这个pxe服务开起来,最好能干到公司over都不用去管它,它就默默地运行着,等着我的一次次召唤它。
本着将公司干over... 哦不,是本着懒人就要懒出境界的原则,下面我们来搞一搞这个Linux版的PXE 服务器
PXE服务器,有几个部分组成[1]
-
DHCP服务器/Proxy DHCP
负责提供给客户机IP,网关,还有引导服务器地址,引导的文件名,还有其它控制option -
tftp 服务器
提供简单的文件服务,最重要的就是提供一个引导文件如:pxeboot.n12(Windows自带),pxelinux.0(Linux常用 ),ipxe(推荐).... -
http/ftp服务器(可选)
最重要的是提供安装系统安装文件 或 启动中使用的大文件。
在要求启动过程在传输大文件时,http出tftp的数据有效性上有很大的优势,tftp使用了udp协议,无法保证传输质量,而http使用的是tcp协议,在启动中要启动一个1两个G的镜像,使用tftp可能会加载了半天,最后无法启动,这个尴尬了,也浪费时间 -
Samba服务器(可选)
在安装Windows时,我常常启动一个PE,再在pe下安装系统,这时,Windows安装文件这最好使用网络映射来提供,(当然使用U盘,移动硬盘也可以,但网启的意义何在???) - 暂时就想到这些...
当然也可以使用Cobbler等自动安装部署工具,这里不讨论
这里应该叫“一步一步手工打造一个PXE服务器 ”
其实部署一个pxe服务,并不难,在Centos 安装也有说过,之前最大的问题是Proxy DHCP环境中配置的问题
真实的使用环境中,企业已经有了dhcp服务器,我们就不能在这个环境中再部署一个,那样会破坏原来的网络架构,带来各种各样的网络问题,你一定会说那就修改原来的dhcp服务器不行吗?
- 如果是路由器、防火墙提供的dhcp服务 怎么办
- 如果没有dhcp服务器的权限 怎么办
之前Centos 安装提到 的pxe-pdhcp,但是这不是一个好的方案,只能临时使用。
说了这么多其实我是想在linux上使用iPXE,在此之前一直卡在,自动引导到iPXE的启动菜单(非内置embed方式)
现在找到了一个关于这个的描述[appnote:proxydhcp],让我又有了折腾linux下iPXE的兴趣,看了这篇文章,真得让我认识到自己的浅薄...
说了这么多废话,下面来部署它
Linux有很多版本,redhat系,Debian系都可以,当然使用一些轻量级的版本也是可以的,如Tiny Core Linux,这个不重要,可以根据自己的习惯来选择,而我自然是不走寻常路的。
我打算使用Tiny Core Linux 来加定制一个有pxe功能的live iso,说实话,这是我没事找事,我较熟悉的是Centos,但我偏不用,就是玩,还有企业中使用肯定不会用这个,有这个想法只是测试功能和玩,
坑不是一般的多,下面听我一一道来:
初体验[2]
下载一个Tiny Core Linux,本着怎么小怎么来的原则,下载了“Core-12.0.iso”,没有gui的版本,只用区区16M,使用vmware光盘启动,不错,看起来还可以,使用busybox,可以正常dhcp获得ip,正常上网,很好...
坑 一: #####时区问题:
在中国地区使用,时间上差了8个小时
在/etc/profile文件中增加一行export TZ='CST-8'
使文件立即生效
source /etc/profile 或者 . /etc/profile
然后就是试着安装服务软件,第一个sshd,使用过linux的人都知道,没有ssh的痛,查官方,推荐使用图形界面,命令还不好找,我去,baidu 一下,有了
在无忧上看到有人说起了这个,谢谢分享
Linux | 尋找 | 查詢詳情 | 安裝 | 卸載移除 |
---|---|---|---|---|
RH | yum search XXX | yum info YYY | yum install YYY | yum remove YYY |
DB | apt search XXX | apt info YYY | apt install YYY | apt remove YYY |
TC | tce-ab (Enter後選"S"earch填入) | tce-ab ('S'earch完選取即可見) | tce-load -wi YYY | tce-remove YYY |
看来tiny core linux有一套自己的扩展库,也可以,开造
这里发现tce-ab,就是tce,又可以少输入三个字符,快乐就是这么的简单
安装的第一个软件要记录一下
$ tce
接着输入 “s”,再输入“ssh”
这里可以看到,有openssh,还可以嘛
选 “5”
一堆介绍, “q”
“i” 安装
这就安装完成了,可以看到tiny core linux的安装包是“.tcz
”,也就是说,它自己有自己的包管理系统,和redhat系和Debian系不一样
好了不要在意这些细节,go on
ssh配置[3]
在之前的软件介绍中,可以看到
启动脚本:
/usr/local/etc/init.d/openssh
配置文件:
/usr/local/etc/ssh/ssh_config
/usr/local/etc/ssh/sshd_config
我们要使用的是sshd,在Linux中一般的软件安装后都会提供模版配置文件,很多都是进行简单的修改或不进行修改都使用
看这不是找到了吗?搞它
cp /usr/local/etc/ssh/sshd_config{.orig,}
报错,我去
忘了这个不是bash,老老实实的写命令吧
好了,现在有配置文件了,启动试试
.....
看来是成功开启了sshd服务了,22端口也打开了,下面就是连接
要连接,就要有密码
$ sudo passwd tc
使用ssh客户端
ssh tc@192.168.0.39
ssh tc@192.168.0.39
Warning: Permanently added '192.168.0.39' (RSA) to the list of known hosts.
X11 forwarding request failed on channel 0
( '>')
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY.
(/----) www.tinycorelinux.net
tc@box:~$
看我们这就搞定了sshd,下面就简单了,一阵操作猛如虎...
等等先看一下当前安装的东东,因为官网的wiki要注册,看不到只能写我自己的理解,有什么不对请指证
这个是下载软件包的目录
tc@box:~$ ll /tmp/tce/optional/
total 3196
-rw-r--r-- 1 tc staff 1409024 Dec 27 02:18 openssh.tcz
-rw-r--r-- 1 tc staff 18 Dec 27 02:18 openssh.tcz.dep
-rw-r--r-- 1 tc staff 46 Dec 27 02:18 openssh.tcz.md5.txt
-rw-r--r-- 1 tc staff 1851392 Dec 27 02:18 openssl-1.1.1.tcz
-rw-r--r-- 1 tc staff 52 Dec 27 02:18 openssl-1.1.1.tcz.md5.txt
========================================================
这个是当前在使用的扩展软件包的目录
tc@box:~$ ll /tmp/tcloop/
total 0
drwxr-xr-x 3 tc staff 26 Mar 3 2021 openssh/
drwxr-xr-x 3 tc staff 26 Feb 18 2021 openssl-1.1.1/
下面再来猛如虎...
安装 dnsmasq httpd samba
为什么要samba呢,这个玩意好大,在安装windows的时候,我一般会启动一个pe环境来进行安装,这时的安装文件就要使用samba来提供,为什么启动pe,这个只能说经过血的教训后,对自动安装不感冒了,除了没有数据的微机室,我是不敢自动的
tc@box:~$ ll /tmp/tcloop/
total 0
drwxr-xr-x 3 tc staff 26 Nov 5 2018 acl/
drwxr-xr-x 3 tc staff 26 Nov 5 2018 attr/
drwxr-xr-x 3 root root 26 Aug 10 2013 busybox-httpd/
drwxr-xr-x 3 tc staff 26 May 31 2021 dbus/
drwxr-xr-x 3 root root 26 Dec 4 2010 dnsmasq/
drwxr-xr-x 3 tc staff 26 Dec 23 2020 expat2/
drwxr-xr-x 3 tc staff 26 Dec 23 2020 gcc_libs/
drwxr-xr-x 3 tc staff 26 Dec 27 2020 glib2/
drwxr-xr-x 3 tc staff 26 Dec 23 2020 gmp/
drwxr-xr-x 3 tc staff 26 Apr 11 2020 gnutls3.6/
drwxr-xr-x 3 tc staff 26 Jan 9 2021 libavahi/
drwxr-xr-x 3 tc staff 26 Jan 8 2020 libcups/
drwxr-xr-x 3 tc staff 26 Dec 24 2020 libffi/
drwxr-xr-x 3 tc staff 26 Aug 19 2019 libidn2/
drwxr-xr-x 3 tc staff 26 Apr 2 2018 libtasn1/
drwxr-xr-x 3 tc staff 26 Aug 13 2014 libunistring/
drwxr-xr-x 3 tc staff 26 Dec 24 2020 ncursesw/
drwxr-xr-x 3 tc staff 26 Apr 11 2020 nettle3/
drwxr-xr-x 3 tc staff 26 Mar 3 2021 openssh/
drwxr-xr-x 3 tc staff 26 Feb 18 2021 openssl-1.1.1/
drwxr-xr-x 3 tc staff 26 Jan 5 2021 p11-kit/
drwxr-xr-x 3 root root 26 Sep 28 2014 popt/
drwxr-xr-x 3 tc staff 26 Sep 16 2016 samba3/
drwxr-xr-x 3 tc staff 26 Jul 27 2016 samba3-libs/
drwxr-xr-x 3 root root 26 Jan 8 2018 tree/
=================================================
tc@box:~$ du -s /tmp/tcloop/
110.8M /tmp/tcloop/
这么大,mini的优势在哪里,我自闭了
当然也可以使用其它服务器来提供samba文件服务,我这儿是要做一个一体化的demo
继续,下面一个一个的来
dnsmasq[4]
Example config file located at /usr/local/etc/dnsmasq.conf.example
dnsmask defaults to /etc/dnsmask.conf. To override the default, use:
dnsmasq --conf-file=/usr/local/etc/dnsmasq.conf
注意:
- dnsmasq的配置文件默认位置在/etc/dnsmasq.conf
- 使用命令启动可前台运行dnsmasq,查看日志
sudo dnsmasq --no-daemon --conf-file=/usr/local/etc/dnsmasq.conf
--no-daemon:不以守护进程运行,前台运行,用于调试,可看到运行情况
--conf-file: 配置文件位置
坑 这是在定制iso后,出现的
# sudo /usr/local/sbin/dnsmasq --no-daemon -C /usr/local/etc/dnsmasq.conf
报错
dnsmasq: cannot open or create lease file /var/lib/misc/dnsmasq.leases: No such file or directory
解决:手工建立一个/var/lib/misc目录
#sudo mkdir /var/lib/misc
下面附上dnsmasq.conf
# Known working dnsmasq version 2.85 config for iPXE proxydhcp usage
# Debug logging
#log-dhcp #详细dhcp信息可打开
#log-facility=/var/log/dnsmasq/dnsmasq.log
log-queries
log-facility=/var/log/dnsmasq.log
# Disable DNS server
port=0
# send disable multicast and broadcast discovery, and to download the boot file immediately
# DHCP_PXE_DISCOVERY_CONTROL, should be vendor option? Needs more understanding and source
dhcp-option=vendor:PXEClient,6,2b # 2b 数值2 类型bit # "kill multicast"
# This range(s) is for the public interface, where dnsmasq functions
# as a proxy DHCP server providing boot information but no IP leases.
# Any ip in the subnet will do, so you may just put your server NIC ip here.
dhcp-range=192.168.0.0,proxy
interface=eth0
# bind-dynamic - remove interface and use this instead to listen everywhere?
# Disable re-use of the DHCP servername and filename fields as extra
# option space. That's to avoid confusing some old or broken DHCP clients.
dhcp-no-override
#dhcp-match=set:<tag>,<option number>|option:<option name>|vi-encap:<enterprise>[,<value>]
#dhcp-boot=[tag:<tag>,]<filename>,[<servername>[,<server address>|<tftp_servername>]]
# Based on logic in https://gist.github.com/robinsmidsrod/4008017
# iPXE sends a 175 option, checking suboptions
dhcp-match=set:ipxe-http,175,19
dhcp-match=set:ipxe-https,175,20
dhcp-match=set:ipxe-menu,175,39
# pcbios specific
dhcp-match=set:ipxe-pxe,175,33
dhcp-match=set:ipxe-bzimage,175,24
dhcp-match=set:ipxe-iscsi,175,17
# efi specific
dhcp-match=set:ipxe-efi,175,36
# combination
# set ipxe-ok tag if we have correct combination
# http && menu && iscsi ((pxe && bzimage) || efi)
tag-if=set:ipxe-ok,tag:ipxe-http,tag:ipxe-menu,tag:ipxe-iscsi,tag:ipxe-pxe,tag:ipxe-bzimage
tag-if=set:ipxe-ok,tag:ipxe-http,tag:ipxe-menu,tag:ipxe-iscsi,tag:ipxe-efi
#pxe-service=[tag:<tag>,]<CSA>,<menu text>[,<basename>|<bootservicetype>][,<server address>|<server_name>]
#pxe-prompt=[tag:<tag>,]<prompt>[,<timeout>]
# these create option 43 cruft, which is required in proxy mode
# TFTP IP is required on all dhcp-boot lines (unless dnsmasq itself acts as tftp server?)
pxe-service=tag:!ipxe-ok,X86PC,PXE,undionly.kpxe,192.168.0.39
pxe-service=tag:!ipxe-ok,IA32_EFI,PXE,snponlyx32.efi,192.168.0.39
pxe-service=tag:!ipxe-ok,BC_EFI,PXE,snponly.efi,192.168.0.39
pxe-service=tag:!ipxe-ok,X86-64_EFI,PXE,snponly.efi,192.168.0.39
# later match overrides previous, keep ipxe script last
# server address must be non zero, but can be anything as long as iPXE script is not fetched over TFTP
# dhcp-boot=tag:ipxe-ok,http://boot.ipxe.org/demo/boot.php,,0.0.0.1
dhcp-boot=tag:ipxe-ok,boot.ipxe,,192.168.0.39
# To use internal TFTP server enabled these, recommended is otherwise atftp
enable-tftp
tftp-root=/tmp/locdisk1/ipxe
httpd[5]
这是一个Busybox版本的httpd,
Comments: Busybox's httpd applet.
Files installed:
/usr/local/httpd/bin/busybox
/usr/local/httpd/bin/false (symlink)
/usr/local/httpd/sbin/httpd (symlink)
False has been built but is not strictly needed - it comes in handy if chrooting httpd
To start:
sudo /usr/local/httpd/sbin/httpd -p port_number -h document_home_directory -u user:group
Where:
port_number is the port for httpd to listen on (default is 80)
document_home_directory is the directory containing your index.html (you'll need to make one)
user is the user you want httpd to run as eg. 'tc' (default is root)
group is the group 'user' is a member of eg. 'staff'
For example:
sudo /usr/local/httpd/sbin/httpd -p 80 -h /home/tc/htdocs -u tc:staff
精简到极点的一个httpd服务,没有什么配置的,使用命令启动,提供参数
-p: 端口
-h: http的“/”目录
-u: httpd所属的用户和组
例:
sudo /usr/local/httpd/sbin/httpd -p 80 -h /tmp/locdisk1/ipxe
注意:使用时要有index.html
getindex[6]
自动生成当前目录及下级目录的index.html
自建目录可用,使用ln -s /mnt/cd/ipx/* /tmp/ipxe/
,下级目录不能使用,因为这是光盘目录,最后这个不是问题
# getindex.sh
function writeli()
{
local main=$1/index.html
cat /dev/null > $main
#echo '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><title>'$1'</title></head><body><h1>'$1'</h1><pre>' > $main
echo '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">' > $main
if [ $1 != '.' ];
then
echo '<title>Index of '${1:1}'</title></head><body><h1>Index of '${1:1}'</h1><hr><pre>' >> $main
echo '<a href="../">../</a>' >> $main
else
echo '<title>Index of /</title></head><body><h1>Index of /</h1><hr><pre>' >> $main
fi
files=`ls -X $1`
echo open $1 getting index..
echo main is $main
for file in $files
do if [ -d $1/$file ] #&& [ $file != 'getindex.sh' ];
then
#ls -d --full-time $1/$file |awk '{printf "<a href=\"%s\">%s</a> %60s %s\n",$9,$9,$6,$7}' >> $main
echo -e '<a href="'$file'">\c' >> $main
ls -d --full-time $1/$file |awk -F '[ /]+' '{printf "%-50s%-10s %s %s\n",$NF,"-",$6,$7}' |sed 's@^\([0-9a-zA-Z\._-]*\)@\1/</a>@' >> $main
#oldpath=$1/index.html
writeli $1/$file
echo after return $main
#main=$oldpath
elif [ $file != 'getindex.sh' ] && [ $file != 'index.html' ];
then
#echo '<li><a href="'$file'">'$file'</a></li>' >> $main
#echo '<li><a href="'$file'">'`ls --full-time $1/$file |awk '{printf "%-20s %-10s %-10s\n",$9,$6,$7}'`'</a></li>' >> $main
#echo '<li><a href="'$file'">' >> $main
#ls --full-time $1/$file |awk '{printf "<a href=\"%s\">%s</a> %60s %s\n",$9,$9,$6,$7}' >> $main
echo -e '<a href="'$1/$file'">\c' >> $main
#ls --full-time $1/$file |awk -F '[ /]+' '{printf "%60s %s %s\n",$NF,$6,$7}' >> $main
#ls --full-time $1/$file |awk -F '[ /]+' '{printf "%-60s %s %s\n",$NF,$6,$7}' |sed 's@^\([0-9a-zA-Z\._-]*\)@\1</a>@' >> $main
ls -h --full-time $1/$file |awk -F '[ /]+' '{printf "%-50s %-10s %s %s\n",$NF,$5,$6,$7}' |sed 's@^\([0-9a-zA-Z\._-]*\)@\1</a>@' >> $main
#echo '</a></li>' >> $main
fi
done
echo '</pre></body></html>' >> $main
return
echo $1 callback.
}
writeli "."
samba[7]
Comments: Samba provides file and print services using the SMB/CIFS protocol,
for DOS and Windows, OS/2, Linux and others
----------
Howto:
edit /usr/local/etc/samba/smb.conf as required
----------
To control samba nmbd/smbd:
$ sudo /usr/local/etc/init.d/samba [start|stop|restart|status]
配置,
[global]
workgroup = WORKGROUP
server string = IPXE Samba Server
netbios name = MY-IPXE-Samba
map to guest = Bad User
load printers = no
log level = 2
log file = /var/log/samba/log.%m
max log size = 50
dns proxy = no
; 下面三行,让Samba服务器支持访问软连接文件和目录
wide links = yes
follow symlinks = yes
unix extensions = no
[ShareDir]
path = /tmp/locdisk1/
read only = yes
guest ok =yes
[ShareDir]中 path为我们共享的目录,自行修改
在使用中,发现一个花了我一天时间的问题,就是samba的共享目录在我使用的win10pe中不能使用net use来映射目录。查了很多资料都要放弃了,最后还是找到了一个还算满意的解决方案!
root@box:/home/tc# smbd -V
Version 4.6.3
这个版本的samba,在win10pe使用 net use时,提示
system error 58 has occurred
无法映射samba的共享目录
方法1:
smb.conf中加入,可以连上,但有个大问题,就是正常的win10系统无法使用,而且启动win10自带的pe也不能连接。
server min protocal = NT1
server max protocal = NT1
# Default: server min protocol = SMB2_02
# Default: server max protocol = SMB3
方法2:
在win10pe中使用PEnetwork.exe,pe网络配置程序可以连接共享目录,但没有找到它的命令行参数
方法3:(推荐)
使用 net use时带上samba服务器中有的用户名
net use i: \\server\share /user:user password
where user is a system user, it works.
当前使用这种方法,命令如下:
net use Y: \\%serverip%\SharedDir /user:tc ""
又发现一个问题,smbclient不能用,报错缺少so文件 ,下载了readline7.tcz,得到了libreadline.so.7.0,但libtinfo.so.6 找不到,下载了ncurses,也找不到,最后才知道在tinycore中,就直接使用libncurses就可以了
# cd /usr/local/lib
# ln -sv libncursesw.so.6.2 libtinfo.so.6
# ln -sv libreadline.so.7.0 libreadline.so.7
# /usr/local/lib$ ll libtinfo.* libncurses* libreadline.*
lrwxrwxrwx 1 root root 18 Dec 29 11:55 libncurses++w.so -> libncurses++w.so.6
lrwxrwxrwx 1 root root 20 Dec 29 11:55 libncurses++w.so.6 -> libncurses++w.so.6.2
-rwxr-xr-x 1 root root 69000 Dec 29 11:55 libncurses++w.so.6.2
lrwxrwxrwx 1 root root 16 Dec 29 11:55 libncursesw.so -> libncursesw.so.6
lrwxrwxrwx 1 root root 18 Dec 29 11:55 libncursesw.so.6 -> libncursesw.so.6.2
-rwxr-xr-x 1 root root 367440 Dec 29 11:55 libncursesw.so.6.2
lrwxrwxrwx 1 root root 18 Dec 29 11:57 libreadline.so.7 -> libreadline.so.7.0
-rwxr-xr-x 1 root root 296616 Dec 29 11:55 libreadline.so.7.0
lrwxrwxrwx 1 root root 18 Dec 29 11:57 libtinfo.so.6 -> libncursesw.so.6.2
再在 tftp-root目录下加上,启动文件和启动菜单就OK了
tc@box:/tmp/locdisk1/ipxe$ ls
boot.ipxe snponly.efi undionly.kpxe
到这里,一个pxe服务器基本搭建完成了。
测试
开两个虚拟机一个bios,一个uefi
1 . 启动时,dnsmasq分发的ipxe文件后面自动加".0
"后缀
- 在tftp-root目录下,给ipxe启动文件加0
2 . 在uefi启动时不能正确获得boot.ipxe启动菜单,进入ipxe环
- 当前版本的dnsmasq对uefi支持不好,怎么升级没有搞
定制iso[8]
1.挂载iso到本机
# mount -t iso9660 -o loop Core-current.iso /mnt/cd
2.将光盘里内容拷贝到本地硬盘下,以便修改
# cp /mnt/cd/* xxx/hislinuxiso/ -r
3.可以添加修改core.gz结尾的文件,该文件一般都是由cpio格式打包又压缩成.gz格式的(可以通过file查看类型),先重命名
# mv core.gz core.cpio.gz
4.解压
# gunzip core.cpio.gz
5.新建目录newcore作为修改的目录,并进入该目录
# mkdir newcore
# cd newcore/
6.将上级的core.cpio解压到该目录下
# cpio -i -F ../core.cpio
7.在newcore里修改需要修改的文件等
=============================
当前规划:
1. # sudo cp -r /tmp/tcloop/*/* ./ # 将当前安装的包复制到newcore中
2. 复制 或 编辑相关配置文件
3. 编写开机运行脚本 ./opt/bootlocal.sh
3.1. 开机自动生成/mnt/cd目录,挂载/dev/cdrom
3.2. # mkdir /tmp/ipxe
3.3. # ln -s /mnt/cd/ipxe/* /tmp/ipxe
3.4. ipxe启动菜单,复制过来,+w, 这样可根据自己获取的ip来,设置next-server,及其它设置
3.5. 系统启动时自动修改配置文件中的 本服务器ip和tftp、http、samba目录
3.6. 启动服务程序(如果dnsmasq使用前台运行,那dnsmasq要最后运行)
4. 将当前系统的ssh key 导入newcore中,这种不用每次启动sshd时生成key
# sudo cp /usr/local/etc/ssh ./usr/local/etc/ssh
5. 设置tc的密码
# sudo passwd tc
# sudo cp /etc/shadow ./etc/shadow
6. boot上级加入ipxe目录,导入ipxe启动文件和脚本
=============================
8.重新开始打包成cpio文件
# find . | cpio -o -H newc > ../newcore.cpio
or(改变不了目录结构)
# cpio -i -t -F ../core.cpio>list
# cpio -o -H newc -O newcore.cpio<list
9.重新打包压缩
# gzip -9 newcore.cpio
10.重命名成原来的文件名
# mv newcore.cpio.gz core.gz
11.制作成光盘镜像ISO,在boot的上一级目录
# mkisofs -r -V "My Tiny Core LINUX" -cache-inodes -J -l \
-b boot/isolinux/isolinux.bin \
-c boot/isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 \
-boot-info-table -o "../MyCoreiso.iso" .
当前光盘目录结构:
# tree /mnt/cd/
/mnt/cd/
|-- boot
| |-- core.gz
| |-- isolinux
| | |-- boot.cat
| | |-- boot.msg
| | |-- f2
| | |-- f3
| | |-- f4
| | |-- isolinux.bin
| | `-- isolinux.cfg
| `-- vmlinuz
`-- ipxe
|-- boot.ipxe
|-- snponly.efi.0
`-- undionly.kpxe.0
下面附上开机脚本: /opt/bootlocal.sh
#!/bin/sh
# put other system startup commands here
sudo mkdir /mnt/cd
sudo mount /dev/cdrom /mnt/cd
#sudo mkdir /tmp/locdisk1
#sudo mount /dev/sda1 /tmp/locdisk1
sudo mkdir /tmp/nginx
sudo mkdir /tmp/ipxe
sudo ln -s /mnt/cd/ipxe/* /tmp/ipxe
sudo cp /mnt/cd/ipxe/boot.ipxe /tmp/ipxe
sudo chmod +w /tmp/ipxe/boot.ipxe
#cd /tmp/ipxe
#sudo ./getindex.sh
# Set Which Directory Will be Shared
# sharedir="/tmp/locdisk1/ipxe"
export sharedir="/tmp/ipxe"
# Set Samba shard Dir
export smbsharedir="/tmp/ipxe"
# get host ip and set the conf files
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo local host ip is [$pc_ip] ...
while [ "$pc_ip" = "" ]
do
echo enter the loop.. sleep 2 sec
sleep 2
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo now get ip is [$pc_ip]
done
echo "modify /etc/dnsmasq.conf"
sudo sed -i -r "s/([0-9]{1,3}\.){3}[0-9]{1,3}/$pc_ip/g" /etc/dnsmasq.conf
sudo sed -i "s@tftp-root=.*@tftp-root=$sharedir@" /etc/dnsmasq.conf
echo "modify $sharedir/boot.ipxe"
sudo sed -ri "s#iseq.* set next-server.*#iseq \$\{next-server\} $pc_ip || set next-server $pc_ip#" $sharedir/boot.ipxe
echo "modify /usr/local/etc/samba/smb.conf Share dir is $smbsharedir"
sudo sed -i "s@path = .*@path = $smbsharedir@" /usr/local/etc/samba/smb.conf
# 1. start sshd
echo "sshd starting..."
sudo /usr/local/etc/init.d/openssh start
# 2. start busbox-httpd
echo "httpd starting... The rootpath is: $sharedir"
sudo /usr/local/httpd/sbin/httpd -p 80 -h $sharedir
echo now! the connect ip is [$pc_ip]
# 3. start Samba Server
echo "Samba Server starting... path: $smbsharedir"
sudo /usr/local/etc/init.d/samba start
# 4. start dnsmasq
sudo dnsmasq --no-daemon
测试iso, 不错运行正常,iso启动就能正常进入pxe服务状态
大功告成!!! 哇哈哈。。。
将此iso,拷入U盘,找一个实机测试,beautiful,基本完美,我兴奋,我GC,再试两个,嗯,不能启动,啥情况,看看目录结构
没有EFI我那个大去,不能uefi启动,如果之前dnsmasq对uefi的pxe启动支持还能接受,那现在这个就是残疾,对强迫症的我来说,这就没有使用价值了
这么一个算发行版吧,包管理都有,应该是有的吧,我去tinycore的官网找了找,有64位的,下来看看,没有,还是没有efi,我心里有一万只草泥马在奔跑,在嘶叫.....
又去找吧,找了syslinux,说明支持uefi,但怎么用,不知道,找了mkisofs,一堆的选项,我觉得没有几个人能将它看完,又找了国内的资料,有大神分享制作bios/uefi两启光盘的工具,但是没有讲怎么回事,我也是个急性子,两搞三搞就没有心情去一一的了解原理了。
当然NB如我,一定是想得到办法的嘛,去下了一个Centos的CentOS-7-x86_64-NetInstall.iso,这个光盘是能够双启的,使用拿来大法,改嘛。。。
分析一个目录结构
目录 | 说明 |
---|---|
isolinux/ | bios的启动目录 |
isolinux/isolinux.cfg | bios 的启动配置文件 |
EFI/ | uefi的启动目录 |
EFI/BOOT/grub.cfg | uefi的启动配置文件 |
下载CorePure64-12.0.iso一个纯64位的Tiny Core Linux
使用这个64位的TinyCore iso中的文件替换到Centos光盘isolinux/目录中的Kernel 和 ramdisk文件
修改配置文件指向新Kernel 和 ramdisk文件
测试,BIOS 和 UEFI 都能使用,不错不错...
下面就是
- 安装ssh, httpd, dnsmasq, samba
- 修改core
- 编辑修改配置文件 和 开机启动文件
到这里,再次发现64拉的Tiny Core Linux和32位的使用tce
得到的,软件列表不一样,没有“Busybox-httpd”,还好有个nginx,同样操作安装,改配置,测试
nginx[9]
Title: nginx.tcz
Comments: Config files: /usr/local/etc/nginx
----
Use /usr/local/etc/init.d/nginx to start/stop
----
nginx的原始配置文件如下:
tc@box:~$ ll /usr/local/etc/nginx/original/
total 28
-rw-r--r-- 1 root root 1077 Dec 26 19:08 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 Dec 26 19:08 fastcgi_params.default
-rw-r--r-- 1 root root 5231 Dec 26 19:08 mime.types.default
-rw-r--r-- 1 root root 2656 Dec 26 19:08 nginx.conf.default
-rw-r--r-- 1 root root 636 Dec 26 19:08 scgi_params.default
-rw-r--r-- 1 root root 664 Dec 26 19:08 uwsgi_params.default
在这个简单的http服务中我们只用到mime.types.default和nginx.conf.default
sudo cp /usr/local/etc/nginx/original/mime.types.default /usr/local/etc/nginx/mime.types
sudo cp /usr/local/etc/nginx/original/nginx.conf.default/usr/local/etc/nginx/nginx.conf
配置可以浏览器中直接打开 txt 文本文件,修改nginx.conf中的server
/usr/local/etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
root /tmp/ipxe; #指定目录所在路径
autoindex on; #开启目录浏览
autoindex_format html; #以html风格将目录展示在浏览器中
autoindex_exact_size off; #切换为 off 后,以可读的方式显示文件大小,单位为 KB、MB 或者 GB
autoindex_localtime on; #以服务器的文件时间作为显示的时间
}
# 浏览器中直接打开 txt
修改mime.types,添加plist扩展名为text/plain类型,直接显示文本。
在文件中添加如下内容
text/plain plist;
/usr/local/etc/nginx/nginx.conf
#include mime.types; ---to--> include mime.types;
到这里基本完成了
最后一些调整
- SSHD
sftp子系统,使用internal-sftp
因为使用"internal-sftp"在ssh客户端才能正常的传文件
/usr/local/etc/ssh/sshd_config
Subsystem sftp internal-sftp
- 建立服务启动需要的目录,封装后第一次启动根据出错信息建立
tc@box:~$ ls /var/lib/
misc/ samba/ sshd/
64位的dnsmasq 升级了 Version: 2.79
现在在uefi启动中可以正常的获取boot.ipxe脚本文件,同时ipxe启动文件也不会自动加
.0
,这不是更加完美了吗?
到目前为止,这个live的pxe服务器,开机就能启动pxe服务和samba服务,光盘目录结构如下:
$ ll /mnt/cd/
total 6
dr-xr-xr-x 3 root root 2048 Oct 27 2020 EFI/ # UEFI启动目录,只包含启动菜单文件
dr-xr-xr-x 6 root root 2048 Dec 26 11:10 ipxe/ # iPXE的目录,包含ipxe和winpe还有tools
drwxr-xr-x 2 root root 2048 Oct 27 2020 isolinux/ # BIOS启动目录,包含启动菜单,Kernel,ramdisk等
# tree /mnt/cd/
/mnt/cd/
|-- EFI
| `-- BOOT
| `-- grub.cfg
|-- ipxe
| |-- README1.txt
| |-- README2.txt
| |-- app
| | `-- netgrubfm
| | |-- fmcore
| | |-- httpfm.0
| | |-- netgrubfm.efi
| | |-- netgrubfm.ipxe
| | |-- netgrubfm.pcbios
| | `-- pxefm
| |-- boot
| | |-- BOOTICEx86.exe
| | |-- Fonts
| | | |-- chs_boot.ttf
| | | `-- wgl4_boot.ttf
| | |-- README.txt
| | |-- bcd
| | |-- bme
| | |-- boot.sdi
| | |-- bpe
| | |-- img
| | | `-- MAXDOS9.IMG
| | |-- memdisk
| | |-- memtest.exe
| | |-- menu.ipxe
| | |-- pe64.wim
| | |-- pxeboot.n12
| | |-- ume
| | |-- upe
| | |-- wimboot
| | |-- wimboot.i386
| | |-- wimboot.x86_64
| | `-- zh-CN
| | |-- bootia32.efi.mui
| | |-- bootmgr.efi.mui
| | |-- bootmgr.exe.mui
| | |-- bootx64.efi.mui
| | |-- memtest.efi.mui
| | `-- memtest.exe.mui
| |-- boot.ipxe
| |-- bootmgr
| |-- bootmgr.exe
| |-- efi
| | |-- boot
| | | |-- README.txt
| | | |-- bootia32.efi
| | | |-- bootia321.efi
| | | |-- bootx64.efi
| | | |-- bootx641.efi
| | | |-- grubx64.efi
| | | `-- zh-CN
| | | |-- bootia32.efi.mui
| | | |-- bootmgr.exe.mui
| | | `-- bootx64.efi.mui
| | `-- microsoft
| | `-- boot
| | |-- bcd
| | |-- fonts
| | | |-- chs_boot.ttf
| | | `-- wgl4_boot.ttf
| | |-- memtest.efi
| | |-- memtest32.efi
| | |-- resources
| | | `-- bootres.dll
| | `-- zh-CN
| | |-- memtest.efi.mui
| | `-- memtest32.efi.mui
| |-- getindex.sh
| |-- pxeautorun.txt
| |-- snponly.efi
| |-- sources
| | |-- boot.sdi
| | |-- boot.wim
| | |-- install.bat
| | `-- winpeshl.ini
| `-- undionly.kpxe
`-- isolinux
|-- TRANS.TBL
|-- boot.cat
|-- boot.msg
|-- corepure64.gz
|-- grub.conf
|-- isolinux.bin
|-- isolinux.cfg
|-- memtest
|-- splash.png
|-- vesamenu.c32
`-- vmlinuz64
ipxe目录是直接从我用的Tiny PXE Server中复制过来只删除了pe32.wim,比较乱,但不打算改变,这样可以做到两个平台的配置一样,不用去两边改,就这样!
这是一个功能demo,不要用在生产环境,因为这只是做功能,没有安全相关的配置,生产中使用请自行加上安全、认证相关配置再上线
不要用在生产环境
不要用在生产环境
不要用在生产环境
三遍了,我说的一定要听!!!
最后附上所有的脚本, 配置文件[10]
- sshd
$ grep sftp /usr/local/etc/ssh/sshd_config
Subsystem sftp internal-sftp - dnsmasq
上面已附 - httpd or nginx
上面已附 - samba
上面已附 - 脚本
5.1 getindex.sh脚本用于生成index.html,上已附
5.2 /opt/中的脚本
tc@box:~$ ll /opt/
total 36
-rwxr-xr-x 1 root staff 1895 Dec 26 19:08 bootlocal.sh #自定义脚本
-rwxr-xr-x 1 root root 272 Dec 26 19:08 bootsync.sh
-rwxr-xr-x 1 root staff 1180 Dec 26 19:08 myreservers.sh #自定义脚本
-rwxr-xr-x 1 root staff 1705 Dec 26 19:08 restart-dnsmasq.sh #自定义脚本
-rwxr-xr-x 1 root staff 1391 Dec 26 19:08 restart-httpd.sh #自定义脚本
-rwxr-xr-x 1 root staff 1410 Dec 26 19:08 restart-nginx.sh #自定义脚本
-rwxr-xr-x 1 root staff 1454 Dec 26 19:08 restart-samba.sh #自定义脚本
-rwxr-xr-x 1 root staff 821 Dec 26 19:08 shutdown.sh
-rw-rw-r-- 1 root staff 31 Dec 26 19:08 tcemirror
# bootlocal.sh
# ============================================
#!/bin/sh
# put other system startup commands here
sudo mkdir /mnt/cd
sudo mount /dev/cdrom /mnt/cd
sudo mkdir /tmp/locdisk1
sudo mount /dev/sda1 /tmp/locdisk1
sudo mkdir /tmp/nginx
sudo mkdir /tmp/ipxe
sudo ln -s /mnt/cd/ipxe/* /tmp/ipxe
sudo cp /mnt/cd/ipxe/boot.ipxe /tmp/ipxe
sudo chmod +w /tmp/ipxe/boot.ipxe
#cd /tmp/ipxe
#sudo ./getindex.sh
# Set Which Directory Will be Shared
# sharedir="/tmp/locdisk1/ipxe"
export sharedir="/tmp/ipxe"
# Set Samba shard Dir
export smbsharedir="/tmp/ipxe"
# get host ip and set the conf files
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo local host ip is [$pc_ip] ...
while [ "$pc_ip" = "" ]
do
echo enter the loop.. sleep 2 sec
sleep 2
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo now get ip is [$pc_ip]
done
echo "modify /etc/dnsmasq.conf"
sudo sed -i -r "s/([0-9]{1,3}\.){3}[0-9]{1,3}/$pc_ip/g" /etc/dnsmasq.conf
sudo sed -i "s@tftp-root=.*@tftp-root=$sharedir@" /etc/dnsmasq.conf
echo "modify $sharedir/boot.ipxe"
sudo sed -ri "s#iseq.* set next-server.*#iseq \$\{next-server\} $pc_ip || set next-server $pc_ip#" $sharedir/boot.ipxe
echo "modify /usr/local/etc/samba/smb.conf Share dir is $smbsharedir"
sudo sed -i "s@path = .*@path = $smbsharedir@" /usr/local/etc/samba/smb.conf
# 1. start sshd
echo "sshd starting..."
sudo /usr/local/etc/init.d/openssh start
# 2. start busbox-httpd
#echo "httpd starting... The rootpath is: $sharedir"
#sudo /usr/local/httpd/sbin/httpd -p 80 -h $sharedir
#echo now! the connect ip is [$pc_ip]
echo "nginx starting... The rootpath is: $sharedir"
sudo /usr/local/etc/init.d/nginx start
echo now! the http server ip is [$pc_ip]
# 3. start Samba Server
echo "Samba Server starting... path: $smbsharedir"
sudo /usr/local/etc/init.d/samba start
# 4. start dnsmasq
sudo dnsmasq --no-daemon
# myreservers.sh
# ============================================
#!/bin/sh
# put other system startup commands here
#export sharedir=/tmp/abc
#./restart-httpd.sh
# Set Which Directory Will be Shared for tftp/httpd
read -p "enter your want to share for tftp/httpd:" sharedir
while [ ! -d $sharedir ]
do
read -p "enter your want to share for tftp/httpd:" sharedir
done
echo -e "You want to share \c"
echo -e "[ \033[31m $sharedir\033[0m ] for [\033[31m tftp/httpd \033[0m]"
read -p 'Are you Sure? If is Wrong, use "Ctrl + C"...'
export sharedir
# Set Which Directory Will be Shared for samba
read -p "enter your want to share for samba:[Default:$sharedir]" smbsharedir
[ "$smbsharedir" = "" ] && smbsharedir=$sharedir
while [ ! -d $smbsharedir ]
do
echo "the [$smbsharedir] is not exist"
read -p "enter your want to share for samba:[Default:$sharedir]" smbsharedir
[ "$smbsharedir" = "" ] && smbsharedir=$sharedir
done
echo -e "You want to share \c"
echo -e "[ \033[31m $smbsharedir \033[0m ] for [\033[31m Samba \033[0m]"
read -p 'Are you Sure? If is Wrong, use "Ctrl + C"...'
export smbsharedir
#/opt/restart-httpd.sh $sharedir
/opt/restart-nginx.sh $sharedir
/opt/restart-samba.sh $smbsharedir
/opt/restart-dnsmasq.sh $sharedir
# restart-dnsmasq.sh
# ============================================
#!/bin/sh
# put other system startup commands here
#echo "now running in the dnsmasq.sh"
function getpath()
{
# Set Which Directory Will be Shared for tftp
# sharedir="/mnt/cd/ipxe"
# Set Which Directory Will be Shared for tftp
read -p "enter your want to share for tftp:[now:$sharedir]" inputsharedir
[ "$inputsharedir" != "" ] && sharedir=$inputsharedir
while [ ! -d $sharedir ]
do
echo "the [$sharedir] is not exist"
read -p "enter your want to share for tftp:[now:$sharedir]" inputsharedir
[ "$inputsharedir" != "" ] && sharedir=$inputsharedir
done
echo -e "You want to share \c"
echo -e "[ \033[31m $sharedir \033[0m ] for tftp"
read -p 'Are you Sure? If is Wrong, use "Ctrl + C"...'
}
[ -d $1 ] || getpath
[ "$1" = "" ] && getpath
#read -p 'pause, use "Ctrl + C"...'
# get host ip and set the conf files
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo local host ip is [$pc_ip] ...
while [ "$pc_ip" = "" ]
do
echo enter the loop.. sleep 2 sec
sleep 2
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo now get ip is [$pc_ip]
done
echo "modify ip and Sharedir /etc/dnsmasq.conf"
sudo sed -i -r "s/([0-9]{1,3}\.){3}[0-9]{1,3}/$pc_ip/g" /etc/dnsmasq.conf
sudo sed -i "s@tftp-root=.*@tftp-root=$sharedir@" /etc/dnsmasq.conf
echo "modify $sharedir/boot.ipxe"
sudo sed -ri "s#iseq.* set next-server.*#iseq \$\{next-server\} $pc_ip || set next-server $pc_ip#" $sharedir/boot.ipxe
# 3. restart dnsmasq
echo "dnsmasq restarting... path: $sharedir"
sudo kill -9 `ps -ef |grep dnsmasq |grep -v grep |grep -v $0 |awk '{print $1}'`
sudo dnsmasq --no-daemon
# restart-httpd.sh
# ============================================
#!/bin/sh
# put other system startup commands here
#echo "now running in the httpd.sh"
function getpath()
{
# Set Which Directory Will be Shared for httpd
# sharedir="/mnt/cd/ipxe"
# Set Which Directory Will be Shared for httpd
read -p "enter your want to share for httpd:[now:$sharedir]" inputsharedir
[ "$inputsharedir" != "" ] && sharedir=$inputsharedir
while [ ! -d $sharedir ]
do
echo "the [$sharedir] is not exist"
read -p "enter your want to share for httpd:[now:$sharedir]" inputsharedir
[ "$inputsharedir" != "" ] && sharedir=$inputsharedir
done
echo -e "You want to share \c"
echo -e "[ \033[31m $sharedir \033[0m ] for httpd"
read -p 'Are you Sure? If is Wrong, use "Ctrl + C"...'
}
[ -d $1 ] || getpath
[ "$1" = "" ] && getpath
# get host ip and set the conf files
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo local host ip is [$pc_ip] ...
while [ "$pc_ip" = "" ]
do
echo enter the loop.. sleep 2 sec
sleep 2
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo now get ip is [$pc_ip]
done
# restart busbox-httpd
echo "httpd restarting... path: $sharedir"
sudo kill -9 `ps -ef |grep httpd |grep -v grep |grep -v $0 |awk '{print $1}'`
sudo /usr/local/httpd/sbin/httpd -p 80 -h $sharedir
echo now! the connect ip is [$pc_ip]
# restart-nginx.sh
# ============================================
#!/bin/sh
# put other system startup commands here
#echo "now running in the httpd.sh"
function getpath()
{
# Set Which Directory Will be Shared for httpd
# sharedir="/mnt/cd/ipxe"
# Set Which Directory Will be Shared for httpd
read -p "enter your want to share for httpd:[now:$sharedir]" inputsharedir
[ "$inputsharedir" != "" ] && sharedir=$inputsharedir
while [ ! -d $sharedir ]
do
echo "the [$sharedir] is not exist"
read -p "enter your want to share for httpd:[now:$sharedir]" inputsharedir
[ "$inputsharedir" != "" ] && sharedir=$inputsharedir
done
echo -e "You want to share \c"
echo -e "[ \033[31m $sharedir \033[0m ] for httpd"
read -p 'Are you Sure? If is Wrong, use "Ctrl + C"...'
}
[ -d $1 ] || getpath
[ "$1" = "" ] && getpath
# get host ip and set the conf files
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo local host ip is [$pc_ip] ...
while [ "$pc_ip" = "" ]
do
echo enter the loop.. sleep 2 sec
sleep 2
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo now get ip is [$pc_ip]
done
sudo sed -i "s@root .*@root $sharedir;@" /usr/local/etc/nginx/nginx.conf
# restart busbox-httpd
echo "nginx restarting... path: $sharedir"
sudo /usr/local/etc/init.d/nginx stop
sudo /usr/local/etc/init.d/nginx start
echo now! the connect ip is [$pc_ip]
# restart-samba.sh
# ============================================
#!/bin/sh
# put other system startup commands here
#echo "now running in the httpd.sh"
function getpath()
{
# Set Which Directory Will be Shared for samba
# sharedir="/mnt/cd/ipxe"
# Set Which Directory Will be Shared for samba
read -p "enter your want to share for samba:[now:$smbsharedir]" inputsharedir
[ "$inputsharedir" != "" ] && smbsharedir=$inputsharedir
while [ ! -d $smbsharedir ]
do
echo "the [$smbsharedir] is not exist"
read -p "enter your want to share for samba:[now:$smbsharedir]" inputsharedir
[ "$inputsharedir" != "" ] && smbsharedir=$inputsharedir
done
echo -e "You want to share \c"
echo -e "[ \033[31m $smbsharedir \033[0m ] for samba"
read -p 'Are you Sure? If is Wrong, use "Ctrl + C"...'
}
[ -d $1 ] || getpath
[ "$1" = "" ] && getpath
# get host ip and set the conf files
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo local host ip is [$pc_ip] ...
while [ "$pc_ip" = "" ]
do
echo enter the loop.. sleep 2 sec
sleep 2
pc_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
echo now get ip is [$pc_ip]
done
echo "modify /usr/local/etc/samba/smb.conf path: $smbsharedir"
sudo sed -i "s@path = .*@path = $smbsharedir@" /usr/local/etc/samba/smb.conf
# 2. start Samba Server
echo "Samba Server restarting..."
sudo /usr/local/etc/init.d/samba stop
sudo /usr/local/etc/init.d/samba start