Проект

Общее

Профиль

Действия

Initramfs » История » Редакция 4

« Предыдущее | Редакция 4/8 (Разница(diff)) | Следующее »
Андрей Волков, 2013-04-28 14:02


Initramfs

/init

#!/bin/busybox sh

# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys

# Do your stuff here.
echo "This script mounts rootfs and boots it up, nothing more!" 

rescue_shell() {
    echo "Something went wrong. Dropping you to a shell." 
    busybox --install -s
    exec /bin/sh
}

mini_udev() {
    ln -s ../bin/busybox /sbin/mdev
    echo /sbin/mdev > /proc/sys/kernel/hotplug
    /sbin/mdev -s
}

# Use devtmpfs if possible
if grep -qs devtmpfs /proc/filesystems; then
    mount -n -t devtmpfs -o "exec,nosuid,mode=0755,size=10M" udev /dev
    devtmpfs=true
else    
    mini_udev
    devtmpfs=false
fi

uuidlabel_root() {
    for cmd in $(cat /proc/cmdline) ; do
        case $cmd in
        root=*)

        mkdir -p /etc/lvm
        echo 'devices { filter = [ "a|/dev/md[0-9]+$|", "a|/dev/[hsv]d[a-z][0-9]*$|", "r/.*/" ] }' > /etc/lvm/lvm.conf

        echo 'activation { udev_rules = 0 }' >> /etc/lvm/lvm.conf

        /sbin/lvm vgscan
        /sbin/lvm vgchange -ay --sysinit

            type=$(echo $cmd | cut -d= -f2)
            if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then
                uuid=$(echo $cmd | cut -d= -f3)
                mount -o ro $(blkid |grep "$type=\"$uuid\"" | cut -d: -f1 | grep -v '/dev/dm-[0-9]*$\|-real$' | sort | head -n1 ) /mnt/root || rescue_shell
            else
                mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root || rescue_shell
            fi
            ;;
    rescue)
        rescue_shell
        ;;
        esac
    done
}

uuidlabel_root || rescue_shell

# Remount /dev if devtmpfs
$devtmpfs && mount -n --move /dev /mnt/root/dev

# Clean up.
umount /proc
umount /sys

# Boot the real thing.
exec switch_root /mnt/root /sbin/init

cd initramfs
find | cpio -o -H newc | gzip -9 > ../initramfs-2012-04-03.igz

Обновлено Андрей Волков больше 11 лет назад · 8 изменени(я, ий)