Bug 274977 - [rc] [patch] /etc/rc.initdiskless: /rescue/tar: not found
Summary: [rc] [patch] /etc/rc.initdiskless: /rescue/tar: not found
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 13.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-rc (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-08 22:43 UTC by Cheng Cui
Modified: 2024-01-19 15:46 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cheng Cui freebsd_committer freebsd_triage 2023-11-08 22:43:51 UTC
During the installation of FreeBSD13.2 via UEFI PXE on a mini PC, I encountered this problem from the console.

* /etc/rc.initdiskless: /rescue/tar: not found: I didn’t found this file in the base system extracted from the official archives such as FreeBSD-13.2-RELEASE-amd64-bootonly.iso or FreeBSD-13.2-RELEASE-amd64-disc1.iso. Instead, I edited the etc/rc.initdiskless file where the tar is:

diff --git a/libexec/rc/rc.initdiskless b/libexec/rc/rc.initdiskless
index 9b37497c1e7e..ac305ffced5f 100644
--- a/libexec/rc/rc.initdiskless
+++ b/libexec/rc/rc.initdiskless
@@ -376,7 +376,7 @@ for i in ${templates} ; do
        if [ -f $j ]; then
            create_md $subdir
            echo "Loading /$subdir from cpio archive $j"
-           (cd / ; /rescue/tar -xpf $j)
+           (cd / ; /usr/bin/tar -xpf $j)
        fi
     done
     for j in /conf/$i/*/extract ; do
Comment 1 Mina Galić freebsd_triage 2023-11-09 08:12:24 UTC
this code hasn't changed in 18 years: base ed5b9e57cdcb31ea939330f8c0e19ec2cc3d16b9
likewise, the last time anything about /rescue/tar changed was 19 years ago: base cc7f9762118bcdef7c5f7bb2504f761aeac8eddf

otoh, if /rescue isn't anywhere on those ISOs, but /usr/bin is, maybe it's time for a change
Comment 2 Cheng Cui freebsd_committer freebsd_triage 2023-11-24 21:00:19 UTC
The patch for this fix is in https://reviews.freebsd.org/D42765
Comment 3 Jose Luis Duran 2023-11-25 14:45:29 UTC
While I do not object to the change proposed in review D42765, I think the issue may be that you probably used the files from FreeBSD-13.2-RELEASE-amd64-bootonly.iso or FreeBSD-13.2-RELEASE-amd64-disc1.iso to populate your /tftpboot/FreeBSD/install directory? (see https://docs.freebsd.org/en/books/handbook/advanced-networking/#network-diskless).

These two images do not contain a /rescue indeed since https://cgit.freebsd.org/src/commit/?id=6e352319b6ff97a20b53d13a6df76b71dd12afc9, given it is a read-only media, it should not "need" a /rescue.

If you untar base from:
https://download.freebsd.org/releases/amd64/amd64/13.2-RELEASE/base.txz
into /tftpboot/FreeBSD/install, you'll notice that it indeed contains /rescue.

All that said, if that solves the problem, we should perhaps clarify the handbook to instruct the users on how to populate the /install directory, as having rc.initdiskless use the tar binary from /rescue may have its advantages as well.
Comment 4 Cheng Cui freebsd_committer freebsd_triage 2023-11-26 23:40:15 UTC
(In reply to Jose Luis Duran from comment #3)

Indeed, I took the release images for granted as the official archives from that handbook chapter. But the whole chapter has an example of NFS mounted root file system as read-only. So I think there should be no "need" of /rescue, as you also have mentioned.

So rc.initdiskless itself over read-only root file system does not need the tar binary from /rescue, does it?
Comment 5 Jose Luis Duran 2023-11-27 01:52:05 UTC
(In reply to Cheng Cui from comment #4)
Again, I'm not opposed to the change, I'm just saying that your system should have /rescue.
I was thinking about adding something like https://docs.freebsd.org/en/articles/remote-install/#mfsbsd-build to the documentation, in order to avoid that from happening to others.
Comment 6 Cheng Cui freebsd_committer freebsd_triage 2023-11-27 12:55:50 UTC
(In reply to Jose Luis Duran from comment #5)

I am confused. For a read-only root file system mounted as NFS, the whole installation process from network (PXE boot) does not need /rescue, does it?
Comment 7 Jose Luis Duran 2023-11-27 13:38:04 UTC
(In reply to Cheng Cui from comment #6)

Not for *installing* from a read-only file system, just like the CD-ROM, as you point out it is not needed.

However, rc.initdiskless may have other uses, such as with a very crunchgen'd minified or NanoBSD read-only embedded system.  But in those cases, /bin and /sbin *should* be there as well (even if linked from /rescue), so ultimately the proposed change *should* be OK.

From what I understood, the underlying issue is to share an installation media via NFS and use UEFI PXE to install to another systems?
Comment 8 Warner Losh freebsd_committer freebsd_triage 2023-11-27 16:30:34 UTC
I think this is a bad change.
It breaks / and /usr being on different partitions. The typical install had a local-ish / for /etc (with /etc being mounted on a MFS to allow changes and a way to persist it to disk) and everything being read-only mounted to avoid filesystem corruption on power failure.

Why don't you have /rescue? It's on / in default installations. you have to go out of your way to delete it.

The isos you talk about are installation isos. They don't have everything on them (they also don't have compilers, for example). If you are looking for an image, you'll likely be happier using one of the CI images we make available. Those have a full installation of base on them. Or extract from the base image sets that are on these installation CDs in /usr/freebsd-dist/base.txz.
Comment 9 Cheng Cui freebsd_committer freebsd_triage 2023-12-01 21:20:33 UTC
(In reply to Warner Losh from comment #8)

> It breaks / and /usr being on different partitions.

Please let me know if these are the partitions in default. Because as an average user who simply follows the bandbook and finds installation images from a well-known place like https://www.freebsd.org/where/, does not and shall not care about advanced details about where the "/rescue" is.

> Why don't you have /rescue?

After I re-installed my box again with FreeBSD 14.0-RELEASE through pxeboot and by using the content from the FreeBSD-14.0-RELEASE-amd64-disc1.iso, I found there shall be clarification that the execute of "rc.initdiskless" is part of the booting process, not a start of the installation process. So I encountered the "/rescue/tar: not found" again, but with the change I could finish the boot and then start the installation. Once the installation finished, I found the files in "/rescue". This means although there are no files in "/rescue" from the ISO, they will be generated during the installation. Then, the system has the "/rescue".

So far, the only place that the keyword "rescue" shows up in "rc.initdiskless" is where the "/rescue/tar" shall be replaced with "/usr/bin/tar" in the proposed patch. Given "rc.initdiskless" is used during the pxeboot, and files in "/rescue" are not ready yet and will be ready after the installation, I think the change is not bad.

Also please let me know if the revert of commit https://cgit.freebsd.org/src/commit/?id=6e352319b6ff97a20b53d13a6df76b71dd12afc9 is a better solution, although I don't think so.
Comment 10 Rodney W. Grimes freebsd_committer freebsd_triage 2023-12-02 22:01:17 UTC
Are you trying to directly use an .ISO image as a diskless boot image?

The proper steps for setting up a PXE/diskless boot server are in the handbook, and if they are followed this problem well not occur.

Specifically at 34.10.1 step 8:
Install the base system into ${NFSROOTDIR}, either by decompressing the official archives or by rebuilding the FreeBSD kernel and userland (refer to “Updating FreeBSD from Source” for more detailed instructions, but do not forget to add DESTDIR=${NFSROOTDIR} when running the make installkernel and make installworld commands.

Decompressing and extracting the base.txz well infact end up with a fully populated ./rescue tree in ${NFSROOTDIR} and rc.diskless works as intended.


NOW, if this is the ONLY change we need to make to use the .ISO image as a PXE ${NFSROOTDIR} and have it work and boot up to the installer I would suggest a little bit more flexable change using a
    if [ -x /rescue/tar ]; then 
        (cd /; /rescue/tar -xpf $j)
    else
        if [ -x /usr/bin/tar ]; then
            (cd /; /usr/bin/tar -xpf $j)
        else
            echo "Cant seem to find /rescue/tar or /usr/bin/tar, bailing out"
        exit 1
    fi
Comment 11 Rodney W. Grimes freebsd_committer freebsd_triage 2023-12-08 15:55:52 UTC
Cheng, you didnt answer my direct question: Are you trying to directly use an .ISO image as a diskless boot image?

Now further, does adding my suggested fix make that possible, if it does then this change would be a big win in my book, as being able to directly diskless boot off the ISO would be a very nice to have feature.
Comment 12 Cheng Cui freebsd_committer freebsd_triage 2023-12-09 15:15:10 UTC
(In reply to Rodney W. Grimes from comment #11)

I feel the need to clarify the use-case here is different and not exactly the same as in the "network-diskless" in the handbook. The ISO is not used as a diskless boot image, but literally an installation image.

use-cases:
[1] pxeboot the target and load the whole system via NFS everytime <= handbook
[2] pxeboot the target and bsdinstall to target disk via NFS once only, then use the system from target disk from now on  <= this use-case

I am not an expert for bsdinstall, so I am trying to illustrate as best as I can.

"installation of FreeBSD13.2 via UEFI PXE on a mini PC" in this PR description is literally bsdinstall via NFS with pxeboot, which unfortunately executes the "rc.initdiskless" during the pxeboot. If possible, the use-case here does not need "rc.initdiskless" but just boot necessary kernel at first and then execute bsdinstall and finish the installation of what's in the ISO. Just like use a USB or DVD media, the ISO is mounted via NFS. 

With the proposed (not perfect) fix, the use-case is fulfilled. And this same use-case had successfully been done before during 2009~2012 (when I worked on FreeBSD7,8) with the same pxeboot setup. So this is not a new use-case.

I feel this is still a good use-case. If this use-case is no longer supported, please let me know and I can drop this PR. But I will feel I can still keep it as my private use-case.
Comment 13 Warner Losh freebsd_committer freebsd_triage 2023-12-11 17:40:16 UTC
I wonder why we can't just put /rescue first in the path and use a bare tar here?
Comment 14 Rodney W. Grimes freebsd_committer freebsd_triage 2023-12-12 16:53:44 UTC
I am fine with doing the add of /rescue to the path, but it should be last, not first, which is infact what you recomended in D42765
Comment 15 Cheng Cui freebsd_committer freebsd_triage 2023-12-12 17:34:00 UTC
(In reply to Rodney W. Grimes from comment #14)

Let me test with the added path and the simplified code again.
Comment 16 commit-hook freebsd_committer freebsd_triage 2023-12-15 13:47:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=93b7818226cf5270646725805b4a8c17a1ad3761

commit 93b7818226cf5270646725805b4a8c17a1ad3761
Author:     Cheng Cui <cc@FreeBSD.org>
AuthorDate: 2023-11-24 15:47:18 +0000
Commit:     Cheng Cui <cc@FreeBSD.org>
CommitDate: 2023-12-15 08:46:44 +0000

    libexec/rc/rc.initdiskless: make tar's path flexible

    Summary:
    PR:             274977
    Reviewed by: rgrimes,imp
    Approved by: rgrimes
    MFC after:      1 month

 libexec/rc/rc.initdiskless | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 17 commit-hook freebsd_committer freebsd_triage 2024-01-19 15:46:48 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=404b91dac415c5c9126fb4201145049c4d3dfbba

commit 404b91dac415c5c9126fb4201145049c4d3dfbba
Author:     Cheng Cui <cc@FreeBSD.org>
AuthorDate: 2023-11-24 15:47:18 +0000
Commit:     Cheng Cui <cc@FreeBSD.org>
CommitDate: 2024-01-19 10:45:28 +0000

    libexec/rc/rc.initdiskless: make tar's path flexible

    PR:             274977

    (cherry picked from commit 93b7818226cf5270646725805b4a8c17a1ad3761
     and from commit a04ca1c229195c7089b878a94fbe76505ea693b5)

 libexec/rc/rc.initdiskless | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)