[arch-projects] [mkinitcpio][PATCH 1/4] /run/initramfs: keep a copy of the initramfs
This is useful for the future shutdown hook, and might make debugging easier, as well as potentially opening up for other usecases (that I cannot yet imagine ;-) ). For the time being we exclude the kernel modules, this decision could be revisited in the future. Signed-off-by: Tom Gundersen <teg@jklm.no> --- init | 4 ++++ install/base | 1 + 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/init b/init index 53c64d5..7f809cc 100644 --- a/init +++ b/init @@ -112,6 +112,10 @@ if [ "${udevd_running}" -eq 1 ]; then udevadm info --cleanup-db fi +# keep a copy of the initramfs around, excluding the kernel modules +rm -r /lib/modules +cp -ax / /run/initramfs + exec env -i "TERM=$TERM" /sbin/switch_root /new_root $init "$@" # vim: set ft=sh ts=4 sw=4 et: diff --git a/install/base b/install/base index 0726fa2..84e7f02 100644 --- a/install/base +++ b/install/base @@ -10,6 +10,7 @@ build() { add_binary /sbin/blkid add_binary /bin/mount add_binary /sbin/switch_root + add_binary /bin/cp add_symlink "/etc/mtab" "/proc/self/mounts" -- 1.7.7.4
Now we fail silently if the file exists, which means there is no easy way to overwrite binaries. I think it makes the most sense to do the following: 1) add all the busybox stuff as a basic system; 2) overwrite some of the links with any binaries we add to base hook; 3) allow users to write their own hooks to overwrite even more stuff. This can now be done by this hook. v2: make sure we are able to overwrite a symlink pointing to a directory Signed-off-by: Tom Gundersen <teg@jklm.no> --- functions | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/functions b/functions index ef4463e..401fa5c 100644 --- a/functions +++ b/functions @@ -82,7 +82,6 @@ _add_file() { # $3: mode (( $# == 3 )) || return $EINVAL - [[ -e "$BUILDROOT$1" ]] && return $EEXIST (( QUIET )) || plain "adding file: %s" "$1" command install -Dm$3 "$2" "$BUILDROOT$1" @@ -106,10 +105,9 @@ _add_symlink() { # $2: target of $1 (( $# == 2 )) || return $EINVAL - [[ -L "$BUILDROOT$1" ]] && return $EEXIST (( QUIET )) || plain "adding symlink: %s -> %s" "$1" "$2" - ln -s "$2" "$BUILDROOT$1" + ln -sfn "$2" "$BUILDROOT$1" } auto_modules() { -- 1.7.7.4
Add compat symlinks from /bin, /sbin and /usr/sbin, so nothing is lost. This will make sure that it is not possibly to install two different versions of the same binary in PATH. The main usecase of this is that we want to be able to override any symlink provided by busybox by adding a binary by the same name. With this patch we don't have to worry in case the busybox symlink and the binary we add are in different directories; the last binary to be added always takes precedence. Signed-off-by: Tom Gundersen <teg@jklm.no> --- init | 5 ++--- install/base | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/init b/init index 7f809cc..4c07f9d 100644 --- a/init +++ b/init @@ -1,6 +1,5 @@ -#!/bin/busybox ash -# Install busybox's applets as symlinks -PATH=/usr/sbin:/usr/bin:/sbin:/bin +#!/usr/bin/ash +PATH=/usr/bin /bin/busybox --install -s diff --git a/install/base b/install/base index 84e7f02..c0c19d2 100644 --- a/install/base +++ b/install/base @@ -1,10 +1,14 @@ #!/bin/bash build() { - for dir in new_root proc sys dev run usr/{bin,sbin}; do + for dir in new_root proc sys dev run usr/bin; do add_dir "/$dir" done + add_symlink /sbin usr/bin + add_symlink /bin usr/bin + add_symlink /usr/sbin bin + add_binary /lib/initcpio/busybox /bin/busybox add_binary /sbin/modprobe add_binary /sbin/blkid -- 1.7.7.4
This means that no "setup" of the initramfs is requried on boot, and this should make testing a lot eaiser by just chrooting into the ramfs to check if it works. Signed-off-by: Tom Gundersen <teg@jklm.no> --- init | 2 -- install/base | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/init b/init index 4c07f9d..51b2969 100644 --- a/init +++ b/init @@ -1,8 +1,6 @@ #!/usr/bin/ash PATH=/usr/bin -/bin/busybox --install -s - . /init_functions mount -t proc proc /proc -o nosuid,noexec,nodev diff --git a/install/base b/install/base index c0c19d2..59c3629 100644 --- a/install/base +++ b/install/base @@ -10,6 +10,11 @@ build() { add_symlink /usr/sbin bin add_binary /lib/initcpio/busybox /bin/busybox + + for applet in `/lib/initcpio/busybox --list`; do + add_symlink "/usr/bin/$applet" busybox + done + add_binary /sbin/modprobe add_binary /sbin/blkid add_binary /bin/mount -- 1.7.7.4
On 11/26/2011 08:17 AM, Tom Gundersen wrote:
This means that no "setup" of the initramfs is requried on boot, and this should make testing a lot eaiser by just chrooting into the ramfs to check if it works.
Signed-off-by: Tom Gundersen<teg@jklm.no> --- init | 2 -- install/base | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/init b/init index 4c07f9d..51b2969 100644 --- a/init +++ b/init @@ -1,8 +1,6 @@ #!/usr/bin/ash PATH=/usr/bin
-/bin/busybox --install -s - . /init_functions
mount -t proc proc /proc -o nosuid,noexec,nodev diff --git a/install/base b/install/base index c0c19d2..59c3629 100644 --- a/install/base +++ b/install/base @@ -10,6 +10,11 @@ build() { add_symlink /usr/sbin bin
add_binary /lib/initcpio/busybox /bin/busybox + + for applet in `/lib/initcpio/busybox --list`; do + add_symlink "/usr/bin/$applet" busybox + done + add_binary /sbin/modprobe add_binary /sbin/blkid add_binary /bin/mount you can use $() instead of `` ;)
-- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
On Sat, Nov 26, 2011 at 1:03 PM, Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> wrote:
On 11/26/2011 08:17 AM, Tom Gundersen wrote:
This means that no "setup" of the initramfs is requried on boot, and this should make testing a lot eaiser by just chrooting into the ramfs to check if it works.
Signed-off-by: Tom Gundersen<teg@jklm.no> --- init | 2 -- install/base | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/init b/init index 4c07f9d..51b2969 100644 --- a/init +++ b/init @@ -1,8 +1,6 @@ #!/usr/bin/ash PATH=/usr/bin
-/bin/busybox --install -s - . /init_functions
mount -t proc proc /proc -o nosuid,noexec,nodev diff --git a/install/base b/install/base index c0c19d2..59c3629 100644 --- a/install/base +++ b/install/base @@ -10,6 +10,11 @@ build() { add_symlink /usr/sbin bin
add_binary /lib/initcpio/busybox /bin/busybox + + for applet in `/lib/initcpio/busybox --list`; do + add_symlink "/usr/bin/$applet" busybox + done + add_binary /sbin/modprobe add_binary /sbin/blkid add_binary /bin/mount
you can use $() instead of `` ;)
Good point. I fixed that up on my public tree (in case you want to pull from there Dave): <https://github.com/teg/mkinitcpio/tree/work>. -t
participants (2)
-
Gerardo Exequiel Pozzi
-
Tom Gundersen