Bug 262098 - [nanobsd] builds with s2 for /cfg, and can't boot?
Summary: [nanobsd] builds with s2 for /cfg, and can't boot?
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.3-RELEASE
Hardware: amd64 Any
: --- Affects Some People
Assignee: Jose Luis Duran
URL: https://reviews.freebsd.org/D47835
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-21 16:34 UTC by peter.larsen
Modified: 2025-02-12 01:46 UTC (History)
3 users (show)

See Also:
jlduran: mfc-stable14?
jlduran: mfc-stable13?


Attachments
nanobsd: Always account for 2 code partitions (407 bytes, patch)
2024-11-22 06:38 UTC, Jose Luis Duran
no flags Details | Diff
nanobsd: Always define the partition index (1.98 KB, patch)
2024-11-28 22:30 UTC, Jose Luis Duran
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description peter.larsen 2022-02-21 16:34:26 UTC
There seems to have been many changes from 12.2 to 12.3 in /usr/src/tools/tools/nanobsd


for some reason I end up with a disk image with root on s1, /cfg on s2 and nothing on s3 


this have not been a problem on 12.2, but I assume its a problem due to I have 

"NANO_IMAGES=1" in my .conf file

expected behaviour:

s1 for root, s2 preserved as a blank, and s3 used for /cfg

actually getting:

s1 for root, s2 used for /cfg, s3 blank


result:
Image can't boot... it expect /cfg on s3
Comment 1 ovi 2022-10-03 12:17:17 UTC
I have the same issue on FreeBSD 12.3, 13.0 and 13.1, on i386 architecture.

I've also tried the complete example from this page (using NANO_IMAGES=1):

https://docs.freebsd.org/en/articles/nanobsd/

More info from nanobsd log:

newfs -b 4096 -f 512 -i 8192 -U -Lnanobsds3 /dev/md0s3
newfs: /dev/md0s3: could not find special device
Running exit trap code
Comment 2 Jose Luis Duran freebsd_committer freebsd_triage 2024-11-22 06:38:46 UTC
Created attachment 255380 [details]
nanobsd: Always account for 2 code partitions

I was able to replicate this bug.

The attached patch (not the final patch, just the shortest fix) should fix the issue. What throws me off is that I was not able to find a difference between 12.2 and 12.3. So there might be something else.

The patch always reserves the partition for code#2, it is not populated if NANO_IMAGES=1 or NANO_INIT_IMG2=0.

Thanks for reporting it, if it is still within your possibilities I would appreciate it if you could test it.
Comment 3 Jose Luis Duran freebsd_committer freebsd_triage 2024-11-28 22:30:00 UTC
Created attachment 255516 [details]
nanobsd: Always define the partition index

Print the partition index together with the starting sector and the size in sectors.  Otherwise, when only one code partition is desired, the configuration partition (/cfg) may not end in the third slice, and breaking the scripts that expect it there.

Prefer this approach rather than adjusting the scripts dynamically to avoid a breaking change.
Comment 4 OlivierW 2025-01-18 23:19:36 UTC
Hello,

Thanks for your patch, it does work on FreeBSD 14.2-RELEASE!
I hope it'll be merged soon.
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-02-04 14:08:22 UTC
A commit in branch main references this bug:

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

commit dc4b36b96333f2ab05f3c454f0df2e0a0d4d451d
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-02-04 14:07:00 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-02-04 14:07:00 +0000

    nanobsd: Always define the partition index

    Print the desired partition index together with the starting LBA and the
    size. Otherwise, when only one code partition is desired, the
    configuration partition (/cfg) may not end up in the third slice, thus
    breaking the scripts that expect it there.

    This was the previous approach, changed in 587c054bea0f ("nanobsd: Use
    gpart and create code image before full disk image").

    Fix it by printing the index as the last column to reduce the chances of
    breaking current overrides, and using it as the gpart index.

    PR:             262098
    Reviewed by:    imp
    Approved by:    emaste (mentor)
    Fixes:  587c054bea0f ("nanobsd: Use gpart and create code image before full disk image")
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D47835

 tools/tools/nanobsd/legacy.sh | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-02-12 01:44:31 UTC
A commit in branch stable/14 references this bug:

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

commit e58d9b71f37dde1cd19bb0af3a4bf94938f4406d
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-02-04 14:07:00 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-02-12 01:32:12 +0000

    nanobsd: Always define the partition index

    Print the desired partition index together with the starting LBA and the
    size. Otherwise, when only one code partition is desired, the
    configuration partition (/cfg) may not end up in the third slice, thus
    breaking the scripts that expect it there.

    This was the previous approach, changed in 587c054bea0f ("nanobsd: Use
    gpart and create code image before full disk image").

    Fix it by printing the index as the last column to reduce the chances of
    breaking current overrides, and using it as the gpart index.

    PR:             262098
    Reviewed by:    imp
    Approved by:    emaste (mentor)
    Fixes:  587c054bea0f ("nanobsd: Use gpart and create code image before full disk image")
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D47835

    (cherry picked from commit dc4b36b96333f2ab05f3c454f0df2e0a0d4d451d)

 tools/tools/nanobsd/legacy.sh | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-02-12 01:45:33 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6fc8d02b59dd7c343a2ab681e57c13c27c6425f7

commit 6fc8d02b59dd7c343a2ab681e57c13c27c6425f7
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-02-04 14:07:00 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-02-12 01:38:47 +0000

    nanobsd: Always define the partition index

    Print the desired partition index together with the starting LBA and the
    size. Otherwise, when only one code partition is desired, the
    configuration partition (/cfg) may not end up in the third slice, thus
    breaking the scripts that expect it there.

    This was the previous approach, changed in 587c054bea0f ("nanobsd: Use
    gpart and create code image before full disk image").

    Fix it by printing the index as the last column to reduce the chances of
    breaking current overrides, and using it as the gpart index.

    PR:             262098
    Reviewed by:    imp
    Approved by:    emaste (mentor)
    Fixes:  587c054bea0f ("nanobsd: Use gpart and create code image before full disk image")
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D47835

    (cherry picked from commit dc4b36b96333f2ab05f3c454f0df2e0a0d4d451d)

 tools/tools/nanobsd/legacy.sh | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)