]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/99base/module-setup.sh
Allow running on a cross-compiled rootfs
[thirdparty/dracut.git] / modules.d / 99base / module-setup.sh
1 #!/bin/bash
2
3 # called by dracut
4 check() {
5 return 0
6 }
7
8 # called by dracut
9 depends() {
10 echo udev-rules
11 return 0
12 }
13
14 # called by dracut
15 install() {
16 local _d
17
18 inst_multiple mount mknod mkdir sleep chroot chown \
19 sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid \
20 modprobe
21
22 inst_multiple -o findmnt less kmod
23
24 if [ ! -e "${initdir}/bin/sh" ]; then
25 inst_multiple bash
26 (ln -s bash "${initdir}/bin/sh" || :)
27 fi
28
29 # add common users in /etc/passwd, it will be used by nfs/ssh currently
30 # use password for hostonly images to facilitate secure sulogin in emergency console
31 [[ $hostonly ]] && pwshadow='x'
32 grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo "root:$pwshadow:0:0::/root:/bin/sh" >> "$initdir/etc/passwd"
33 grep '^nobody:' $dracutsysrootdir/etc/passwd >> "$initdir/etc/passwd"
34
35 [[ $hostonly ]] && grep '^root:' $dracutsysrootdir/etc/shadow >> "$initdir/etc/shadow"
36
37 # install our scripts and hooks
38 inst_script "$moddir/init.sh" "/init"
39 inst_script "$moddir/initqueue.sh" "/sbin/initqueue"
40 inst_script "$moddir/loginit.sh" "/sbin/loginit"
41 inst_script "$moddir/rdsosreport.sh" "/sbin/rdsosreport"
42 inst_script "$moddir/memtrace-ko.sh" "/sbin/tracekomem"
43
44 [ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib
45 mkdir -m 0755 -p ${initdir}/lib/dracut
46 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks
47
48 mkdir -p ${initdir}/tmp
49
50 inst_simple "$moddir/dracut-lib.sh" "/lib/dracut-lib.sh"
51 mkdir -p "${initdir}/var"
52
53 if ! dracut_module_included "systemd"; then
54 inst_multiple switch_root || dfatal "Failed to install switch_root"
55 inst_hook cmdline 10 "$moddir/parse-root-opts.sh"
56 inst_multiple -o $systemdutildir/systemd-timestamp
57 fi
58
59 if [[ $realinitpath ]]; then
60 for i in $realinitpath; do
61 echo "rd.distroinit=$i"
62 done > "${initdir}/etc/cmdline.d/distroinit.conf"
63 fi
64
65 ln -fs /proc/self/mounts "$initdir/etc/mtab"
66 if [[ $ro_mnt = yes ]]; then
67 echo ro >> "${initdir}/etc/cmdline.d/base.conf"
68 fi
69
70 [ -e "${initdir}/usr/lib" ] || mkdir -m 0755 -p ${initdir}/usr/lib
71
72 local VERSION=""
73 local PRETTY_NAME=""
74 # Derive an os-release file from the host, if it exists
75 if [ -e $dracutsysrootdir/etc/os-release ]; then
76 . $dracutsysrootdir/etc/os-release
77 grep -hE -ve '^VERSION=' -ve '^PRETTY_NAME' $dracutsysrootdir/etc/os-release >${initdir}/usr/lib/initrd-release
78 [[ -n ${VERSION} ]] && VERSION+=" "
79 [[ -n ${PRETTY_NAME} ]] && PRETTY_NAME+=" "
80 else
81 # Fall back to synthesizing one, since dracut is presently used
82 # on non-systemd systems as well.
83 {
84 echo NAME=dracut
85 echo ID=dracut
86 echo VERSION_ID=\"$DRACUT_VERSION\"
87 echo ANSI_COLOR='"0;34"'
88 } >${initdir}/usr/lib/initrd-release
89 fi
90 VERSION+="dracut-$DRACUT_VERSION"
91 PRETTY_NAME+="dracut-$DRACUT_VERSION (Initramfs)"
92 {
93 echo VERSION=\"$VERSION\"
94 echo PRETTY_NAME=\"$PRETTY_NAME\"
95 # This addition is relatively new, intended to allow software
96 # to easily detect the dracut version if need be without
97 # having it mixed in with the real underlying OS version.
98 echo DRACUT_VERSION=\"${DRACUT_VERSION}\"
99 } >> $initdir/usr/lib/initrd-release
100 echo dracut-$DRACUT_VERSION > $initdir/lib/dracut/dracut-$DRACUT_VERSION
101 ln -sf ../usr/lib/initrd-release $initdir/etc/initrd-release
102 ln -sf initrd-release $initdir/usr/lib/os-release
103 ln -sf initrd-release $initdir/etc/os-release
104
105 ## save host_devs which we need bring up
106 if [[ $hostonly_cmdline == "yes" ]]; then
107 if [[ -n "${host_devs[@]}" ]]; then
108 dracut_need_initqueue
109 fi
110 if [[ -f "$initdir/lib/dracut/need-initqueue" ]] || ! dracut_module_included "systemd"; then
111 (
112 if dracut_module_included "systemd"; then
113 DRACUT_SYSTEMD=1
114 fi
115 PREFIX="$initdir"
116
117 . "$moddir/dracut-lib.sh"
118
119 for _dev in "${host_devs[@]}"; do
120 for _dev2 in "${root_devs[@]}"; do
121 [[ "$_dev" == "$_dev2" ]] && continue 2
122 done
123
124 # We only actually wait for real devs - swap is only needed
125 # for resume and udev rules generated when parsing resume=
126 # argument take care of the waiting for us
127 for _dev2 in "${swap_devs[@]}"; do
128 [[ "$_dev" == "$_dev2" ]] && continue 2
129 done
130
131 _pdev=$(get_persistent_dev $_dev)
132
133 case "$_pdev" in
134 /dev/?*) wait_for_dev $_pdev;;
135 *) ;;
136 esac
137 done
138 )
139 fi
140 fi
141 }