initramfs(
initial ram filesystem
) purpose
1,variable definition
stage="
creating rootfs mount point"
ROOTFS_MNT=/mnt/rootfs
mkdir -p $ROOTFS_MNT
DOWNLOAD_DIR=${ROOTFS_MNT}/downloads
OS_FEP_FILE="OS-FEP" #
2,downloading OS FEP
echo "
Downloading ${remote_dir}/${OS_FEP_FILE} from ${remote_ip}"
#下载FEP包(包含rootfs)到根目录(/NSN-LSP-OS )
if ! timeout -t $FTP_TIMEOUT wget -T $WGET_TIMEOUT ftp://${FTP_USER}@${FTP_ADDRESS}; then
rm -rf ${
OS_FEP_FILE}
fi
3,processing OS FEP, extract rootfs(ROOTFS-AXM.cpio.xz) from FEP file, and put in ROOTFS_MNT
stage="
processing AXM OS FEP file"
#处理FEP,提取rootfs放在ROOTFS_MNT目录
echo "Download complete, processing..."
# Start kicking watchdog since boot flash updates may take a few min
/sbin/watchdog -T 8 -t 2 /dev/watchdog
if ! /usr/bin/
process_axm_fep $
OS_FEP_FILE $
ROOTFS_MNT ; then
echo "Failed to process $OS_FEP_FILE!"
pkill watchdog
fi
4,switch to rootfs(in ROOTFS_MNT)
stage="
switching to $ROOTFS_MNT"
#从initranfs切换到rootfs
echo "Starting init..."
# switch root
exec /sbin/switch_root $ROOTFS_MNT /sbin/init
5, /sbin/init是个软链接,连接到systemd,切换到rootfs后,就会执行/sbin/init(即启动systemd)
xxxx@yyyy:~# ls -all /sbin/init
20 Jan 1 1970 /sbin/init ->
/lib/systemd/systemd
systemd启动后,进程ID为1,实际上还是initramfs的init进程,因为调用exec执行切换rootfs后,initramfs的init进程并不会退出,而是继续执行systemd,而进程名会变为systemd,
它是Linux系统其他所有进程的父进程。为系统启动的第一个用户进程。
switch_root: