Hi.

makefs -o rdroot writes a disklabel with d_nsectors left at 0, which the
kernel's checkdisklabel() in sys/kern/subr_disk.c rejects with EINVAL:

```
        /* These fields may not be 0, no point trying a byteswap */
        if (dlp->d_secpercyl == 0 || dlp->d_nsectors == 0 ||
            dlp->d_version == 0)
                return EINVAL;  /* invalid label */
```

The resulting image fails to boot: the kernel panics with cannot open
disk, error 22 when attempting to mount the ramdisk root.

ffs_makerdroot() in usr.sbin/makefs/ffs.c sets d_ntracks, d_ncylinders,
and d_secpercyl to rdsize, but omits d_nsectors:

```
        lp->d_version = 1;
        lp->d_type = DTYPE_RDROOT;
        strlcpy(lp->d_typename, "rdroot", sizeof(lp->d_typename));
        lp->d_npartitions = RAW_PART + 1;
        lp->d_secsize = sectorsize;
        lp->d_ntracks = lp->d_ncylinders = 1;
        lp->d_secpercyl = rdsize;
        DL_SETDSIZE(lp, rdsize);
```

Since d_ntracks = 1 and d_ncylinders = 1, d_nsectors should equal rdsize
for the geometry to be consistent:

Index: ffs.c
===================================================================
RCS file: /cvs/src/usr.sbin/makefs/ffs.c,v
diff -p -U4 -r1.40 ffs.c
--- ffs.c       19 Nov 2025 18:18:09 -0000      1.40
+++ ffs.c       2 Oct 2026 00:27:47 -0000
@@ -238,8 +238,9 @@ ffs_makerdroot(const fsinfo_t *fsopts)
        strlcpy(lp->d_typename, "rdroot", sizeof(lp->d_typename));
        lp->d_npartitions = RAW_PART + 1;
        lp->d_secsize = sectorsize;
        lp->d_ntracks = lp->d_ncylinders = 1;
+       lp->d_nsectors = rdsize;
        lp->d_secpercyl = rdsize;
        DL_SETDSIZE(lp, rdsize);
 
        pp = &lp->d_partitions[0];              /* a.k.a. 'a' */

This is visible for example via:

$ mkdir example
$ makefs.bad -s 6m -o rdroot,minfree=0,bsize=4096,fsize=512,density=4096 bad.fs 
example/
$ makefs.fix -s 6m -o rdroot,minfree=0,bsize=4096,fsize=512,density=4096 fix.fs 
example/

# vnconfig bad.fs
vnd0
# vnconfig fix.fs
vnd1

# vnconfig -l
vnd0: covering bad.fs on sd0d, inode 51973
vnd1: covering fix.fs on sd0d, inode 51974
vnd2: not in use
vnd3: not in use


Here partition `a` is missing (bad case):

# disklabel vnd0
# /dev/rvnd0c:
type: vnd
disk: vnd device
label: fictitious
duid: 0000000000000000
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 122
total sectors: 12288
boundstart: 0
boundend: 12288

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  c:            12288                0  unused


Here partition `a` is present (fixed case):

# disklabel vnd1
# /dev/rvnd1c:
type: vnd
disk: rdroot
label: 
duid: 9f62a3176d372763
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 122
total sectors: 12288
boundstart: 0
boundend: 0

3 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:            12288                0  4.2BSD    512  4096  1536 
  c:            12288                0  unused

-- 
Regards,
 Mikolaj

Reply via email to