Date: Tue, 28 Jan 2014 09:48:27 +0100 From: Nick Hibma <nick@van-laarhoven.org> To: Arrigo Marchiori <ardovm@yahoo.it> Cc: Ian Smith <smithi@nimnet.asn.au>, =?windows-1252?Q?=93FreeBSD_Embedded_Mailing_List=94?= <freebsd-embedded@freebsd.org> Subject: Re: Creating code slice before disk image in nanobsd Message-ID: <69B43B44-C122-4D6E-92AB-7A5480ABFE54@van-laarhoven.org> In-Reply-To: <20140123120053.GC27181@snail.casa> References: <20120629133759.GA19373@snail.casa> <20140114161533.GB19601@snail.casa> <CAJ-VmonKFEvPRimEmA8vnAbXVCYQ16yOftYhq03VJBYB5knotA@mail.gmail.com> <6027B660-1D2E-4058-B87F-83D8225F0DC3@bsdimp.com> <20140116034220.B43023@sola.nimnet.asn.au> <alpine.BSF.2.00.1401151214480.83038@wonkity.com> <20140123120053.GC27181@snail.casa>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_BA1B0337-80AC-40C3-86CD-81FB8AE711A4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 >>>> I'll take a look at things... It isn't obvious at first blush this = is >>>> the right thing to do, but I need to think about it a bit... >>>>=20 >>>> Warner >>>=20 >>> Perhaps an aside, but I'm pretty sure Warren (cc'd) has said that = gpart >>> can do anything that fdisk AND bsdlabel can do? >>=20 >> Yes. Although there is an exception: gpart silently forces alignment = to=20 >> CHS values on MBR slices, and fdisk does not. So to get a 4K-aligned=20= >> slice requires fdisk. gpart can align BSD partitions inside a slice = to=20 >> 4K, but that is a workaround. (I believe gpart should default to CHS=20= >> but use -a alignment or -b values when given for MBR slices, = regardless=20 >> of the MBR spec. This becomes increasingly important as 4K drives = and=20 >> SSDs become more common.) >=20 > I didn't take alignment into account; I just adapted the calculations > to match the parameters required by gpart. >=20 >>> If that's so, and the >>> object here is to deprecate fdisk, why not also replace these lines: >>>=20 >>> + >>> + bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD} >>> + bsdlabel ${MD} >>> + >>>=20 >>> with their gpart equivalents? >>>=20 >>> (and no, I don't know what those should be in this context) >>=20 >> To create the initial MBR, probably already done before the code = above: >> gpart create -s mbr ${MD} >=20 > This is done by the patch. >=20 > [...] >> To create a slice and set it active: >> gpart add -s freebsd ${MD} [1] > [...] >> [1] when creating the slice, -a4k or -b1m can be specified but will = be >> silently rounded to CHS values >=20 > The -b parameter is also used, therefore your note [1] applies. >=20 >> gpart set -a active -i1 ${MD} >=20 > This is done by the patch. >=20 >> To create the BSDlabel inside the slice and write the bootcode to it: >> gpart create -s bsd ${MD}s1 >> gpart bootcode -b ${NANO_WORLDDIR}/boot/boot ${MD}s1 >> Then BSD partitions can be added with, for example: >> gpart add -t freebsd-ufs -s2g ${MD}s1 [2] > [...] >> [2] when creating BSD partitions, -a4k can be used and they will be >> created with an offset inside the slice to end up aligned >=20 > These were kept as the original: >=20 > bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1 >=20 >> For reference, see=20 >> = http://www.wonkity.com/~wblock/docs/html/disksetup.html#_the_old_standard_= mbr For reference, I=92ve replaced the disk image build with a simpler disk = image function, and a separate script to generate a full disk image = (used only for new installations. The disk image script is a = simplification of the existing one in nanobsd.sh. The second, separate script does the full initialisation of a disk = depending on what it finds. It also does automatic filling of the disk = with a /data partition (so we can use 2 150MB code partitions, cfg = partition and the rest for storage on any medium). As you can see we = still use the boot0cfg commands here. It can build an MBR style = partitioning, but also a BSD style partitioning (USB drives) (left out = for brevity). (Note: Our scripts can not only generate MBR style partitioning, but = also BSD style partitioning holding 2 code slices. For that to work you = will need to do some fancy twiddling of the partition switching after = update). Maybe this is of use for reference in this discussions. Nick echo "### Creating MBR style layout for HD/CF style image on $CFCARD" = 1>&4 # AWIMGroot1 ada0s1a # AWIMGroot2 ada0s2a # AWIMGcfg ada0s3 # AWIMGdata ada0s4 gpart create -s MBR $CFCARD # We need to increase the size of the root partitions by a small amount = to # make room for the BSD label at the start gpart add -t freebsd -s $(($IMAGE_CODESIZE+1))M $CFCARD gpart create -s BSD ${CFCARD}s1 gpart bootcode -b $NANO_WORLDDIR/boot/boot ${CFCARD}s1 gpart add -i 1 -t freebsd-ufs -s ${IMAGE_CODESIZE}M ${CFCARD}s1 root1=3D${CFCARD}s1a if [ $NANO_IMAGES -gt 1 ]; then gpart add -i 2 -t freebsd -s $(($IMAGE_CODESIZE+1))M $CFCARD gpart create -s BSD ${CFCARD}s2 gpart bootcode -b $NANO_WORLDDIR/boot/boot ${CFCARD}s2 gpart add -t freebsd-ufs -s ${IMAGE_CODESIZE}M ${CFCARD}s2 root2=3D${CFCARD}s2a fi gpart add -i 3 -t freebsd -s ${IMAGE_CFGSIZE}M $CFCARD cfgpart=3D${CFCARD}s3 if [ -z "$IMAGE_DATASIZE" ] || [ "$IMAGE_DATASIZE" -gt 0 ]; then gpart add -i 4 -t freebsd ${IMAGE_DATASIZE:+-s = ${IMAGE_DATASIZE}M} $CFCARD datapart=3D${CFCARD}s4 fi # Mark the first partition bootable gpart bootcode -b $NANO_WORLDDIR/$NANO_BOOTLOADER $CFCARD gpart set -a active -i 1 $CFCARD # Configure boot0 boot0cfg $NANO_BOOT0CFG $CFCARD echo "### Populating root 1 partition" 1>&4 dd if=3D$IMG of=3D/dev/$root1 bs=3D8k skip=3D1 seek=3D1 if [ -n "$root2" ]; then echo "### Leaving empty root 2 partition" 1>&4 echo "### Populating config partition" 1>&4 fi newfs -L ${NANO_LABEL}cfg $cfgpart populate_fs /dev/$cfgpart ./Cfg ${IMAGE_SUBNAME:+./$IMAGE_SUBNAME/Cfg} = $cfgdir if [ -n "$datapart" ]; then echo "### Populating data partition" 1>&4 newfs -L ${NANO_LABEL}data $datapart populate_fs /dev/$datapart ${IMAGE_DEFAULTS}/Data ./Data = ${IMAGE_SUBNAME:+./$IMAGE_SUBNAME/Data} fi --Apple-Mail=_BA1B0337-80AC-40C3-86CD-81FB8AE711A4 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: GPGTools - http://gpgtools.org iEYEARECAAYFAlLnbtwACgkQBxE2H56uaYmCPQCfZBpch+L/a47OvnxxRWaSovRH aOYAnj69X6MuuFN2aBIVdHpFfOU4Mv6e =dA2C -----END PGP SIGNATURE----- --Apple-Mail=_BA1B0337-80AC-40C3-86CD-81FB8AE711A4--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69B43B44-C122-4D6E-92AB-7A5480ABFE54>