Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142095673
D2573.id5439.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D2573.id5439.diff
View Options
Index: tools/tools/nanobsd/defaults.sh
===================================================================
--- tools/tools/nanobsd/defaults.sh
+++ tools/tools/nanobsd/defaults.sh
@@ -140,9 +140,12 @@
# Can be "file" or "swap"
NANO_MD_BACKING="file"
-# for swap type md(4) backing, write out the mbr only
+# For swap type md(4) backing, write out the mbr only
NANO_IMAGE_MBRONLY=true
+# Partitioning scheme: MBR or GPT
+NANO_PART_SCHEME=MBR
+
# Progress Print level
PPLEVEL=3
@@ -419,7 +422,7 @@
echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size
# pick up config files from the special partition
- echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount
+ echo "mount -o ro /dev/${NANO_DRIVE}${SLICE}3" > conf/default/etc/remount
# Put /tmp on the /var ramdisk (could be symlink already)
nano_rm -rf tmp
@@ -443,8 +446,8 @@
# save config file for scripts
echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
- echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab
- echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab
+ echo "/dev/${NANO_DRIVE}${SYS1_SLICE} / ufs ro 1 1" > etc/fstab
+ echo "/dev/${NANO_DRIVE}${SLICE}3 /cfg ufs rw,noauto 2 2" >> etc/fstab
mkdir -p cfg
)
)
@@ -505,25 +508,37 @@
pprint 3 "log: ${NANO_OBJ}/_.di"
(
- echo $NANO_MEDIASIZE $NANO_IMAGES \
+ case $NANO_PART_SCHEME in
+ MBR)
+ unset GPART_LABEL
+ GPART_BOOTFL="active"
+ GPART_UFS="freebsd"
+ NANO_GPART_MEDIASIZE=${NANO_MEDIASIZE}
+ ;;
+ GPT)
+ GPART_LABEL="-l ${NANO_LABEL}"
+ GPART_BOOTFL="bootme"
+ GPART_UFS="freebsd-ufs"
+ NANO_GPART_MEDIASIZE=$((${NANO_MEDIASIZE} - 256))
+ # Reserve 256 sectors for boot partition
+ ;;
+ esac
+ echo $NANO_GPART_MEDIASIZE $NANO_IMAGES \
$NANO_SECTS $NANO_HEADS \
$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
+
awk '
{
printf "# %s\n", $0
+ print "create -s '$NANO_PART_SCHEME'"
+
# 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)
@@ -542,36 +557,35 @@
}
# First image partition start at second track
- print "p 1 165 " $3, isl * cs - $3
+ print "add -t ${GPART_UFS} -b " $3 " -s " isl * cs - $3 " -i 1 ${GPART_LABEL+${GPART_LABEL}${SLICE}1}"
+ print "set -i 1 -a ${GPART_BOOTFL}"
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
+ print "add -t ${GPART_UFS} -b " $3 + c " -s " isl * cs - $3 " -i 2 ${GPART_LABEL+${GPART_LABEL}${SLICE}2}"
c += isl * cs;
}
# Config partition starts at cylinder boundary.
- print "p 3 165 " c, csl * cs
+ print "add -t ${GPART_UFS} -b " c " -s " csl * cs " -i 3 ${GPART_LABEL+${GPART_LABEL}${SLICE}3}"
c += csl * cs
# Data partition (if any) starts at cylinder boundary.
if ($7 > 0) {
- print "p 4 165 " c, dsl * cs
+ print "add -t ${GPART_UFS} -b " c " -s " dsl * cs " -i 4 ${GPART_LABEL+${GPART_LABEL}${SLICE}4}"
} else if ($7 < 0 && $1 > c) {
- print "p 4 165 " c, $1 - c
+ print "add -t ${GPART_UFS} -b " c " -s " $1 - c " -i 4 ${GPART_LABEL+${GPART_LABEL}${SLICE}4}"
} 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"
+ print "commit!"
+ print "show!"
}
- ' > ${NANO_OBJ}/_.fdisk
+ ' | sed -e 's/^[^#]/gpart &/' -e 's/[^!]$/& -f x!/' -e 's/!$/ ${MD}/' > ${NANO_OBJ}/_.gpart
IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
MNT=${NANO_OBJ}/_.mnt
@@ -590,23 +604,39 @@
trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
- fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD}
- fdisk ${MD}
+ (set -x; . ${NANO_OBJ}/_.gpart)
# XXX: params
# XXX: pick up cached boot* files, they may not be in image anymore.
- if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
- boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
- fi
- if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
- bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1
- else
- bsdlabel -w ${MD}s1
- fi
- bsdlabel ${MD}s1
+
+ case $NANO_PART_SCHEME in
+ MBR)
+ # For MBR, we need to create a disklabel in the system slice to hold the
+ # boot blocks.
+ if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
+ boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
+ fi
+ if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
+ bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1
+ else
+ bsdlabel -w ${MD}s1
+ fi
+ bsdlabel ${MD}s1
+ ;;
+ GPT)
+ # For GPT, no bsdlabel is required, since the boot blocks live in their
+ # own freebsd-boot partition, and in any case gptboot expects freebsd-ufs
+ # partitions to contain an UFS filesystem, *not* a bsdlabel.
+ gpart add -t freebsd-boot -s 256 -i 15 ${GPART_LABEL}boot -f x ${MD}
+ if [ -f ${NANO_WORLDDIR}/boot/pmbr -a -f ${NANO_WORLDDIR}/boot/gptboot ]; then
+ gpart bootcode -b ${NANO_WORLDDIR}/boot/pmbr -p ${NANO_WORLDDIR}/boot/gptboot -i 15 -f x ${MD}
+ fi
+ gpart commit ${MD}
+ ;;
+ esac
# Create first image
- populate_slice /dev/${MD}s1a ${NANO_WORLDDIR} ${MNT} "s1a"
- mount /dev/${MD}s1a ${MNT}
+ populate_slice /dev/${MD}${SYS1_SLICE} ${NANO_WORLDDIR} ${MNT} "${SYS1_SLICE}"
+ mount /dev/${MD}${SYS1_SLICE} ${MNT}
echo "Generating mtree..."
( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree
( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du
@@ -615,26 +645,26 @@
if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
# Duplicate to second image (if present)
echo "Duplicating to second image..."
- dd conv=sparse if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
- mount /dev/${MD}s2a ${MNT}
+ dd conv=sparse if=/dev/${MD}${SLICE}1 of=/dev/${MD}${SLICE}2 bs=64k
+ mount /dev/${MD}${SYS2_SLICE} ${MNT}
for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
do
- sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f
+ sed -i "" "s=${NANO_DRIVE}${SLICE}1=${NANO_DRIVE}${SLICE}2=g" $f
done
nano_umount ${MNT}
# Override the label from the first partition so we
# don't confuse glabel with duplicates.
if [ ! -z ${NANO_LABEL} ]; then
- tunefs -L ${NANO_LABEL}"s2a" /dev/${MD}s2a
+ tunefs -L ${NANO_LABEL}"${SYS2_SLICE}" /dev/${MD}${SYS2_SLICE}
fi
fi
# Create Config slice
- populate_cfg_slice /dev/${MD}s3 "${NANO_CFGDIR}" ${MNT} "s3"
+ populate_cfg_slice /dev/${MD}${SLICE}3 "${NANO_CFGDIR}" ${MNT} "${SLICE}3"
# Create Data slice, if any.
if [ $NANO_DATASIZE -ne 0 ] ; then
- populate_data_slice /dev/${MD}s4 "${NANO_DATADIR}" ${MNT} "s4"
+ populate_data_slice /dev/${MD}${SLICE}4 "${NANO_DATADIR}" ${MNT} "${SLICE}4"
fi
if [ "${NANO_MD_BACKING}" = "swap" ] ; then
@@ -652,7 +682,7 @@
if ${do_copyout_partition} ; then
echo "Writing out _.disk.image..."
- dd conv=sparse if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
+ dd conv=sparse if=/dev/${MD}${SLICE}1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
fi
mdconfig -d -u $MD
@@ -948,6 +978,20 @@
# Override user's NANO_DRIVE if they specified a NANO_LABEL
[ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}"
+ # Set SLICE prefix character according to partitioning scheme
+ case ${NANO_PART_SCHEME} in
+ MBR)
+ SLICE=s
+ SYS1_SLICE=${SLICE}1a
+ SYS2_SLICE=${SLICE}2a
+ ;;
+ GPT)
+ SLICE=p
+ SYS1_SLICE=${SLICE}1
+ SYS2_SLICE=${SLICE}2
+ ;;
+ esac
+
# Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists.
[ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \
NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 17, 12:21 AM (35 m, 57 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27674384
Default Alt Text
D2573.id5439.diff (7 KB)
Attached To
Mode
D2573: NanoBSD: support for GPT partitioning
Attached
Detach File
Event Timeline
Log In to Comment