View | Details | Raw Unified | Return to bug 186030 | Differences between
and this patch

Collapse All | Expand All

(-)defaults.sh (-46 / +92 lines)
Lines 164-169 Link Here
164
NANO_SLICE_ALTROOT=s2
164
NANO_SLICE_ALTROOT=s2
165
NANO_SLICE_CFG=s3
165
NANO_SLICE_CFG=s3
166
NANO_SLICE_DATA=s4
166
NANO_SLICE_DATA=s4
167
NANO_PARTITION_ROOT=a
168
NANO_PARTITION_ALTROOT=a
167
NANO_ROOT=s1a
169
NANO_ROOT=s1a
168
NANO_ALTROOT=s2a
170
NANO_ALTROOT=s2a
169
171
Lines 652-669 Link Here
652
	populate_slice "$1" "$2" "$3" "$4"
654
	populate_slice "$1" "$2" "$3" "$4"
653
)
655
)
654
656
655
create_diskimage ( ) (
657
calculate_partitioning ( ) (
656
	pprint 2 "build diskimage"
657
	pprint 3 "log: ${NANO_LOG}/_.di"
658
659
	(
660
	echo $NANO_MEDIASIZE $NANO_IMAGES \
658
	echo $NANO_MEDIASIZE $NANO_IMAGES \
661
		$NANO_SECTS $NANO_HEADS \
659
		$NANO_SECTS $NANO_HEADS \
662
		$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
660
		$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
663
	awk '
661
	awk '
664
	{
662
	{
665
		printf "# %s\n", $0
666
667
		# size of cylinder in sectors
663
		# size of cylinder in sectors
668
		cs = $3 * $4
664
		cs = $3 * $4
669
665
Lines 670-681 Link Here
670
		# number of full cylinders on media
666
		# number of full cylinders on media
671
		cyl = int ($1 / cs)
667
		cyl = int ($1 / cs)
672
668
673
		# output fdisk geometry spec, truncate cyls to 1023
674
		if (cyl <= 1023)
675
			print "g c" cyl " h" $4 " s" $3
676
		else
677
			print "g c" 1023 " h" $4 " s" $3
678
679
		if ($7 > 0) {
669
		if ($7 > 0) {
680
			# size of data partition in full cylinders
670
			# size of data partition in full cylinders
681
			dsl = int (($7 + cs - 1) / cs)
671
			dsl = int (($7 + cs - 1) / cs)
Lines 686-693 Link Here
686
		# size of config partition in full cylinders
676
		# size of config partition in full cylinders
687
		csl = int (($6 + cs - 1) / cs)
677
		csl = int (($6 + cs - 1) / cs)
688
678
679
		# size of image partition(s) in full cylinders
689
		if ($5 == 0) {
680
		if ($5 == 0) {
690
			# size of image partition(s) in full cylinders
691
			isl = int ((cyl - dsl - csl) / $2)
681
			isl = int ((cyl - dsl - csl) / $2)
692
		} else {
682
		} else {
693
			isl = int (($5 + cs - 1) / cs)
683
			isl = int (($5 + cs - 1) / cs)
Lines 694-730 Link Here
694
		}
684
		}
695
685
696
		# First image partition start at second track
686
		# First image partition start at second track
697
		print "p 1 165 " $3, isl * cs - $3
687
		print $3, isl * cs - $3
698
		c = isl * cs;
688
		c = isl * cs;
699
689
700
		# Second image partition (if any) also starts offset one
690
		# Second image partition (if any) also starts offset one
701
		# track to keep them identical.
691
		# track to keep them identical.
702
		if ($2 > 1) {
692
		if ($2 > 1) {
703
			print "p 2 165 " $3 + c, isl * cs - $3
693
			print $3 + c, isl * cs - $3
704
			c += isl * cs;
694
			c += isl * cs;
705
		}
695
		}
706
696
707
		# Config partition starts at cylinder boundary.
697
		# Config partition starts at cylinder boundary.
708
		print "p 3 165 " c, csl * cs
698
		print c, csl * cs
709
		c += csl * cs
699
		c += csl * cs
710
700
711
		# Data partition (if any) starts at cylinder boundary.
701
		# Data partition (if any) starts at cylinder boundary.
712
		if ($7 > 0) {
702
		if ($7 > 0) {
713
			print "p 4 165 " c, dsl * cs
703
			print c, dsl * cs
714
		} else if ($7 < 0 && $1 > c) {
704
		} else if ($7 < 0 && $1 > c) {
715
			print "p 4 165 " c, $1 - c
705
			print c, $1 - c
716
		} else if ($1 < c) {
706
		} else if ($1 < c) {
717
			print "Disk space overcommitted by", \
707
			print "Disk space overcommitted by", \
718
			    c - $1, "sectors" > "/dev/stderr"
708
			    c - $1, "sectors" > "/dev/stderr"
719
			exit 2
709
			exit 2
720
		}
710
		}
721
722
		# Force slice 1 to be marked active. This is necessary
723
		# for booting the image from a USB device to work.
724
		print "a 1"
725
	}
711
	}
726
	' > ${NANO_LOG}/_.fdisk
712
	' > ${NANO_LOG}/_.partitioning
727
713
714
)
715
716
create_code_slice ( ) (
717
	pprint 2 "build code slice"
718
	pprint 3 "log: ${NANO_OBJ}/_.cs"
719
720
	(
721
	IMG=${NANO_DISKIMGDIR}/_.disk.image
722
	MNT=${NANO_OBJ}/_.mnt
723
	mkdir -p ${MNT}
724
	CODE_SIZE=`head -n 1 ${NANO_OBJ}/_.partitioning | awk '{ print $2 }'`
725
726
	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
727
		MD=`mdconfig -a -t swap -s ${CODE_SIZE} -x ${NANO_SECTS} \
728
			-y ${NANO_HEADS}`
729
	else
730
		echo "Creating md backing file..."
731
		rm -f ${IMG}
732
		dd if=/dev/zero of=${IMG} seek=${CODE_SIZE} count=0
733
		MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
734
			-y ${NANO_HEADS}`
735
	fi
736
737
	trap "echo 'Running exit trap code' ; df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
738
739
	bsdlabel -w ${MD}
740
	if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
741
	    echo "Making bootable partition"
742
	    gpart bootcode -b ${NANO_WORLDDIR}/boot/boot ${MD}
743
	else
744
	    echo "Partition will not be bootable"
745
	fi
746
	bsdlabel ${MD}
747
748
	# Create first image
749
	populate_slice /dev/${MD}${NANO_PARTITION_ROOT} ${NANO_WORLDDIR} ${MNT} "${NANO_ROOT}"
750
	mount /dev/${MD}a ${MNT}
751
	echo "Generating mtree..."
752
	( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree
753
	( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du
754
	nano_umount ${MNT}
755
756
	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
757
		echo "Writing out _.disk.image..."
758
		dd conv=sparse if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
759
	fi
760
	mdconfig -d -u $MD
761
762
	trap - 1 2 15 EXIT
763
764
	) > ${NANO_OBJ}/_.cs 2>&1
765
)
766
767
768
create_diskimage ( ) (
769
	pprint 2 "build diskimage"
770
	pprint 3 "log: ${NANO_OBJ}/_.di"
771
772
	(
773
728
	IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
774
	IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
729
	MNT=${NANO_OBJ}/_.mnt
775
	MNT=${NANO_OBJ}/_.mnt
730
	mkdir -p ${MNT}
776
	mkdir -p ${MNT}
Lines 740-768 Link Here
740
			-y ${NANO_HEADS}`
786
			-y ${NANO_HEADS}`
741
	fi
787
	fi
742
788
789
	awk '
790
	BEGIN {
791
		# Create MBR partition table
792
		print "gpart create -s mbr $1"
793
	}
794
	{
795
		# Make partition
796
		print "gpart add -t freebsd -b ", $1, " -s ", $2, " $1"
797
	}
798
	END {
799
		# Force slice 1 to be marked active. This is necessary
800
		# for booting the image from a USB device to work.
801
		print "gpart set -a active -i 1 $1"
802
	}
803
	' ${NANO_OBJ}/_.partitioning > ${NANO_OBJ}/_.gpart
804
743
	trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
805
	trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
744
806
745
	fdisk -i -f ${NANO_LOG}/_.fdisk ${MD}
807
	sh ${NANO_OBJ}/_.gpart ${MD}
746
	fdisk ${MD}
808
	gpart show ${MD}
747
	# XXX: params
809
	# XXX: params
748
	# XXX: pick up cached boot* files, they may not be in image anymore.
810
	# XXX: pick up cached boot* files, they may not be in image anymore.
749
	if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
811
	if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
750
		boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
812
		gpart bootcode -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOTFLAGS} ${MD}
751
	fi
813
	fi
752
	if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
753
		bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}${NANO_SLICE_ROOT}
754
	else
755
		bsdlabel -w ${MD}${NANO_SLICE_ROOT}
756
	fi
757
	bsdlabel ${MD}${NANO_SLICE_ROOT}
758
814
759
	# Create first image
815
	echo "Writing code image..."
760
	populate_slice /dev/${MD}${NANO_ROOT} ${NANO_WORLDDIR} ${MNT} "${NANO_ROOT}"
816
	dd conv=sparse if=${NANO_DISKIMGDIR}/_.disk.image of=/dev/${MD}${NANO_SLICE_ROOT} bs=64k
761
	mount /dev/${MD}${NANO_ROOT} ${MNT}
762
	echo "Generating mtree..."
763
	( cd "${MNT}" && mtree -c ) > ${NANO_LOG}/_.mtree
764
	( cd "${MNT}" && du -k ) > ${NANO_LOG}/_.du
765
	nano_umount "${MNT}"
766
817
767
	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
818
	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
768
		# Duplicate to second image (if present)
819
		# Duplicate to second image (if present)
Lines 806-816 Link Here
806
		echo "Writing out ${NANO_IMGNAME}..."
857
		echo "Writing out ${NANO_IMGNAME}..."
807
		dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
858
		dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
808
	fi
859
	fi
809
810
	if ${do_copyout_partition} ; then
811
		echo "Writing out _.disk.image..."
812
		dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
813
	fi
814
	mdconfig -d -u $MD
860
	mdconfig -d -u $MD
815
861
816
	trap - 1 2 15
862
	trap - 1 2 15
Lines 1021-1027 Link Here
1021
	echo "Usage: $0 [-bfhiKknqvwX] [-c config_file]"
1067
	echo "Usage: $0 [-bfhiKknqvwX] [-c config_file]"
1022
	echo "	-b	suppress builds (both kernel and world)"
1068
	echo "	-b	suppress builds (both kernel and world)"
1023
	echo "	-c	specify config file"
1069
	echo "	-c	specify config file"
1024
	echo "	-f	suppress code slice extraction"
1070
	echo "	-f	suppress code slice extraction (implies -i)"
1025
	echo "	-h	print this help summary page"
1071
	echo "	-h	print this help summary page"
1026
	echo "	-i	suppress disk image build"
1072
	echo "	-i	suppress disk image build"
1027
	echo "	-K	suppress installkernel"
1073
	echo "	-K	suppress installkernel"
(-)nanobsd.sh (-5 / +12 lines)
Lines 40-47 Link Here
40
do_kernel=true
40
do_kernel=true
41
do_installkernel=true
41
do_installkernel=true
42
do_world=true
42
do_world=true
43
do_code=true
43
do_image=true
44
do_image=true
44
do_copyout_partition=true
45
do_native_xtools=false
45
do_native_xtools=false
46
46
47
set +e
47
set +e
Lines 80-86 Link Here
80
		shift
80
		shift
81
		;;
81
		;;
82
	-f)
82
	-f)
83
		do_copyout_partition=false
83
		do_code=false
84
		do_image=false
84
		shift
85
		shift
85
		;;
86
		;;
86
	-h)
87
	-h)
Lines 181-190 Link Here
181
prune_usr
182
prune_usr
182
run_late_customize
183
run_late_customize
183
fixup_before_diskimage
184
fixup_before_diskimage
184
if $do_image ; then
185
if $do_code ; then
185
	create_diskimage
186
	calculate_partitioning
187
	create_code_slice
188
	if $do_image ; then
189
		create_diskimage
190
	else
191
		pprint 2 "Skipping image build (as instructed)"
192
	fi
186
else
193
else
187
	pprint 2 "Skipping image build (as instructed)"
194
	pprint 2 "Skipping code and image build (as instructed)"
188
fi
195
fi
189
last_orders
196
last_orders
190
197

Return to bug 186030