Initramfs » История » Версия 1
Андрей Волков, 2012-04-03 19:21
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 | /sbin/lvm vgscan |
||
40 | /sbin/lvm vgchange -ay --sysinit |
||
41 | |||
42 | type=$(echo $cmd | cut -d= -f2) |
||
43 | if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then |
||
44 | uuid=$(echo $cmd | cut -d= -f3) |
||
45 | mount -o ro $(blkid |grep "$type=\"$uuid\"" | cut -d: -f1 | grep -v '/dev/dm-[0-9]*$\|-real$' | sort | head -n1 ) /mnt/root || rescue_shell |
||
46 | else |
||
47 | mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root || rescue_shell |
||
48 | fi |
||
49 | ;; |
||
50 | rescue) |
||
51 | rescue_shell |
||
52 | ;; |
||
53 | esac |
||
54 | done |
||
55 | } |
||
56 | |||
57 | uuidlabel_root || rescue_shell |
||
58 | |||
59 | # Remount /dev if devtmpfs |
||
60 | $devtmpfs && mount -n --move /dev /mnt/root/dev |
||
61 | |||
62 | # Clean up. |
||
63 | umount /proc |
||
64 | umount /sys |
||
65 | |||
66 | # Boot the real thing. |
||
67 | exec switch_root /mnt/root /sbin/init |
||
68 | </pre> |