misc/135588: [nanobsd] simple patch for adding amd64 support

Olivier Cochard-Labbé olivier at cochard.me
Mon Jun 15 06:00:10 UTC 2009


>Number:         135588
>Category:       misc
>Synopsis:       [nanobsd] simple patch for adding amd64 support
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 15 06:00:10 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Olivier Cochard-Labbé
>Release:        amd64-current
>Organization:
>Environment:
FreeBSD d630.freenas.org 8.0-CURRENT FreeBSD 8.0-CURRENT #33: Sat Jun 13 09:36:53 CEST 2009     root at d630.freenas.org:/usr/obj/usr/src/sys/DellD630  amd64
>Description:
I would to generate a amd64 nanobsd image from my FreeBSD-amd64-current (using the NANO_ARCH=amd64 on my nano configuration file).
But nanobsd complains that function create_amd64_diskimage() is missing.
Then I've just copy the function create_i386_dikimage() to a new create_amd64_diskimage() and it's working...


>How-To-Repeat:
By generating a nanobsd amd64 image.
>Fix:
Using the patch file included in this PR (tested from a freebsd-amd64 only).

Patch attached with submission follows:

--- nanobsd.orig	2009-06-14 09:43:36.000000000 +0200
+++ nanobsd.sh	2009-06-14 10:19:25.000000000 +0200
@@ -490,6 +490,153 @@
 	) > ${MAKEOBJDIRPREFIX}/_.di 2>&1
 )
 
+# Patch added for supporting amd64 arch
+# A simple copy/past of create_i386_diskimage
+
+create_amd64_diskimage ( ) (
+	pprint 2 "build diskimage"
+	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.di"
+
+	(
+	echo $NANO_MEDIASIZE $NANO_IMAGES \
+		$NANO_SECTS $NANO_HEADS \
+		$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
+	awk '
+	{
+		printf "# %s\n", $0
+
+		# size of cylinder in sectors
+		cs = $3 * $4
+
+		# number of full cylinders on media
+		cyl = int ($1 / cs)
+
+		# output fdisk geometry spec, truncate cyls to 1023
+		if (cyl <= 1023)
+			print "g c" cyl " h" $4 " s" $3
+		else
+			print "g c" 1023 " h" $4 " s" $3
+
+		if ($7 > 0) { 
+			# size of data partition in full cylinders
+			dsl = int (($7 + cs - 1) / cs)
+		} else {
+			dsl = 0;
+		}
+
+		# size of config partition in full cylinders
+		csl = int (($6 + cs - 1) / cs)
+
+		if ($5 == 0) {
+			# size of image partition(s) in full cylinders
+			isl = int ((cyl - dsl - csl) / $2)
+		} else {
+			isl = int (($5 + cs - 1) / cs)
+		}
+
+		# First image partition start at second track
+		print "p 1 165 " $3, isl * cs - $3
+		c = isl * cs;
+
+		# Second image partition (if any) also starts offset one 
+		# track to keep them identical.
+		if ($2 > 1) {
+			print "p 2 165 " $3 + c, isl * cs - $3
+			c += isl * cs;
+		}
+
+		# Config partition starts at cylinder boundary.
+		print "p 3 165 " c, csl * cs
+		c += csl * cs
+
+		# Data partition (if any) starts at cylinder boundary.
+		if ($7 > 0) {
+			print "p 4 165 " c, dsl * cs
+		} else if ($7 < 0 && $1 > c) {
+			print "p 4 165 " c, $1 - c
+		} else if ($1 < c) {
+			print "Disk space overcommitted by", \
+			    c - $1, "sectors" > "/dev/stderr"
+			exit 2
+		}
+
+		# Force slice 1 to be marked active. This is necessary
+		# for booting the image from a USB device to work.
+		print "a 1"
+	}
+	' > ${MAKEOBJDIRPREFIX}/_.fdisk
+
+	IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
+	MNT=${MAKEOBJDIRPREFIX}/_.mnt
+	mkdir -p ${MNT}
+
+	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
+		MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
+			-y ${NANO_HEADS}`
+	else
+		echo "Creating md backing file..."
+		dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \
+			count=`expr ${NANO_MEDIASIZE} / ${NANO_SECTS}`
+		MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
+			-y ${NANO_HEADS}`
+	fi
+
+	trap "df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
+
+	fdisk -i -f ${MAKEOBJDIRPREFIX}/_.fdisk ${MD}
+	fdisk ${MD}
+	# XXX: params
+	# XXX: pick up cached boot* files, they may not be in image anymore.
+	boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
+	bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1
+	bsdlabel ${MD}s1
+
+	# Create first image
+	newfs ${NANO_NEWFS} /dev/${MD}s1a
+	mount /dev/${MD}s1a ${MNT}
+	df -i ${MNT}
+	echo "Copying worlddir..."
+	( cd ${NANO_WORLDDIR} && find . -print | cpio -dump ${MNT} )
+	df -i ${MNT}
+	echo "Generating mtree..."
+	( cd ${MNT} && mtree -c ) > ${MAKEOBJDIRPREFIX}/_.mtree
+	( cd ${MNT} && du -k ) > ${MAKEOBJDIRPREFIX}/_.du
+	umount ${MNT}
+
+	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
+		# Duplicate to second image (if present)
+		echo "Duplicating to second image..."
+		dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
+		mount /dev/${MD}s2a ${MNT}
+		for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
+		do
+			sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/g" $f
+		done
+		umount ${MNT}
+
+	fi
+	
+	# Create Config slice
+	newfs ${NANO_NEWFS} /dev/${MD}s3
+	# XXX: fill from where ?
+
+	# Create Data slice, if any.
+	if [ $NANO_DATASIZE -gt 0 ] ; then
+		newfs ${NANO_NEWFS} /dev/${MD}s4
+		# XXX: fill from where ?
+	fi
+
+	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
+		echo "Writing out _.disk.full..."
+		dd if=/dev/${MD} of=${IMG} bs=64k
+	fi
+
+	echo "Writing out _.disk.image..."
+	dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
+	mdconfig -d -u $MD
+	) > ${MAKEOBJDIRPREFIX}/_.di 2>&1
+)
+
 last_orders () (
 	# Redefine this function with any last orders you may have
 	# after the build completed, for instance to copy the finished


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list