Initramfs » История » Версия 5
Андрей Волков, 2014-05-23 14:02
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 | 4 | Андрей Волков | echo 'activation { udev_rules = 0 }' >> /etc/lvm/lvm.conf |
44 | |||
45 | 1 | Андрей Волков | /sbin/lvm vgscan |
46 | /sbin/lvm vgchange -ay --sysinit |
||
47 | |||
48 | type=$(echo $cmd | cut -d= -f2) |
||
49 | if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then |
||
50 | uuid=$(echo $cmd | cut -d= -f3) |
||
51 | mount -o ro $(blkid |grep "$type=\"$uuid\"" | cut -d: -f1 | grep -v '/dev/dm-[0-9]*$\|-real$' | sort | head -n1 ) /mnt/root || rescue_shell |
||
52 | else |
||
53 | mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root || rescue_shell |
||
54 | fi |
||
55 | ;; |
||
56 | rescue) |
||
57 | rescue_shell |
||
58 | ;; |
||
59 | esac |
||
60 | done |
||
61 | } |
||
62 | |||
63 | uuidlabel_root || rescue_shell |
||
64 | |||
65 | # Remount /dev if devtmpfs |
||
66 | $devtmpfs && mount -n --move /dev /mnt/root/dev |
||
67 | |||
68 | # Clean up. |
||
69 | umount /proc |
||
70 | umount /sys |
||
71 | |||
72 | # Boot the real thing. |
||
73 | exec switch_root /mnt/root /sbin/init |
||
74 | 3 | Андрей Волков | </pre> |
75 | |||
76 | <pre> |
||
77 | cd initramfs |
||
78 | find | cpio -o -H newc | gzip -9 > ../initramfs-2012-04-03.igz |
||
79 | 1 | Андрей Волков | </pre> |
80 | 5 | Андрей Волков | |
81 | для сборки i686: |
||
82 | |||
83 | /etc/paludis/bashrc |
||
84 | |||
85 | <pre> |
||
86 | CC="x86_64-pc-linux-gnu-gcc -m32" |
||
87 | </pre> |
||
88 | |||
89 | для dropbear --enable-static-nss (glibc) |
||
90 | |||
91 | /etc/paludis/use.conf.d/initramfs.conf |
||
92 | |||
93 | <pre> |
||
94 | dev-libs/libtommath static-libs |
||
95 | net-misc/dropbear minimal -pam -shadow static -zlib |
||
96 | dev-libs/popt static-libs |
||
97 | net-misc/rsync static -drop_cache -iconv -ipv6 |
||
98 | sys-fs/lvm2 static -udev |
||
99 | sys-apps/busybox -ipv6 static |
||
100 | </pre> |