[systemd-devel] systemctl switch-root /sysroot without deleting old_root

Richard Maw richard.maw at codethink.co.uk
Sat Nov 7 04:31:02 PST 2015


On Sat, Nov 07, 2015 at 01:17:29PM +0100, hgr1 wrote:
> Am 2015-11-07 12:33, schrieb Richard Maw:
> >You can remove /etc/initrd-release to stop it removing the old
> >rootfs tmpfs,
> >I'm not sure what other side-effects this may have.
> This was my first attempt too but switch-root is checking the
> existance of /etc/initrd-release via in_initrd() which saves its
> result as a static variable. Therefore I would need to patch with
> something like:
> 
> diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c
> index 813641a..307b7f3 100644
> --- a/src/shared/switch-root.c
> +++ b/src/shared/switch-root.c
> @@ -54,7 +54,7 @@ int switch_root(const char *new_root, const char
> *oldroot, bool detach_oldroot,
>          temporary_old_root = strjoina(new_root, oldroot);
>          mkdir_p_label(temporary_old_root, 0755);
> 
> -        old_root_remove = in_initrd();
> +        old_root_remove = in_initrd() &&
> access("/etc/initrd-release", F_OK) >= 0;
> 
>          if (stat(new_root, &new_root_stat) < 0)
>                  return log_error_errno(errno, "Failed to stat
> directory %s: %m", new_root);
> 
> Or maybe an uncached version of in_initrd() e.g. _in_initrd() could
> fit. Maybe I'm missing something here.

By some definition, your initial tmpfs isn't an initrd, so you could try
removing initrd-release from your cpio image, so it's gone before systemd
starts, so it can't cache an invalid result.


More information about the systemd-devel mailing list