From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7CB9C3F2D2 for ; Thu, 5 Mar 2020 20:21:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A0FB207FD for ; Thu, 5 Mar 2020 20:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726164AbgCEUV0 (ORCPT ); Thu, 5 Mar 2020 15:21:26 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:49780 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726080AbgCEUV0 (ORCPT ); Thu, 5 Mar 2020 15:21:26 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j9wzk-005u6z-JP; Thu, 05 Mar 2020 20:21:24 +0000 Date: Thu, 5 Mar 2020 20:21:24 +0000 From: Al Viro To: Ignat Korchagin Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@cloudflare.com Subject: Re: [PATCH] mnt: add support for non-rootfs initramfs Message-ID: <20200305202124.GV23230@ZenIV.linux.org.uk> References: <20200305193511.28621-1-ignat@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200305193511.28621-1-ignat@cloudflare.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu, Mar 05, 2020 at 07:35:11PM +0000, Ignat Korchagin wrote: > The main need for this is to support container runtimes on stateless Linux > system (pivot_root system call from initramfs). > > Normally, the task of initramfs is to mount and switch to a "real" root > filesystem. However, on stateless systems (booting over the network) it is just > convenient to have your "real" filesystem as initramfs from the start. > > This, however, breaks different container runtimes, because they usually use > pivot_root system call after creating their mount namespace. But pivot_root does > not work from initramfs, because initramfs runs form rootfs, which is the root > of the mount tree and can't be unmounted. > > One can solve this problem from userspace, but it is much more cumbersome. We > either have to create a multilayered archive for initramfs, where the outer > layer creates a tmpfs filesystem and unpacks the inner layer, switches root and > does not forget to properly cleanup the old rootfs. Or we need to use keepinitrd > kernel cmdline option, unpack initramfs to rootfs, run a script to create our > target tmpfs root, unpack the same initramfs there, switch root to it and again > properly cleanup the old root, thus unpacking the same archive twice and also > wasting memory, because kernel stores compressed initramfs image indefinitely. > > With this change we can ask the kernel (by specifying nonroot_initramfs kernel > cmdline option) to create a "leaf" tmpfs mount for us and switch root to it > before the initramfs handling code, so initramfs gets unpacked directly into > the "leaf" tmpfs with rootfs being empty and no need to clean up anything. IDGI. Why not simply this as the first thing from your userland: mount("/", "/", NULL, MS_BIND | MS_REC, NULL); chdir("/.."); chroot("."); 3 syscalls and you should be all set...