Проект

Общее

Профиль

Initramfs » История » Версия 2

Андрей Волков, 2012-04-03 19:30

1 1 Андрей Волков
h1. Initramfs
2
3
<pre>
4
#!/bin/busybox sh
5
6
# Mount the /proc and /sys filesystems.
7
mount -t proc none /proc
8
mount -t sysfs none /sys
9
10
# Do your stuff here.
11
echo "This script mounts rootfs and boots it up, nothing more!"
12
13
rescue_shell() {
14
    echo "Something went wrong. Dropping you to a shell."
15
    busybox --install -s
16
    exec /bin/sh
17
}
18
19
mini_udev() {
20
    ln -s ../bin/busybox /sbin/mdev
21
    echo /sbin/mdev > /proc/sys/kernel/hotplug
22
    /sbin/mdev -s
23
}
24
25
# Use devtmpfs if possible
26
if grep -qs devtmpfs /proc/filesystems; then
27
    mount -n -t devtmpfs -o "exec,nosuid,mode=0755,size=10M" udev /dev
28
    devtmpfs=true
29
else    
30
    mini_udev
31
    devtmpfs=false
32
fi
33
34
uuidlabel_root() {
35
    for cmd in $(cat /proc/cmdline) ; do
36
        case $cmd in
37
        root=*)
38
39 2 Андрей Волков
	    mkdir -p /etc/lvm
40
	    echo 'devices { filter = [ "a|/dev/md[0-9]+$|", "a|/dev/[hsv]d[a-z][0-9]*$|", "r/.*/" ] }' > /etc/lvm/lvm.conf
41
42 1 Андрей Волков
	    /sbin/lvm vgscan
43
	    /sbin/lvm vgchange -ay --sysinit
44
45
            type=$(echo $cmd | cut -d= -f2)
46
            if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then
47
                uuid=$(echo $cmd | cut -d= -f3)
48
                mount -o ro $(blkid |grep "$type=\"$uuid\"" | cut -d: -f1 | grep -v '/dev/dm-[0-9]*$\|-real$' | sort | head -n1 ) /mnt/root || rescue_shell
49
            else
50
                mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root || rescue_shell
51
            fi
52
            ;;
53
	rescue)
54
	    rescue_shell
55
	    ;;
56
        esac
57
    done
58
}
59
60
uuidlabel_root || rescue_shell
61
62
# Remount /dev if devtmpfs
63
$devtmpfs && mount -n --move /dev /mnt/root/dev
64
65
# Clean up.
66
umount /proc
67
umount /sys
68
69
# Boot the real thing.
70
exec switch_root /mnt/root /sbin/init
71
</pre>