Commit 7ba6c0a4 authored by Nico Schottelius's avatar Nico Schottelius

can generate initramfs from busybox

Signed-off-by: default avatarNico Schottelius <>
parent f51a4440
# FIXME: Write cdist type / explorer that finds
# package for a file, distro independent
# FIXME: distro specific kernel location
if [ "$#" -ne 1 ]; then
echo "$0 dir-out"
......@@ -12,18 +11,14 @@ dir=$1; shift
mkdir -p "$boot"
cp /boot/vmlinuz-linux \
/boot/initramfs-linux-fallback.img \
/usr/lib/syslinux/bios/isolinux.bin \
cp /usr/lib/syslinux/bios/ldlinux.c32 \
cp /boot/vmlinuz-linux "$boot/linux"
cp /usr/lib/syslinux/bios/isolinux.bin "$boot"
cp /usr/lib/syslinux/bios/ldlinux.c32 "$dir"
cat > "$dir/isolinux.cfg" << eof
default preos
label preos
title cdist PreOS
linux /boot/vmlinuz-linux
initrd /boot/initramfs-linux-fallback.img
linux /boot/linux
initrd /boot/initramfs
rm -rf preos
mkdir -p preos/boot
./ > preos/boot/initramfs
./ preos
set -ex
initramfs_dir=$(mktemp -d /tmp/cdist-preos.XXXXXXX)
# initramfs_dir=$1
for dir in bin sbin etc proc sys newroot; do
mkdir -p ${initramfs_dir}/$dir
touch ${initramfs_dir}/etc/mdev.conf
cp init "${initramfs_dir}/init"
cp $(which busybox) "${initramfs_dir}/bin"
ln -fs busybox "${initramfs_dir}/bin/sh"
cd "${initramfs_dir}"
find . | cpio -H newc -o | gzip
exit 0
# - Kernel modules
# - ssh
# - various mkfs
# - libs
#Mount things needed by this script
mount -t proc proc /proc
mount -t sysfs sysfs /sys
#Disable kernel messages from popping onto the screen
echo 0 > /proc/sys/kernel/printk
#Create all the symlinks to /bin/busybox
busybox --install -s
#Create device nodes
mknod /dev/null c 1 3
mknod /dev/tty c 5 0
mdev -s
#Function for parsing command line options with "=" in them
# get_opt("init=/sbin/init") will return "/sbin/init"
get_opt() {
echo "$@" | cut -d "=" -f 2
#Process command line options
for i in $(cat /proc/cmdline); do
case $i in
root=$(get_opt $i)
init=$(get_opt $i)
exec sh
# Skipping the rest
#Mount the root device
mount "${root}" /newroot
#Check if $init exists and is executable
if [[ -x "/newroot/${init}" ]] ; then
#Unmount all other mounts so that the ram used by
#the initramfs can be cleared after switch_root
umount /sys /proc
#Switch to the new root and execute init
exec switch_root /newroot "${init}"
#This will only be run if the exec above failed
echo "Failed to switch_root, dropping to a shell"
exec sh
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment