-
Notifications
You must be signed in to change notification settings - Fork 65
/
gen_initramfs.sh
executable file
·2297 lines (1906 loc) · 73.2 KB
/
gen_initramfs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# $Id$
COPY_BINARIES=false
CPIO_ARGS="--quiet --null -o -H newc --owner root:root --force-local"
# The copy_binaries function is explicitly released under the CC0 license to
# encourage wide adoption and re-use. That means:
# - You may use the code of copy_binaries() as CC0 outside of genkernel
# - Contributions to this function are licensed under CC0 as well.
# - If you change it outside of genkernel, please consider sending your
# modifications back to [email protected].
#
# On a side note: "Both public domain works and the simple license provided by
# CC0 are compatible with the GNU GPL."
# (from https://www.gnu.org/licenses/license-list.html#CC0)
#
# Written by:
# - Sebastian Pipping <[email protected]> (error checking)
# - Robin H. Johnson <[email protected]> (complete rewrite)
# - Richard Yao <[email protected]> (original concept)
# Usage:
# copy_binaries DESTDIR BINARIES...
copy_binaries() {
local destdir=${1}
shift
if [ ! -f "${TEMP}/.binaries_copied" ]
then
touch "${TEMP}/.binaries_copied" \
|| gen_die "Failed to set '${TEMP}/.binaries_copied' marker!"
fi
local binary
for binary in "$@"
do
[[ -e "${binary}" ]] \
|| gen_die "Binary ${binary} could not be found"
if "${LDDTREE_COMMAND}" "${binary}" 2>&1 | grep -F -q 'not found'
then
gen_die "Binary ${binary} is linked to missing libraries and may need to be re-built"
fi
done
# This must be OUTSIDE the for loop, we only want to run lddtree etc ONCE.
# lddtree does not have the -V (version) nor the -l (list) options prior to version 1.18
(
if "${LDDTREE_COMMAND}" -V > /dev/null 2>&1
then
"${LDDTREE_COMMAND}" -l "$@" \
|| gen_die "Binary '${binary}' or some of its library dependencies could not be copied!"
else
"${LDDTREE_COMMAND}" "$@" \
| tr ')(' '\n' \
| awk '/=>/{ if($3 ~ /^\//){print $3}}' \
|| gen_die "Binary '${binary}' or some of its library dependencies could not be copied!"
fi
) \
| sort \
| uniq \
| "${CPIO_COMMAND}" -p --make-directories --dereference --quiet "${destdir}" \
|| gen_die "Binary '${binary}' or some of its library dependencies could not be copied!"
}
# @FUNCTION: copy_system_binaries
# @USAGE: <DESTDIR> <system binaries to copy>
# @DESCRIPTION:
# Copies system binaries into dest dir.
#
# Difference to copy_binaries() is, that copy_system_binaries() does NOT
# try to recreate directory structure. Any system binary to copy will be
# placed into same DESTination DIRectory.
# Because we focus on *system* binaries, it's safe to assume that everything
# belongs to the same directory. This assumption will allow us to copy from
# crossdev environments (i.e. /usr/$CHOST).
copy_system_binaries() {
[[ ${#} -lt 2 ]] \
&& gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid usage of ${FUNCNAME}(): Function takes at least two arguments (${#} given)!"
local destdir=${1}
shift
[[ ! -d "${destdir}" ]] \
&& gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid usage of ${FUNCNAME}(): Destdir '${destdir}' does NOT exist!"
if [ ! -f "${TEMP}/.system_binaries_copied" ]
then
touch "${TEMP}/.system_binaries_copied" \
|| gen_die "Failed to set '${TEMP}/.system_binaries_copied' marker!"
fi
local binary binary_realpath binary_basename base_dir
local binary_dependency binary_dependency_basename
for binary in "$@"
do
[[ -e "${binary}" ]] \
|| gen_die "$(get_useful_function_stack)System binary '${binary}' could not be found!"
print_info 5 "System binary '${binary}' should be copied to '${destdir}' ..."
binary_basename=$(basename "${binary}")
if [[ -z "${binary_basename}" ]]
then
gen_die "$(get_useful_function_stack)Failed to determine basename of '${binary}'!"
else
print_info 5 "System binary's basename is '${binary_basename}'."
fi
if [[ -e "${destdir}/${binary_basename}" ]]
then
print_info 5 "System binary '${binary_basename}' already exists in '${destdir}'; Skipping ..."
continue
fi
if [[ -L "${binary}" ]]
then
binary_realpath=$(realpath "${binary}")
if [[ -z "${binary_realpath}" ]]
then
gen_die "$(get_useful_function_stack)Failed to resolve path to '${binary}'!"
elif [[ ! -e "${binary_realpath}" ]]
then
gen_die "$(get_useful_function_stack)System binary '${binary}' was resolved to '${binary_realpath}' but file does NOT exist!"
else
print_info 5 "System binary '${binary}' resolved to '${binary_realpath}'."
binary=${binary_realpath}
fi
fi
base_dir=$(dirname "${binary}")
if [[ -z "${base_dir}" ]]
then
gen_die "$(get_useful_function_stack)Failed to determine directory of '${binary}'!"
else
print_info 5 "System binary dirname set to '${base_dir}'."
fi
local is_first=1
while IFS= read -r -u 3 binary_dependency
do
binary_dependency_basename=$(basename "${binary_dependency}")
if [[ -z "${binary_dependency_basename}" ]]
then
gen_die "$(get_useful_function_stack)Failed to determine basename of '${binary_dependency}'!"
fi
if [[ ${is_first} -eq 1 ]]
then
# `lddtree -l` first line is always the binary itself
print_info 5 "Copying '${base_dir}/${binary_dependency_basename}' to '${destdir}/' ..."
cp -aL "${base_dir}/${binary_dependency_basename}" "${destdir}/${binary_basename}" \
|| gen_die "$(get_useful_function_stack)Failed to copy '${base_dir}/${binary_dependency_basename}' to '${destdir}'!"
is_first=0
elif [[ -e "${destdir}/${binary_dependency_basename}" ]]
then
print_info 5 "System binary '${binary_basename}' already exists in '${destdir}'; Skipping ..."
continue
else
print_info 5 "Need to copy dependency '${base_dir}/${binary_dependency_basename}' ..."
"${FUNCNAME}" "${destdir}" "${base_dir}/${binary_dependency_basename}"
fi
done 3< <("${LDDTREE_COMMAND}" -l "${binary}" 2>/dev/null)
IFS="${GK_DEFAULT_IFS}"
done
}
log_future_cpio_content() {
local dir_size=$(get_du "${PWD}")
if [ -n "${dir_size}" ]
then
dir_size=" (${dir_size})"
fi
print_info 3 "=================================================================" 1 0 1
print_info 3 "About to add these files${dir_size} from '${PWD}' to cpio archive:" 1 0 1
print_info 3 "$(find . -print0 | xargs --null ls -ald)" 1 0 1
print_info 3 "=================================================================" 1 0 1
}
append_devicemanager() {
local PN="lvm"
local TDIR="${TEMP}/initramfs-dm-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
# Delete unneeded files
rm -rf \
sbin/lvm \
usr/include \
usr/lib/device-mapper \
usr/lib/pkgconfig \
usr/lib/lib* \
usr/sbin/lvm \
usr/share
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append bcache to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_devices() {
if isTrue "${BUSYBOX}"
then
local TDIR="${TEMP}/initramfs-devices-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
mkdir -p "${TDIR}/dev" || gen_die "Failed to create '${TDIR}/dev'!"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
chmod 0755 dev || gen_die "Failed to chmod of '${TDIR}/dev' to 0755!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append devices to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
else
local TFILE="${TEMP}/initramfs-base-temp.devices"
if [ -f "${TFILE}" ]
then
rm "${TFILE}" || gen_die "Failed to clean out existing '${TFILE}'!"
fi
if [[ ! -x "${KERNEL_OUTPUTDIR}/usr/gen_init_cpio" ]]; then
compile_gen_init_cpio
fi
# WARNING, does NOT support appending to cpio!
cat >"${TFILE}" <<-EOF
dir /dev 0755 0 0
nod /dev/console 660 0 0 c 5 1
nod /dev/null 666 0 0 c 1 3
nod /dev/random 600 0 0 c 1 8
nod /dev/tty0 600 0 0 c 4 0
nod /dev/tty1 600 0 0 c 4 1
nod /dev/ttyS0 600 0 0 c 4 64
nod /dev/ttyS1 600 0 0 c 4 65
nod /dev/urandom 600 0 0 c 1 9
nod /dev/zero 666 0 0 c 1 5
EOF
print_info 3 "=================================================================" 1 0 1
print_info 3 "Adding the following devices to cpio:" 1 0 1
print_info 3 "$(cat "${TFILE}")" 1 0 1
print_info 3 "=================================================================" 1 0 1
"${KERNEL_OUTPUTDIR}"/usr/gen_init_cpio "${TFILE}" >"${CPIO_ARCHIVE}" \
|| gen_die "Failed to append devices to cpio!"
fi
}
append_base_layout() {
local TDIR="${TEMP}/initramfs-base-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
local mydir=
for mydir in \
.initrd \
bin \
dev \
etc \
lib \
lib/console \
lib/dracut \
mnt \
proc \
run \
sbin \
sys \
tmp \
usr \
usr/bin \
usr/lib \
usr/sbin \
var/empty \
var/log \
var/run/lock \
; do
mkdir -p "${TDIR}"/${mydir} || gen_die "Failed to create '${TDIR}/${mydir}'!"
done
chmod 1777 "${TDIR}"/tmp || gen_die "Failed to chmod of '${TDIR}/tmp' to 1777!"
# In general, we don't really need lib{32,64} anymore because we now
# compile most stuff on our own and therefore don't have to deal with
# multilib anymore. However, when copy_binaries() was used to copy
# binaries from a multilib-enabled system, this could be a problem.
# So let's keep symlinks to ensure that all libraries will land in
# /lib.
local myliblink
for myliblink in \
lib32 \
lib64 \
usr/lib32 \
usr/lib64 \
; do
ln -s lib ${myliblink} || gen_die "Failed to create symlink '${TDIR}/${myliblink}' to '${TDIR}/lib'!"
done
print_info 2 "$(get_indent 2)>> Populating '/etc/fstab' ..."
echo "/dev/ram0 / ext2 defaults 0 0" > "${TDIR}"/etc/fstab \
|| gen_die "Failed to add /dev/ram0 to '${TDIR}/etc/fstab'!"
echo "proc /proc proc defaults 0 0" >> "${TDIR}"/etc/fstab \
|| gen_die "Failed to add proc to '${TDIR}/etc/fstab'!"
print_info 2 "$(get_indent 2)>> Adding /etc/{group,passwd,shadow} ..."
cat >"${TDIR}"/etc/group <<-EOF
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root,adm
lp:x:7:lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
floppy:x:11:root
news:x:13:news
uucp:x:14:uucp
console:x:17:
audio:x:18:
cdrom:x:19:
dialout:x:20:
tape:x:26:root
video:x:27:root
render:x:28:
rpc:x:32:
kvm:x:78:
usb:x:85:
input:x:97:
utmp:x:406:
nogroup:x:65533:
nobody:x:65534:
EOF
chmod 0644 "${TDIR}"/etc/group \
|| gen_die "Failed to chmod of '${TDIR}/etc/group'!"
cat >"${TDIR}"/etc/passwd <<-EOF
root:x:0:0:root:/root:/usr/bin/login-remote.sh
nobody:x:65534:65534:nobody:/var/empty:/bin/false
EOF
chmod 0644 "${TDIR}"/etc/passwd \
|| gen_die "Failed to chmod of '${TDIR}/etc/passwd'!"
echo "root:!:0:0:99999:7:::" > "${TDIR}"/etc/shadow \
|| gen_die "Failed to create '/etc/shadow'!"
chmod 0640 "${TDIR}"/etc/shadow \
|| gen_die "Failed to chmod of '${TDIR}/etc/shadow'!"
print_info 2 "$(get_indent 2)>> Adding /etc/nsswitch.conf ..."
cat >"${TDIR}"/etc/nsswitch.conf <<-EOF
# /etc/nsswitch.conf generated by genkernel
passwd: files
shadow: files
group: files
EOF
print_info 2 "$(get_indent 2)>> Adding /etc/ld.so.conf ..."
cat >"${TDIR}"/etc/ld.so.conf <<-EOF
# ld.so.conf generated by genkernel
include ld.so.conf.d/*.conf
/lib
/usr/lib
EOF
print_info 2 "$(get_indent 2)>> Adding misc files ..."
date -u '+%Y-%m-%d %H:%M:%S UTC' > "${TDIR}"/etc/build_date \
|| gen_die "Failed to create '${TDIR}/etc/build_date'!"
echo "Genkernel ${GK_V}" > "${TDIR}"/etc/build_id \
|| gen_die "Failed to create '${TDIR}/etc/build_id'!"
cat >"${TDIR}"/etc/initrd-release <<-EOF
NAME="genkernel"
VERSION="genkernel-${GK_V}"
ID=genkernel
VERSION_ID=${GK_V}
PRETTY_NAME="Gentoo/Linux genkernel-${GK_V} (Initramfs)"
ANSI_COLOR="0;34"
EOF
cp -a "${GK_SHARE}"/defaults/gksosreport.sh "${TDIR}"/usr/sbin/gksosreport \
|| gen_die "Failed to copy '${GK_SHARE}/defaults/gksosreport.sh' to '${TDIR}/usr/sbin/gksosreport'"
chmod 0755 "${TDIR}"/usr/sbin/gksosreport \
|| gen_die "Failed to chmod of '${TDIR}/usr/sbin/gksosreport'!"
ln -s /proc/self/mounts "${TDIR}"/etc/mtab \
|| gen_die "Failed to symlink '/etc/mtab' to '/proc/self/mounts'!"
# Allow lsinitrd from dracut to process our initramfs
echo "$(cat "${TDIR}/etc/build_id") ($(cat "${TDIR}/etc/build_date"))" > "${TDIR}"/lib/dracut/dracut-gk-version.info \
|| gen_die "Failed to create '${TDIR}/lib/dracut/dracut-gk-version.info'!"
if [[ "${CMD_BOOTFONT}" == "none" ]]
then
print_info 3 "$(get_indent 2)>> --boot-font=none set; Not embedding console font ..."
else
local BOOTFONT_FILE="${TDIR}/lib/console/font"
if [[ "${CMD_BOOTFONT}" == "current" ]]
then
print_info 2 "$(get_indent 2)>> Embedding current active console font ..."
local -a setfont_cmd=( "${SETFONT_COMMAND}" )
setfont_cmd+=( "-O ${BOOTFONT_FILE}" )
print_info 3 "COMMAND: ${setfont_cmd[*]}" 1 0 1
eval "${setfont_cmd[@]}" || gen_die "Failed to dump current active console font!"
if ! isTrue $(is_psf_file "${BOOTFONT_FILE}")
then
gen_die "Sanity check failed: Dumped current active console font does NOT look like a valid PC Screen Font (PSF) file!"
fi
else
print_info 2 "$(get_indent 2)>> Embedding '${BOOTFONT}' as console font ..."
# Already validated in determine_real_args()
cp -aL "${BOOTFONT}" "${BOOTFONT_FILE}" \
|| gen_die "Failed to copy '${BOOTFONT}' to '${BOOTFONT_FILE}'!"
fi
fi
local -a build_parameters
build_parameters+=( --boot-font=${CMD_BOOTFONT} )
if isTrue "${KEYMAP}"
then
build_parameters+=( --keymap )
isTrue "${DOKEYMAPAUTO}" && build_parameters+=( --do-keymap-auto )
else
build_parameters+=( --no-keymap )
fi
isTrue "${COMPRESS_INITRD}" && build_parameters+=( --compress-initramfs ) || build_parameters+=( --no-compress-initramfs )
isTrue "${MICROCODE_INITRAMFS}" && build_parameters+=( --microcode-initramfs ) || build_parameters+=( --no-microcode-initramfs )
isTrue "${RAMDISKMODULES}" && build_parameters+=( --ramdisk-modules ) || build_parameters+=( --no-ramdisk-modules )
isTrue "${BUSYBOX}" && build_parameters+=( --busybox ) || build_parameters+=( --no-busybox )
isTrue "${BCACHE}" && build_parameters+=( --bcache ) || build_parameters+=( --no-bcache )
isTrue "${B2SUM}" && build_parameters+=( --b2sum ) || build_parameters+=( --no-b2sum )
isTrue "${BTRFS}" && build_parameters+=( --btrfs ) || build_parameters+=( --no-btrfs )
isTrue "${ISCSI}" && build_parameters+=( --iscsi ) || build_parameters+=( --no-iscsi )
isTrue "${MULTIPATH}" && build_parameters+=( --multipath ) || build_parameters+=( --no-multipath )
isTrue "${DMRAID}" && build_parameters+=( --dmraid ) || build_parameters+=( --no-dmraid )
isTrue "${MDADM}" && build_parameters+=( --mdadm ) || build_parameters+=( --no-mdadm )
isTrue "${LVM}" && build_parameters+=( --lvm ) || build_parameters+=( --no-lvm )
isTrue "${UNIONFS}" && build_parameters+=( --unionfs ) || build_parameters+=( --no-unionfs )
isTrue "${ZFS}" && build_parameters+=( --zfs ) || build_parameters+=( --no-zfs )
isTrue "${SPLASH}" && build_parameters+=( --splash ) || build_parameters+=( --no-splash )
isTrue "${STRACE}" && build_parameters+=( --strace ) || build_parameters+=( --no-strace )
isTrue "${GPG}" && build_parameters+=( --gpg ) || build_parameters+=( --no-gpg )
isTrue "${LUKS}" && build_parameters+=( --luks ) || build_parameters+=( --no-luks )
isTrue "${FIRMWARE}" && build_parameters+=( --firmware ) || build_parameters+=( --no-firmware )
[ -n "${FIRMWARE_DIR}" ] && build_parameters+=( --firmware-dir="${FIRMWARE_DIR}" )
[ -n "${FIRMWARE_FILES}" ] && build_parameters+=( --firmware-files="${FIRMWARE_FILES}" )
isTrue "${SSH}" && build_parameters+=( --ssh ) || build_parameters+=( --no-ssh )
isTrue "${E2FSPROGS}" && build_parameters+=( --e2fsprogs ) || build_parameters+=( --no-e2fsprogs )
isTrue "${XFSPROGS}" && build_parameters+=( --xfsprogs ) || build_parameters+=( --no-xfsprogs )
echo "${build_parameters[@]}" > "${TDIR}"/lib/dracut/build-parameter.txt \
|| gen_die "Failed to create '${TDIR}/lib/dracut/build-parameter.txt'!"
dd if=/dev/zero of="${TDIR}/var/log/lastlog" bs=1 count=0 seek=0 &>/dev/null \
|| die "Failed to create '${TDIR}/var/log/lastlog'!"
dd if=/dev/zero of="${TDIR}/var/log/wtmp" bs=1 count=0 seek=0 &>/dev/null \
|| die "Failed to create '${TDIR}/var/log/wtmp'!"
dd if=/dev/zero of="${TDIR}/var/run/utmp" bs=1 count=0 seek=0 &>/dev/null \
|| die "Failed to create '${TDIR}/var/run/utmp'!"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append baselayout to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_busybox() {
local PN=busybox
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
# Delete unneeded files
rm -rf configs/
mkdir -p "${TDIR}"/usr/share/udhcpc || gen_die "Failed to create '${TDIR}/usr/share/udhcpc'!"
cp -a "${GK_SHARE}"/defaults/udhcpc.scripts usr/share/udhcpc/default.script 2>/dev/null \
|| gen_die "Failed to copy '${GK_SHARE}/defaults/udhcpc.scripts' to '${TDIR}/usr/share/udhcpc/default.script'!"
local myfile=
for myfile in \
bin/busybox \
usr/share/udhcpc/default.script \
; do
chmod +x "${TDIR}"/${myfile} || gen_die "Failed to chmod of '${TDIR}/${myfile}'!"
done
# Set up a few default symlinks
local required_applets='[ ash sh mkdir mknod mount uname echo chmod cut cat touch'
local required_applet=
for required_applet in ${required_applets}
do
ln -s busybox "${TDIR}"/bin/${required_applet} \
|| gen_die "Failed to create Busybox symlink for '${required_applet}' applet!"
done
# allow for DNS resolution
if isTrue "$(is_glibc)"
then
local libdir=$(get_chost_libdir)
local libnss_dns="${libdir}/libnss_dns.so"
# NSS dns module was moved into libc in >=glibc-2.34
# but when this file exists we are probably dealing with older glibc
# and need to manually copy the module.
if [[ -f "${libnss_dns}" ]]
then
mkdir -p "${TDIR}"/lib || gen_die "Failed to create '${TDIR}/lib'!"
copy_system_binaries "${TDIR}"/lib "${libnss_dns}"
fi
fi
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append ${PN} to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_e2fsprogs() {
local PN=e2fsprogs
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append ${PN} to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_eudev() {
local PN=eudev
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
populate_binpkg hwids
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
unpack "$(get_gkpkg_binpkg hwids)" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
if isTrue "$(can_run_programs_compiled_by_genkernel)"
then
print_info 2 "$(get_indent 2)${PN}: >> Pre-generating initramfs' /etc/udev/hwdb.bin ..."
local gen_hwdb_cmd=( "${TDIR}/usr/bin/udevadm" )
gen_hwdb_cmd+=( hwdb --update --root "${TDIR}" )
print_info 3 "COMMAND: ${gen_hwdb_cmd[*]}" 1 0 1
eval "${gen_hwdb_cmd[@]}" 2>&1 | tee -a "${LOGFILE}" \
|| gen_die "Failed to pre-generate initramfs' /etc/udev/hwdb.bin!"
# Now that we have a pre-generated hwdb in initramfs
# we can delete source files
rm -rf usr/lib/udev/hwdb.d/
fi
# Delete unneeded files
rm -rf usr/include \
usr/lib/libu* \
usr/lib/pkgconfig \
usr/share
# Disable predictable network interface names in initramfs
echo "" > usr/lib/udev/rules.d/80-net-name-slot.rules \
|| gen_die "Failed to disable predictable network interface naming rule"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append ${PN} to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_b2sum() {
local PN="coreutils"
local TDIR="${TEMP}/initramfs-b2sum-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append b2sum to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_bcache() {
local PN="bcache-tools"
local TDIR="${TEMP}/initramfs-bcache-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append bcache to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_unionfs_fuse() {
local PN=unionfs-fuse
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append ${PN} to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_util-linux() {
local PN="util-linux"
local TDIR="${TEMP}/initramfs-util-linux-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
# Delete unneeded files
rm -rf usr/
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append ${PN} to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_multipath() {
local PN=multipath-tools
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
mkdir -p "${TDIR}"/etc || gen_die "Failed to create '${TDIR}/etc'!"
mkdir -p "${TDIR}"/usr/lib/udev/rules.d || gen_die "Failed to create '${TDIR}/usr/lib/udev/rules.d'!"
local libdir=$(get_chost_libdir)
if [[ "${libdir}" =~ ^/usr ]]
then
libdir=${libdir/\/usr/}
fi
copy_binaries \
"${TDIR}" \
/sbin/multipath \
/sbin/kpartx \
/sbin/mpathpersist \
${libdir}/multipath/lib*.so
local udevdir=$(get_udevdir)
local udevdir_initramfs="/usr/lib/udev"
local udev_files=( $(qlist -e sys-fs/multipath-tools:0 \
| grep -E -- "^${udevdir}")
)
if [ ${#udev_files[@]} -eq 0 ]
then
gen_die "Something went wrong: Did not found any udev-related files for sys-fs/multipath-tools!"
fi
local udev_files
for udev_file in "${udev_files[@]}"
do
local dest_file="${TDIR%/}${udev_file/${udevdir}/${udevdir_initramfs}}"
cp -aL "${udev_file}" "${dest_file}" \
|| gen_die "Failed to copy '${udev_file}' to '${dest_file}'"
done
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
cp -aL /etc/multipath.conf "${TDIR}"/etc/multipath.conf 2>/dev/null \
|| gen_die "Failed to copy '/etc/multipath.conf'!"
# /etc/scsi_id.config does not exist in newer udevs
# copy it optionally.
if [ -f /etc/scsi_id.config ]
then
cp -aL /etc/scsi_id.config "${TDIR}"/etc/scsi_id.config 2>/dev/null \
|| gen_die "Failed to copy '/etc/scsi_id.config'!"
fi
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append ${PN} to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_dmraid() {
local PN=dmraid
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
# Delete unneeded files
rm -rf \
usr/lib \
usr/share \
usr/include
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append dmraid to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_iscsi() {
local PN=open-iscsi
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append iscsi to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_lvm() {
local PN=lvm
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
populate_binpkg thin-provisioning-tools
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
unpack "$(get_gkpkg_binpkg "thin-provisioning-tools")" "${TDIR}"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
local mydir=
for mydir in \
etc/lvm/cache \
sbin \
; do
mkdir -p ${mydir} || gen_die "Failed to create '${TDIR}/${mydir}'!"
done
# Delete unneeded files
rm -rf \
usr/lib/device-mapper \
usr/lib/pkgconfig \
usr/lib/lib* \
usr/sbin/dm* \
usr/share \
usr/include
# Include the LVM config
if [ -x /sbin/lvm -o -x /bin/lvm ]
then
local ABORT_ON_ERRORS=$(kconfig_get_opt "/etc/lvm/lvm.conf" "abort_on_errors")
if isTrue "${ABORT_ON_ERRORS}" && [[ ${CBUILD} == ${CHOST} ]]
then
# Make sure the LVM binary we created is able to handle
# system's lvm.conf
"${TDIR}"/sbin/lvm dumpconfig 1>"${TDIR}"/etc/lvm/lvm.conf 2>/dev/null \
|| gen_die "Bundled LVM version does NOT support system's lvm.conf!"
# Sanity check
if [ ! -s "${TDIR}/etc/lvm/lvm.conf" ]
then
gen_die "Sanity check failed: '${TDIR}/etc/lvm/lvm.conf' looks empty?!"
fi
else
cp -aL /etc/lvm/lvm.conf "${TDIR}"/etc/lvm/lvm.conf 2>/dev/null \
|| gen_die "Failed to copy '/etc/lvm/lvm.conf'!"
fi
# Some LVM config options need changing, because the functionality is
# not compiled in:
sed -r -i \
-e '/^[[:space:]]*obtain_device_list_from_udev/s,=.*,= 1,g' \
-e '/^[[:space:]]*udev_sync/s,=.*,= 1,g' \
-e '/^[[:space:]]*use_lvmetad/s,=.*,= 0,g' \
-e '/^[[:space:]]*use_lvmlockd/s,=.*,= 0,g' \
-e '/^[[:space:]]*use_lvmpolld/s,=.*,= 0,g' \
-e '/^[[:space:]]*monitoring/s,=.*,= 0,g' \
-e '/^[[:space:]]*external_device_info_source/s,=.*,= "none",g' \
-e '/^[[:space:]]*units/s,=.*"r",= "h",g' \
-e '/^[[:space:]]*thin_repair_executable/s,=.*,= /usr/sbin/thin_repair,g' \
-e '/^[[:space:]]*thin_dump_executable/s,=.*,= /usr/sbin/thin_dump,g' \
-e '/^[[:space:]]*thin_check_executable/s,=.*,= /usr/sbin/thin_check,g' \
"${TDIR}"/etc/lvm/lvm.conf \
|| gen_die 'Could not sed lvm.conf!'
fi
log_future_cpio_content
find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F "${CPIO_ARCHIVE}" \
|| gen_die "Failed to append lvm to cpio!"
cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
if isTrue "${CLEANUP}"
then
rm -rf "${TDIR}"
fi
}
append_mdadm() {
local PN=mdadm
local TDIR="${TEMP}/initramfs-${PN}-temp"
if [ -d "${TDIR}" ]
then
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!"
fi
populate_binpkg ${PN}
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"