1 |
On Wed, Dec 26, 2012 at 1:49 PM, Mark Knecht <markknecht@×××××.com> wrote: |
2 |
<SNIP> |
3 |
> Actually, I think the initramfs wiki covers this, albeit it's 'not |
4 |
> easy'. Their words. |
5 |
> |
6 |
> I think I'm covered for now. |
7 |
> |
8 |
> Cheers, |
9 |
> Mark |
10 |
|
11 |
While extracting it from the kernel image may be involved, and for now |
12 |
using Neil's example init script which probably isn't exactly right |
13 |
for my needs, there is an intermediate step I quickly discovered. |
14 |
After building the new kernel there is an initramfs_data_cpio file |
15 |
created in /usr/src/linux/usr. I copied this file to a new directory |
16 |
under /root and then ran |
17 |
|
18 |
cpio -i -d -H newc --no-absolute-filenames < initramfs_data.cpio |
19 |
|
20 |
which creates all of the initramfs file structure in this directory. I |
21 |
can then list it and it appears everything is there: |
22 |
|
23 |
|
24 |
c2stable initramfs-work # ls -lR |
25 |
.: |
26 |
total 2620 |
27 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 bin |
28 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 dev |
29 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 etc |
30 |
-rwxr-xr-x 1 root root 2017 Dec 26 14:00 init |
31 |
-rw-r--r-- 1 root root 2640384 Dec 26 13:59 initramfs_data.cpio |
32 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 lib |
33 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 proc |
34 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 realroot |
35 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 sbin |
36 |
drwxr-xr-x 2 root root 4096 Dec 26 14:00 sys |
37 |
|
38 |
./bin: |
39 |
total 2020 |
40 |
-rwxr-xr-x 1 root root 2061600 Dec 26 14:00 busybox |
41 |
lrwxrwxrwx 1 root root 7 Dec 26 14:00 sh -> busybox |
42 |
|
43 |
./dev: |
44 |
total 0 |
45 |
crw------- 1 root root 5, 1 Dec 26 14:00 console |
46 |
crw-rw-rw- 1 root root 1, 3 Dec 26 14:00 null |
47 |
crw-rw-rw- 1 root root 5, 0 Dec 26 14:00 tty |
48 |
crw-rw-rw- 1 root root 1, 9 Dec 26 14:00 urandom |
49 |
|
50 |
./etc: |
51 |
total 4 |
52 |
-rwxr-xr-x 1 root root 3017 Dec 26 14:00 mdadm.conf |
53 |
|
54 |
./lib: |
55 |
total 4 |
56 |
-rwxr-xr-x 1 root root 528 Dec 26 14:00 libext2fs.so |
57 |
|
58 |
./proc: |
59 |
total 0 |
60 |
|
61 |
./realroot: |
62 |
total 0 |
63 |
|
64 |
./sbin: |
65 |
total 568 |
66 |
-rwxr-xr-x 1 root root 216744 Dec 26 14:00 e2fsck |
67 |
-rwxr-xr-x 1 root root 353928 Dec 26 14:00 mdadm |
68 |
|
69 |
./sys: |
70 |
total 0 |
71 |
c2stable initramfs-work # |
72 |
|
73 |
|
74 |
c2stable initramfs-work # cat init |
75 |
#!/bin/busybox sh |
76 |
|
77 |
rescue_shell() { |
78 |
busybox --install -s |
79 |
echo $1 |
80 |
exec /bin/sh |
81 |
} |
82 |
|
83 |
### Mount the /proc and /sys filesystems. |
84 |
mount -t proc none /proc |
85 |
grep -q initdebug </proc/cmdline && set -x && DEBUG=1 |
86 |
mount -t sysfs none /sys |
87 |
mount -t devtmpfs none /dev |
88 |
|
89 |
### Get root and init parameters from cmdline |
90 |
REAL_ROOT="$(sed 's/.*root=\(\S*\).*/\1/' <proc/cmdline)" |
91 |
if grep -q init= </proc/cmdline; then |
92 |
REAL_INIT="$(sed 's/.*init=\(\S*\).*/\1/' <proc/cmdline)" |
93 |
else |
94 |
REAL_INIT="/sbin/init" |
95 |
fi |
96 |
|
97 |
### Assemble RAID |
98 |
[[ -f /sbin/mdadm ]] && mdadm --assemble --scan |
99 |
|
100 |
### Initialise LVM |
101 |
if [[ -f /sbin/lvm.static ]]; then |
102 |
lvm.static vgchange -a y |
103 |
lvm.static vgscan --mknodes |
104 |
[[ -n "$DEBUG" ]] && sleep 10 |
105 |
fi |
106 |
|
107 |
### Mount the root filesystem. |
108 |
if [[ -f /sbin/cryptsetup ]] && cryptsetup isLuks $REAL_ROOT; then |
109 |
busybox echo -e "\e[0;32m\n=====================\nEncrypted |
110 |
root device\n=====================\n\e[m" |
111 |
cryptsetup luksOpen $REAL_ROOT cryptroot |
112 |
REAL_ROOT="/dev/mapper/cryptroot" |
113 |
[[ -n "$DEBUG" ]] && echo $REAL_ROOT && sleep 10 |
114 |
fi |
115 |
mount -o ro $REAL_ROOT /realroot || rescue_shell "Could not mount REAL_ROOT" |
116 |
[[ -n "$DEBUG" ]] && df -h /realroot && sleep 10 |
117 |
|
118 |
### Mount /usr if separate |
119 |
if grep -qE '^[^#].*\s\/usr\s' /realroot/etc/fstab; then |
120 |
#mount $(awk '/\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, |
121 |
"-o", $4 ",ro"}' /realroot/etc/fstab) |
122 |
mount $(awk '/^[^#].*\s\/usr\s/ {print $1, "/realroot"$2, "-t", |
123 |
$3, "-o", $4 ",ro"}' /realroot/etc/fstab) |
124 |
[[ -n "$DEBUG" ]] && df -h /realroot//usr && sleep 10 |
125 |
fi |
126 |
|
127 |
grep -q waitforkey </proc/cmdline && WAITFORKEY=1 |
128 |
grep -q rescue </proc/cmdline && rescue_shell "...because you asked for it." |
129 |
|
130 |
### Clean up. |
131 |
umount /dev |
132 |
umount /sys |
133 |
umount /proc |
134 |
|
135 |
### Boot the real thing |
136 |
[[ -n "$DEBUG" ]] && echo "Ready to switch" && sleep 10 |
137 |
[[ -n "$WAITFORKEY" ]] && busybox showkey -a |
138 |
exec busybox switch_root /realroot $REAL_INIT || rescue_shell "Failed |
139 |
to switch_root" |
140 |
c2stable initramfs-work # |
141 |
|
142 |
|
143 |
|
144 |
At this point I don't know that 1) the image is actually in the |
145 |
kernel, or 2) that my "init thingy" ;-) image would work, but at least |
146 |
the process of putting it together is verifiable. |
147 |
|
148 |
|
149 |
Cheers, |
150 |
Mark |