| 174 | |
| 175 | |
| 176 | == rebuilding or modifying an initramfs |
| 177 | You can modify an external initramfs fairly easily with the {{{cpio}}} tool. You merely need to uncompress it (if compressed) and use the extract parameter. You will want to do this as root in order to preserve file ownership of root files. |
| 178 | |
| 179 | Example: |
| 180 | 1. extract files from an existing gzipped cpio: |
| 181 | {{{#!bash |
| 182 | # uncompress it (if compressed) and use {{{cpio -i}}} to extract it: |
| 183 | # -i extract |
| 184 | # -d create directories |
| 185 | # -m preserve mtime |
| 186 | # -v verbose |
| 187 | mkdir rootfs_mod |
| 188 | (cd rootfs_mod; gzip -cd ../cpio | sudo cpio -idmv) |
| 189 | }}} |
| 190 | 2. modify it; for example overwrite or create your own /init: |
| 191 | cat <<EOF >rootfs_mod/init |
| 192 | #!/bin/busybox sh |
| 193 | mount -t devtmpfs devtmpfs /dev |
| 194 | mount -t proc proc /proc |
| 195 | mount -t sysfs sysfs /sys |
| 196 | mount -t tmpfs tmpfs /tmp |
| 197 | |
| 198 | echo "Hello world!" |
| 199 | sh |
| 200 | EOF |
| 201 | chmod +x rootfs_mod/init |
| 202 | }}} |
| 203 | 1. re-create it |
| 204 | {{{#!bash |
| 205 | (cd rootfs_mod; find . | cpio -ov --format=newc) | gzip -9 > cpio |
| 206 | }}} |