Initramfs » История » Версия 8
Андрей Волков, 2016-07-10 05:41
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 | 6 | Андрей Волков | h3. Вариант с gzip |
77 | |||
78 | 3 | Андрей Волков | <pre> |
79 | cd initramfs |
||
80 | find | cpio -o -H newc | gzip -9 > ../initramfs-2012-04-03.igz |
||
81 | 7 | Андрей Волков | </pre> |
82 | 6 | Андрей Волков | |
83 | h3. Вариант с xz |
||
84 | |||
85 | 7 | Андрей Волков | <pre> |
86 | 6 | Андрей Волков | cd initramfs |
87 | find | cpio -o -H newc | xz -v --check=crc32 --x86 --lzma2 > ../initramfs-2015-04-03.ixz |
||
88 | 1 | Андрей Волков | </pre> |
89 | 5 | Андрей Волков | |
90 | для сборки i686: |
||
91 | |||
92 | /etc/paludis/bashrc |
||
93 | |||
94 | <pre> |
||
95 | CC="x86_64-pc-linux-gnu-gcc -m32" |
||
96 | </pre> |
||
97 | |||
98 | для dropbear --enable-static-nss (glibc) |
||
99 | |||
100 | /etc/paludis/use.conf.d/initramfs.conf |
||
101 | |||
102 | <pre> |
||
103 | dev-libs/libtommath static-libs |
||
104 | net-misc/dropbear minimal -pam -shadow static -zlib |
||
105 | dev-libs/popt static-libs |
||
106 | net-misc/rsync static -drop_cache -iconv -ipv6 |
||
107 | sys-fs/lvm2 static -udev |
||
108 | sys-apps/busybox -ipv6 static |
||
109 | </pre> |
||
110 | 8 | Андрей Волков | |
111 | h3. Конвертируем ключи openssh в ключи для dropbear |
||
112 | |||
113 | <pre> |
||
114 | dropbearconvert openssh dropbear ../ssh/ssh_host_rsa_key dropbear_rsa_host_key |
||
115 | dropbearconvert openssh dropbear ../ssh/ssh_host_dsa_key dropbear_dsa_host_key |
||
116 | dropbearconvert openssh dropbear ../ssh/ssh_host_ecdsa_key dropbear_ecdsa_host_key |
||
117 | </pre> |