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