1 |
commit: 94dc288487f2cb5c993ed471ed490a0031a65acc |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Feb 6 08:33:10 2012 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 6 09:31:59 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=94dc2884 |
7 |
|
8 |
Customizable initramfs compression based on Pentoo genkernel fork |
9 |
|
10 |
This implements customizable initramfs compression, based on the Pentoo |
11 |
genkernel fork (SVN revs r2142, r2145, by Jens Pranaitis |
12 |
<jens <AT> chaox.net>). |
13 |
|
14 |
New configuration option COMPRESS_INITRD_TYPE to allow manual selection, |
15 |
whereas the Pentoo fork provided auto-selection based on what was |
16 |
available in the kernel configuration. Auto-selection is used by |
17 |
default, and is available with the argument of 'best' to the new option. |
18 |
|
19 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
20 |
|
21 |
--- |
22 |
ChangeLog | 4 +++ |
23 |
defaults/config.sh | 3 +- |
24 |
gen_cmdline.sh | 6 ++++- |
25 |
gen_determineargs.sh | 1 + |
26 |
gen_initramfs.sh | 62 ++++++++++++++++++++++++++++++++++++++----------- |
27 |
genkernel.conf | 3 ++ |
28 |
6 files changed, 63 insertions(+), 16 deletions(-) |
29 |
|
30 |
diff --git a/ChangeLog b/ChangeLog |
31 |
index d6e4dcf..e2cc9ab 100644 |
32 |
--- a/ChangeLog |
33 |
+++ b/ChangeLog |
34 |
@@ -5,6 +5,10 @@ |
35 |
# Distributed under the GPL v2 |
36 |
# $Id$ |
37 |
|
38 |
+ 06 Feb 2012; Robin H. Johnson <robbat2@g.o> defaults/config.sh, |
39 |
+ gen_cmdline.sh, gen_determineargs.sh, gen_initramfs.sh, genkernel.conf: |
40 |
+ Import customizable compression for initramfs, based on Pentoo development. |
41 |
+ |
42 |
06 Feb 2012: Richard Yao <ryao@×××××××××××××.edu> arch/alpha/modules_load, |
43 |
arch/arm/modules_load, arch/ia64/modules_load, arch/mips/modules_load, |
44 |
arch/parisc/modules_load, arch/parisc64/modules_load, arch/ppc/modules_load, |
45 |
|
46 |
diff --git a/defaults/config.sh b/defaults/config.sh |
47 |
index d135e0e..7ee9ef2 100755 |
48 |
--- a/defaults/config.sh |
49 |
+++ b/defaults/config.sh |
50 |
@@ -12,7 +12,8 @@ KERNEL_MAKE_DIRECTIVE_2="" |
51 |
KERNEL_BINARY="arch/i386/boot/bzImage" |
52 |
KERNEL_BINARY_OVERRIDE="" |
53 |
|
54 |
-COMPRESS_INITRD=yes |
55 |
+DEFAULT_COMPRESS_INITRD=yes |
56 |
+DEFAULT_COMPRESS_INITRD_TYPE=best |
57 |
|
58 |
# |
59 |
# Arch-specific defaults that can be overridden in the config file or on the |
60 |
|
61 |
diff --git a/gen_cmdline.sh b/gen_cmdline.sh |
62 |
index de56a25..aabaa7e 100755 |
63 |
--- a/gen_cmdline.sh |
64 |
+++ b/gen_cmdline.sh |
65 |
@@ -537,10 +537,14 @@ parse_cmdline() { |
66 |
CMD_INTEGRATED_INITRAMFS=`parse_optbool "$*"` |
67 |
print_info 2 "CMD_INTEGRATED_INITRAMFS=${CMD_INTEGRATED_INITRAMFS}" |
68 |
;; |
69 |
- --compress-initramfs|--no-compress-initramfs) |
70 |
+ --compress-initramfs|--no-compress-initramfs|--compress-initrd|--no-compress-initrd) |
71 |
CMD_COMPRESS_INITRD=`parse_optbool "$*"` |
72 |
print_info 2 "CMD_COMPRESS_INITRD=${CMD_COMPRESS_INITRD}" |
73 |
;; |
74 |
+ --compress-initramfs-type=*|--compress-initrd-type=*) |
75 |
+ COMPRESS_INITRD_TYPE=`parse_opt "$*"` |
76 |
+ print_info 2 "CMD_COMPRESS_INITRD_TYPE: ${CMD_LINUXRC}" |
77 |
+ ;; |
78 |
--config=*) |
79 |
print_info 2 "CMD_GK_CONFIG: `parse_opt "$*"`" |
80 |
;; |
81 |
|
82 |
diff --git a/gen_determineargs.sh b/gen_determineargs.sh |
83 |
index e6ed0a3..4a21530 100755 |
84 |
--- a/gen_determineargs.sh |
85 |
+++ b/gen_determineargs.sh |
86 |
@@ -76,6 +76,7 @@ determine_real_args() { |
87 |
set_config_with_override STRING KNAME CMD_KERNNAME "genkernel" |
88 |
|
89 |
set_config_with_override STRING COMPRESS_INITRD CMD_COMPRESS_INITRD "$DEFAULT_COMPRESS_INITRD" |
90 |
+ set_config_with_override STRING COMPRESS_INITRD_TYPE CMD_COMPRESS_INITRD_TYPE "$DEFAULT_COMPRESS_INITRD_TYPE" |
91 |
set_config_with_override STRING MAKEOPTS CMD_MAKEOPTS "$DEFAULT_MAKEOPTS" |
92 |
set_config_with_override STRING KERNEL_MAKE CMD_KERNEL_MAKE "$DEFAULT_KERNEL_MAKE" |
93 |
set_config_with_override STRING UTILS_MAKE CMD_UTILS_MAKE "$DEFAULT_UTILS_MAKE" |
94 |
|
95 |
diff --git a/gen_initramfs.sh b/gen_initramfs.sh |
96 |
index 170361b..3aab15d 100755 |
97 |
--- a/gen_initramfs.sh |
98 |
+++ b/gen_initramfs.sh |
99 |
@@ -686,23 +686,57 @@ create_initramfs() { |
100 |
append_data 'overlay' |
101 |
fi |
102 |
|
103 |
- # Implement support for disabling compression |
104 |
- if isTrue "${COMPRESS_INITRD}" |
105 |
- then |
106 |
- compress_ext=".gz" |
107 |
- print_info 1 " >> Compressing cpio data..." |
108 |
- gzip -9 "${CPIO}" || gen_die "Compression failed" |
109 |
- mv -f "${CPIO}.gz" "${CPIO}" || gen_die "Rename failed" |
110 |
- fi |
111 |
- |
112 |
- |
113 |
if isTrue "${INTEGRATED_INITRAMFS}" |
114 |
then |
115 |
-# cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/usr/initramfs_data.cpio.gz |
116 |
- mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio${compress_ext} |
117 |
-# sed -i "s|^.*CONFIG_INITRAMFS_SOURCE=.*$|CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio.gz\"|" ${KERNEL_DIR}/.config |
118 |
+ # Explicitly do not compress if we are integrating into the kernel. |
119 |
+ # The kernel will do a better job of it than us. |
120 |
+ mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio |
121 |
sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config |
122 |
- echo -e "CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio${compress_ext}\"\nCONFIG_INITRAMFS_ROOT_UID=0\nCONFIG_INITRAMFS_ROOT_GID=0" >> ${KERNEL_DIR}/.config |
123 |
+ cat >>${KERNEL_DIR}/.config <<-EOF |
124 |
+ CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}" |
125 |
+ CONFIG_INITRAMFS_ROOT_UID=0 |
126 |
+ CONFIG_INITRAMFS_ROOT_GID=0 |
127 |
+ EOF |
128 |
+ else |
129 |
+ if isTrue "${COMPRESS_INITRD}" |
130 |
+ then |
131 |
+ cmd_xz=$(type -p xz) |
132 |
+ cmd_lzma=$(type -p lzma) |
133 |
+ cmd_bzip2=$(type -p bzip2) |
134 |
+ cmd_gzip=$(type -p gzip) |
135 |
+ cmd_lzop=$(type -p lzop) |
136 |
+ local compression |
137 |
+ case ${COMPRESS_INITRD_TYPE} in |
138 |
+ xz|lzma|bzip2|gzip2|lzo) compression=${COMPRESS_INITRD_TYPE} ;; |
139 |
+ best) |
140 |
+ if grep -sq '^CONFIG_RD_XZ=y' ${KERNEL_DIR}/.config && test -n "${cmd_xz}" ; |
141 |
+ compression=xz |
142 |
+ elif grep -sq '^CONFIG_RD_LZMA=y' ${KERNEL_DIR}/.config && test -n "${cmd_lzma}" ; |
143 |
+ compression=lzma |
144 |
+ elif grep -sq '^CONFIG_RD_BZIP2=y' ${KERNEL_DIR}/.config && test -n "${cmd_bzip2}" ; |
145 |
+ compression=bzip2 |
146 |
+ elif grep -sq '^CONFIG_RD_GZIP=y' ${KERNEL_DIR}/.config && test -n "${cmd_gzip}" ; |
147 |
+ compression=gzip |
148 |
+ elif grep -sq '^CONFIG_RD_LZO=y' ${KERNEL_DIR}/.config && test -n "${cmd_lzop}" ; |
149 |
+ compression=lzo |
150 |
+ fi ;; |
151 |
+ esac |
152 |
+ case $compression in |
153 |
+ xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;; |
154 |
+ lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;; |
155 |
+ bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" |
156 |
+ gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;; |
157 |
+ lzo) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;; |
158 |
+ esac |
159 |
+ |
160 |
+ if [ -n "${compression}" ]; then |
161 |
+ print_info 1 " >> Compressing cpio data (${compress_ext})..." |
162 |
+ ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed" |
163 |
+ mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed" |
164 |
+ else |
165 |
+ print_info 1 " >> Not compressing cpio data ..." |
166 |
+ fi |
167 |
+ fi |
168 |
fi |
169 |
|
170 |
if isTrue "${CMD_INSTALL}" |
171 |
|
172 |
diff --git a/genkernel.conf b/genkernel.conf |
173 |
index 7032ac7..22b18d7 100644 |
174 |
--- a/genkernel.conf |
175 |
+++ b/genkernel.conf |
176 |
@@ -319,6 +319,9 @@ GPG_BINCACHE="%%CACHE%%/gnupg-${GPG_VER}-%%ARCH%%.bz2" |
177 |
|
178 |
# Compress generated initramfs |
179 |
#COMPRESS_INITRD="yes" |
180 |
+# Types of compression: best, xz, lzma, bzip2, gzip, lzop |
181 |
+# "best" selects the best available compression method |
182 |
+#COMPRESS_INITRD_TYPE="best" |
183 |
|
184 |
|
185 |
# Create a self-contained env in the initramfs |