NetBSD Problem Report #55382

From tsutsui@ceres.dti.ne.jp  Fri Jun 12 18:59:57 2020
Return-Path: <tsutsui@ceres.dti.ne.jp>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D486F1A9219
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 12 Jun 2020 18:59:57 +0000 (UTC)
Message-Id: <202006121859.05CIxqgO005187@ceres.dti.ne.jp>
Date: Sat, 13 Jun 2020 03:59:52 +0900 (JST)
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Reply-To: tsutsui@ceres.dti.ne.jp
To: gnats-bugs@NetBSD.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: sysinst doesn't create boot ext2fs in MBR Ext2 partition
X-Send-Pr-Version: 3.95

>Number:         55382
>Category:       install
>Synopsis:       sysinst doesn't create boot ext2fs in MBR Ext2 partition
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    install-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 12 19:00:00 +0000 2020
>Closed-Date:    Tue Sep 29 15:29:58 +0000 2020
>Last-Modified:  Sat Dec 31 05:20:01 +0000 2022
>Originator:     Izumi Tsutsui
>Release:        NetBSD 9.0
>Organization:
>Environment:
System: NetBSD 9.0 (RAMDISK) #0: Fri Feb 14 00:06:28 UTC 2020
mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/cobalt/compile/RAMDISK
Architecture: maybe all
Machine: currently only cobalt is affected
>Description:
NetBSD/cobalt requries to have an Ext2fs partition for its bootstrap
and sysinst in NetBSD 8.0 and prior handles it.

On NetBSD 9.0 sysinst still create an Ext2fs boot partition
on cobalt, but the partition is not allocated in the MBR partition
for Linux but in NetBSD partition. 


>How-To-Repeat:

MBR partition is allocated as the following if ""

---

Set "the sizes for the system partitions" as following:
---

 You can now change the sizes for the system partitions.  The default is to
 allocate all the space to the root file system.  However, you may wish to
 have separate /usr (additional system files), /var (log files etc) or /home
 (users' home directories) file systems.

 Free space will be added to the partition marked with a '+'.

       Size (sec)                            Filesystem
       ----------------------------------- - --------------------
    a: 10240                                 /stand
    b: 643072 (963248)                     + /
    c: 65536                                 <swap>
    d: 0                                     /tmp (mfs)
    e: 0                                     /usr
    f: 0                                     /var
       ----------------------------------- - --------------------
    h: Add a user defined partition
    i: Clone external partition(s)
    j: Change input units (sectors/cylinders/MB/GB)
   >x: Go on.  Free space 320176 sec.

---

Then the "/stand" boot partition ("/ext2" in -current)
is allocated in the "NetBSD parptition":

---

 We now have your disklabel partitions for wd0 below.  This is your last   
 chance to change them. 

 Flags: (N)ewfs.  Total size: 507M, free: 1536B

     Start (sec)    End (sec)   Size (sec)  FS type Flag Filesystem
    ------------ ------------ ------------ -------- ---- ----------------
 a:        20546       983793       963248   4.2BSD N    /
 b:       983795      1049327        65533     swap
 c:        10304      1049327      1039024 NetBSD partition
 d:            0      1049327      1049328 Whole disk
 e:        10305        20544        10240 Linux Ex N    /stand
    ------------ ------------ ------------ -------- ---- ----------------
 g: Change input units (sectors/cylinders/MB/GB)
 h: Edit name of the disk
 i: Clone external partition(s)
 j: Cancel
>x: Partition sizes ok

---

The boot Linux Ext2 should be allocated at region from 63 to 10304.

>Fix:

I don't understand design and implementation of new sysinst at all,
but the following changes make sysinst allocate Ext2fs partition
in the Linux partition in MBR:

---

Index: bsddisklabel.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sysinst/bsddisklabel.c,v
retrieving revision 1.23.2.10
diff -u -p -d -r1.23.2.10 bsddisklabel.c
--- bsddisklabel.c	10 Feb 2020 21:39:37 -0000	1.23.2.10
+++ bsddisklabel.c	12 Jun 2020 18:47:00 -0000
@@ -76,7 +76,7 @@ default_parts_init[] =
 #endif
 #ifdef PART_BOOT_TYPE
 	  .fs_type = PART_BOOT_TYPE,
-#if PART_BOOT_TYPE == FS_MSDOS
+#if (PART_BOOT_TYPE == FS_MSDOS) || (PART_BOOT_TYPE == FS_EX2FS)
 	  .flags = PUIFLAG_ADD_OUTER,
 #endif
 #endif
@@ -100,7 +100,7 @@ default_parts_init[] =
 #endif
 #ifdef PART_BOOT1_TYPE
 	  .fs_type = PART_BOOT1_TYPE,
-#if PART_BOOT1_TYPE == FS_MSDOS
+#if (PART_BOOT1_TYPE == FS_MSDOS) || (PART_BOOT1_TYPE == FS_EX2FS)
 	  .flags = PUIFLAG_ADD_OUTER,
 #endif
 #endif
@@ -119,7 +119,7 @@ default_parts_init[] =
 #endif
 #ifdef PART_BOOT2_TYPE
 	  .fs_type = PART_BOOT2_TYPE,
-#if PART_BOOT2_TYPE == FS_MSDOS
+#if (PART_BOOT2_TYPE == FS_MSDOS) || (PART_BOOT2_TYPE == FS_EX2FS)
 	  .flags = PUIFLAG_ADD_OUTER,
 #endif
 #endif
@@ -961,7 +967,8 @@ fill_defaults(struct partition_usage_set
 				wanted->infos[i].type = pt->generic_ptype;
 		}
 		if (wanted->parts->parent != NULL &&
-		    wanted->infos[i].fs_type == FS_MSDOS)
+		    (wanted->infos[i].fs_type == FS_MSDOS ||
+		     wanted->infos[i].fs_type == FS_EX2FS))
 			wanted->infos[i].flags |=
 			    PUIFLG_ADD_INNER|PUIFLAG_ADD_OUTER;

@@ -1008,8 +1015,8 @@ fill_defaults(struct partition_usage_set
 	 * empty disk. Merge the partitions in target range that are already
 	 * there (match with wanted) or are there additionaly.
 	 * The only thing outside of target range that we care for
-	 * are FAT partitions and a potential swap partition - we assume one
-	 * is enough.
+	 * are FAT partitions, EXT2FS partitions, and a potential
+	 * swap partition - we assume one is enough.
 	 */
 	size_t num = wanted->num;
 	if (parts->parent) {
@@ -1020,7 +1027,8 @@ fill_defaults(struct partition_usage_set
 			    parts->parent, pno, &info))
 				continue;
 			if (info.nat_type->generic_ptype != PT_swap &&
-			    info.fs_type != FS_MSDOS)
+			    info.fs_type != FS_MSDOS &&
+			    info.fs_type != FS_EX2FS)
 				continue;
 			merge_part_with_wanted(parts->parent, pno, &info,
 			    wanted, num, true);
Index: disklabel.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sysinst/disklabel.c,v
retrieving revision 1.10.2.9
diff -u -p -d -r1.10.2.9 disklabel.c
--- disklabel.c	10 Feb 2020 21:39:37 -0000	1.10.2.9
+++ disklabel.c	12 Jun 2020 18:47:01 -0000
@@ -582,6 +582,9 @@ dl_init_types(void)
 				pt = PT_root; break;
 		case FS_SWAP:	pt = PT_swap; break;
 		case FS_MSDOS:	pt = PT_FAT; break;
+		case FS_EX2FS:	pt = PT_EXT2; break;
+		case FS_SYSVBFS:
+				pt = PT_SYSVBFS; break;
 		default:	pt = PT_unknown; break;
 		}
 		dl_types[i].generic_ptype = pt;
@@ -707,6 +710,9 @@ disklabel_get_generic_type(enum part_typ
 	case PT_FAT:
 	case PT_EFI_SYSTEM:
 			nt = FS_MSDOS; break;
+	case PT_EXT2:	nt = FS_EX2FS; break;
+	case PT_SYSVBFS:
+			nt = FS_SYSVBFS; break;
 	default:	nt = FS_UNUSED; break;
 	}

Index: mbr.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sysinst/mbr.c,v
retrieving revision 1.19.2.6
diff -u -p -d -r1.19.2.6 mbr.c
--- mbr.c	10 Feb 2020 21:39:37 -0000	1.19.2.6
+++ mbr.c	12 Jun 2020 18:47:02 -0000
@@ -1117,6 +1117,8 @@ mbr_map_part_type(unsigned int t)
 		return PT_FAT;
 	case MBR_PTYPE_EFI:
 		return PT_EFI_SYSTEM;
+	case MBR_PTYPE_LNXEXT2:
+		return PT_EXT2;
 	case MBR_PTYPE_NETBSD:
 		return PT_root;
 	}
@@ -1279,6 +1281,8 @@ mbr_get_generic_part_type(enum part_type
 		return mbr_get_gen_type_desc(MBR_PTYPE_NETBSD);
 	case PT_FAT:
 		return mbr_get_gen_type_desc(MBR_PTYPE_FAT32L);
+	case PT_EXT2:
+		return mbr_get_gen_type_desc(MBR_PTYPE_LNXEXT2);
 	case PT_EFI_SYSTEM:
 		return mbr_get_gen_type_desc(MBR_PTYPE_EFI);
 	default:
@@ -1386,6 +1390,9 @@ mbr_do_get_part_info(const struct disk_p
 		case MBR_PTYPE_EFI:
 			info->fs_type = FS_MSDOS;
 			break;
+		case MBR_PTYPE_LNXEXT2:
+			info->fs_type = FS_EX2FS;
+			break;
 		case MBR_PTYPE_XENIX_ROOT:
 		case MBR_PTYPE_XENIX_USR:
 			info->fs_type = FS_SYSV;
Index: partitions.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/sysinst/partitions.h,v
retrieving revision 1.4.2.6
diff -u -p -d -r1.4.2.6 partitions.h
--- partitions.h	28 Jan 2020 10:17:58 -0000	1.4.2.6
+++ partitions.h	12 Jun 2020 18:47:02 -0000
@@ -91,6 +91,8 @@ enum part_type {
 	PT_root,		/* the NetBSD / partition (bootable) */
 	PT_swap,		/* the NetBSD swap partition */
 	PT_FAT,			/* boot partition (e.g. for u-boot) */
+	PT_EXT2,		/* boot partition (for Linux appliances) */
+	PT_SYSVBFS,		/* boot partition (for some SYSV machines) */
 	PT_EFI_SYSTEM,		/* (U)EFI boot partition */
 };

Index: arch/cobalt/md.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sysinst/arch/cobalt/md.c,v
retrieving revision 1.8.2.3
diff -u -p -d -r1.8.2.3 md.c
--- arch/cobalt/md.c	28 Jan 2020 10:17:57 -0000	1.8.2.3
+++ arch/cobalt/md.c	12 Jun 2020 18:47:02 -0000
@@ -281,12 +281,12 @@ md_parts_use_wholedisk(struct disk_parti
 	struct disk_part_info boot_part = {
 		.size = PART_BOOT / 512,
 		.fs_type = PART_BOOT_TYPE,
-		.fs_sub_type = MBR_PTYPE_FAT12,
+		.fs_sub_type = MBR_PTYPE_LNXEXT2,
 		.last_mounted = PART_BOOT_MOUNT,
 	};

 	boot_part.nat_type = parts->pscheme->get_fs_part_type(
-	    PT_root, boot_part.fs_type, boot_part.fs_sub_type);
+	    PT_EXT2, boot_part.fs_type, boot_part.fs_sub_type);

 	return parts_use_wholedisk(parts, 1, &boot_part);
 }

---

 You can now change the sizes for the system partitions.  The default is to
 allocate all the space to the root file system.  However, you may wish to
 have separate /usr (additional system files), /var (log files etc) or /home
 (users' home directories) file systems.

 Free space will be added to the partition marked with a '+'.
 Other markers: '@' external partition.

       Size (sec)                            Filesystem
       ----------------------------------- - --------------------
   >a: 10240                               @ /ext2
    b: 774144 (973488)                     + /
    c: 65536                                 <swap>
    d: 0                                     /tmp (mfs)
    e: 0                                     /usr
    f: 0                                     /var
       ----------------------------------- - --------------------
    h: Add a user defined partition
    i: Clone external partition(s)
    j: Change input units (sectors/cylinders/MB/GB)
    x: Go on.  Free space 199344 sec.

---

 We now have your disklabel partitions for wd0 below.  This is your last   
 chance to change them. 

 Flags: (N)ewfs.  Total size: 507M, free: 5120K

     Start (sec)    End (sec)   Size (sec)  FS type Flag Filesystem
    ------------ ------------ ------------ -------- ---- ----------------
 a:        10304       973551       963248   4.2BSD N    /
 b:       973553      1039088        65536     swap
 c:        10304      1049327      1039024 NetBSD partition
 d:            0      1049327      1049328 Whole disk
 e:           63        10302        10240 Linux Ex N    /ext2
    ------------ ------------ ------------ -------- ---- ----------------
 g: Change input units (sectors/cylinders/MB/GB)
 h: Edit name of the disk
 i: Clone external partition(s)
 j: Cancel
>x: Partition sizes ok

---

I have no idea what "PUIFLAG_foo" flags mean and
what "enum part_type" (PT_foo) values mean at all
so all changes are applied blindly per implementation
for current existing "PT_FAT" ones.

---
Izumi Tsutsui

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Tue, 29 Sep 2020 15:29:58 +0000
State-Changed-Why:
Patch applied, thanks!


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55382 CVS commit: src/usr.sbin/sysinst
Date: Tue, 29 Sep 2020 15:29:17 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Sep 29 15:29:17 UTC 2020

 Modified Files:
 	src/usr.sbin/sysinst: bsddisklabel.c disklabel.c mbr.c partitions.h

 Log Message:
 Apply patch provided by Izumi Tsutsui in PR 55382: make ext2 partitions
 show up in the outer (MBR) partition table, needed for example on Cobalt
 where firmware boots from that partition.


 To generate a diff of this commit:
 cvs rdiff -u -r1.44 -r1.45 src/usr.sbin/sysinst/bsddisklabel.c
 cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/sysinst/disklabel.c
 cvs rdiff -u -r1.32 -r1.33 src/usr.sbin/sysinst/mbr.c
 cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/sysinst/partitions.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: gnats-bugs@netbsd.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: Re: install/55382 (sysinst doesn't create boot ext2fs in MBR Ext2 partition)
Date: Sat, 31 Dec 2022 14:18:11 +0900

 Note this has been pulled up to netbsd-9 via ticket 1113.
  https://mail-index.netbsd.org/source-changes/2020/10/15/msg122964.html

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.