1.如何制作无盘PXE服务器 (ubuntu16.04实测记录)
https://editor.csdn.net/md/?articleId=116166807
2.如何私人修改定制无盘PXE系统 (ubuntu16.04为列子)
https://editor.csdn.net/md/?articleId=115624660
续集1:initramfs 启动网络连接
https://blog.csdn.net/crystal_li_9/article/details/116206024?spm=1001.2014.3001.5501
1. switch_root命令
initramfs切入真实linux文件系统主要用到switch_root命令。
通常initramfs都是为安装最终的根文件系统做准备工作,它的最后一步需要安装最终的根文件系统,然后切换到新根文件系统上去。
以往 的基于ramdisk 的initrd 使用pivot_root命令切换到新的根文件系统,然后卸载ramdisk。但是initramfs是rootfs,而rootfs既不能 pivot_root,也不能umount。
switch_root命令的格式是:
switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]
其中NEW_ROOT是实际的根文件系统的挂载目录,执行switch_root命令前需要挂载到系统中;
NEW_INIT是实际根文件系统的init程序的路径,一般是/sbin/init;
-c /dev/console是可选参数,用于重定向实际的根文件系统的设备文件,一般情况我们不会使用;
ARGUMENTS_TO_INIT则是传递给实际的根文件系统的init程序的参数,也是可选的。
特别注意
switch_root命令必须由PID=1的进程调用,也就是必须由initramfs的init程序直接调用,不能由init派生的其他进程调用,否则会出错,提示: switch_root: not rootfs
也是同样的原因,init脚本调用switch_root命令必须用exec命令调用,否则也会出错,提示: switch_root: not rootfs
2.如何调用switch_root
minimalistic /init example,即在做initramfs文件架构中,最上面以层的init里
Mount the root filesystem.
mount -o ro /dev/sda1 /mnt/root
exec switch_root /mnt/root /sbin/init
3. 如何执行与验证
正常进入initramfs后, 运行 /sbin/init ,可以启动到真实的系统(系统安装在/dev/sda1),
实践证明:
unbunt16.04的initramfs 可以启动到ubuntu16.04, ubuntu18.04.
4.自启动
启动initramfs后,如何实现自动执行 /sbin/init呢
解答:启动initramfs后,会自动执行根目录下的 init文件,只需要把写好的文件放在这里调用就行。
如
sh /etc/init.d/rcS
5.参考链接
https://wiki.gentoo.org/wiki/Custom_Initramfs