From owner-freebsd-hackers@freebsd.org Sun Aug 23 17:40:03 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BA2CE3C2FD9 for ; Sun, 23 Aug 2020 17:40:03 +0000 (UTC) (envelope-from gljennjohn@gmail.com) Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BZMw25M8wz3dRl for ; Sun, 23 Aug 2020 17:40:02 +0000 (UTC) (envelope-from gljennjohn@gmail.com) Received: by mail-wm1-x341.google.com with SMTP id a65so2658255wme.5 for ; Sun, 23 Aug 2020 10:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=d47FU/prDMXd2fD634AsByyFRVfn+nHIZVpOYl1WBa0=; b=ktRyIem15xdLiVcQ6VJ3OyK+GFmoqC5BrmPG+4PlvAiiayPq7UVwFEOdhou2xDpzSk HEcpqRUwAGzTh1X9sIFHdW0hjd30GQYl05siKB0f8RtKB3gM0lbmGQ+pCSsXckmveaTH 9W+Ut3hw7yj2KYy+pY6Q8xxNEpCFT6ny1T5C0n/9TlMbNzoJ3d9SZFMKoACHQ3g/RLj6 bU7PbC+9GnvfW2TnzR6YSG4qodJwzknclD/CYeSs90RJtw4qBop4ocSWl2DmrLGdVQ66 vpQxNDDZKfWo+JKBS6DuucApYXSrCVPUuATJzIL3xjaxwMwMC3fnz/p/ltS/1uIoT8K0 TdbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=d47FU/prDMXd2fD634AsByyFRVfn+nHIZVpOYl1WBa0=; b=XUdVjkM8VbnemfJuOhYjclIMnOO05WJoSxgUT6SzUlhR2CNjnOKNJ2LMKsNMo5J2Fi ZJbBrubpDabvoxxJIgwTv9Z8sqXGGKQCE0z3sh+jSPjfOEuDFKJFXPfDFpDJw+QvKACh eUSX6b4dUmzS2jouns3T/VTdL2gfWoe8FQXoXnHaKoWt36GQTnFGT47alIj4aC/ULz79 FpF5xrYuAsKX6S92O0k87toNaxKz9Gdi1eR+vTROYd/eXVRynmBs1+YBuvR/s5wuidA5 CPs36nDaohNkQa5siGrk9FUKXVDd3j9vW593bJuxILl02F3s9zIxMw++eaRCqS9VvuA2 0HBg== X-Gm-Message-State: AOAM532nYxRud7lWP2JiCAE25Zs2GsWe0qsh9cu9vecG5TlA1m7cSL9d sgtUfzM6NoshyzLCNndmheM= X-Google-Smtp-Source: ABdhPJwq0mi6RgDlJISRh4yPi/oOAxCEFZ9Qnkrh4Ds6X9f6+HqK46COVxLcn1byyY+iJ+vhaGz+7g== X-Received: by 2002:a1c:96c5:: with SMTP id y188mr2266629wmd.72.1598204400559; Sun, 23 Aug 2020 10:40:00 -0700 (PDT) Received: from ernst.home (pd9e23482.dip0.t-ipconnect.de. [217.226.52.130]) by smtp.gmail.com with ESMTPSA id m3sm9554221wru.79.2020.08.23.10.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2020 10:39:59 -0700 (PDT) Date: Sun, 23 Aug 2020 19:39:58 +0200 From: Gary Jennejohn To: guyvert@secmail.pro Cc: freebsd-hackers@freebsd.org Subject: Re: Running BSD from RAM memory using zroot Message-ID: <20200823193958.059882be@ernst.home> In-Reply-To: <6a7da06949dbd8f1c38d5faa22f3f28b.squirrel@giyzk7o6dcunb2ry.onion> References: <6a7da06949dbd8f1c38d5faa22f3f28b.squirrel@giyzk7o6dcunb2ry.onion> Reply-To: gljennjohn@gmail.com X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; amd64-portbld-freebsd13.0) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4BZMw25M8wz3dRl X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=ktRyIem1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of gljennjohn@gmail.com designates 2a00:1450:4864:20::341 as permitted sender) smtp.mailfrom=gljennjohn@gmail.com X-Spamd-Result: default: False [-1.26 / 15.00]; HAS_REPLYTO(0.00)[gljennjohn@gmail.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; REPLYTO_ADDR_EQ_FROM(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; NEURAL_HAM_SHORT(-0.26)[-0.259]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RECEIVED_SPAMHAUS_PBL(0.00)[217.226.52.130:received]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_REPLYTO(0.00)[gmail.com]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::341:from]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Aug 2020 17:40:03 -0000 On Sun, 23 Aug 2020 05:51:39 -0700 guyvert@secmail.pro wrote: > Hello list, > > I am trying to get FreeBSD to operate entirely within RAM, thus no disks. > Either boot via PXE/NFS/TFTP or via a SD card or eMMC that is read-only. > > I now have: > Filesystem Size Used Avail Capacity Mounted on > /dev/md0 18M 16M 956K 95% / > zroot 1.7G 512M 1.2G 29% / > devfs 1.0K 1.0K 0B 100% /dev > > The /dev/md0 is of type preloaded, and loaded from ISO CD using mfsroot > variables in /boot/loader.conf. The ZFS pool is called 'zroot' and has > only one filesystem, though more can be created like zroot/var/log and set > quota's on that filesystem so logs cannot claim too much RAM memory. > > With mount we can see the FSID, but we cannot unmount the /dev/md0 because > unmounting root filesystems appears to be explicitely forbidden, as 'man > umount' says: > "The root file system cannot be forcibly unmounted." > > But that is only by current design, right? We already have another root > filesystem (the zroot) and no open files should be in use on the original > root filesystem (/dev/md0). Interestingly, while /dev/md0 cannot be > unmounted, the actual block device can be forcibly destroyed. This appears > to work without problems, because the mounted /dev/md0 is not read from or > written to. But of course, i would like to get rid of it altogether, and > just have the zroot filesystem and no more /dev/md0. > > My question to you guys is, would any of you like to work on changing this > behaviour? It would allow for a neat setup where, once booted, the system > runs inside RAM using a memory disk (mdconfig) with a ZFS pool on top. > Once the ZFS root filesystem is populated with the base and kernel, the > mountpoint is changed to root: > > zfs set mountpoint=/ zroot > > That simple, now the system runs on RAM. To reduce RAM usage, compression > can be enabled, and soon zstd compression will be available. > > Advantages: > - No more unstable system if the system disk has problems, crashes, bad > sectors, corruption, whatever. > - Potentially faster because we read from RAM and not from disk. > - Does not wear out MicroSD/eMMC/SSD flash because it is used read-only. > - Better than tmpfs because of compression options, as well as many other > cool features of ZFS like snapshots etc. > - RAM can be encrypted if desired by using 'geli onetime /dev/md1' and > using md1.eli as the zroot disk. This would help against Cold Boot Attack. > > Disadvantage would be slightly longer boot time, complexity and by default > about 0.5GB RAM used, which can grow as the system is used. But that is > worth it for me. And you can always mount something persistent on say /var > and /home and leave the rest as volatile in-RAM filesystem. > > To avoid double RAM caching (first the md block device, then ZFS ARC > cache) the primarycache and secondarycache can be changed to prevent ZFS > from caching anything and read everything from block device instead. > > Even better would be to adapt ZFS to allow for in-memory filesystems. Then > the ARC would be the actual backing and those caches would be persistent > until the pool is destroyed or the system is reboot. But that requires > more work, currently i'm already excited about running BSD from RAM. > > But my question: is there any way to force unmount of the unneeded > /dev/md0 which is preloaded md (mfsroot) ? I see two approaches: > > 1. Adapt the umount utility to allow force unmount of root filesystem, > which is currently forbidden. Should be a one-line patch? > 2. Rewrite the init program so that no preloaded md is required, but init > does the work of creating md disk, zroot pool and populating the base > system and kernel from archive (base.txz and kernel.txz which reside on > MicroSD/eMMC/ISO). > > Anyone thinks this is interesting? > Take a look at mount.conf(5). It seems like this may do what you want. -- Gary Jennejohn