Permalink
Browse files

Large update to pc-sysinstall:

 * Improve how we create disk layouts for ZFS mirror/raidz disks
 * Do not blindly create a single freebsd-zfs partition
 * Create partition / sizes to match the parent disk
 * When adding freebsd-swap to a ZFS mirror/raidz parent, we will now setup gmirror on the
   swap devices and label it as such
  • Loading branch information...
1 parent ce67c5a commit 3018894abb9df102ef305a2e193e362ce731a16b @kmoore134 kmoore134 committed Aug 12, 2013
View
62 src-sh/pc-sysinstall/backend/functions-bsdlabel.sh
@@ -104,6 +104,7 @@ get_fs_line_xvars()
setup_zfs_mirror_parts()
{
_nZFS=""
+ SOUT="$4"
# Check if the target disk is using GRUB
grep -q "$3" ${TMPDIR}/.grub-install 2>/dev/null
@@ -126,9 +127,14 @@ setup_zfs_mirror_parts()
is_disk "$_zvars" >/dev/null 2>/dev/null
if [ $? -eq 0 ] ; then
+
+ # Save this disk as one we want to clone the original disk setup to
+ ZFS_CLONE_DISKS="$ZFS_CLONE_DISKS ${_zvars}"
+ export ZFS_CLONE_DISKS
+
echo "Setting up ZFS disk $_zvars" >>${LOGOUT}
init_gpt_full_disk "$_zvars" "$_tBL" >/dev/null 2>/dev/null
- rc_halt "gpart add -a 4k -t freebsd-zfs ${_zvars}" >/dev/null 2>/dev/null
+ #rc_halt "gpart add ${SOUT} -t freebsd-zfs ${_zvars}" >/dev/null 2>/dev/null
# If we are not using GRUB we need to add pmbr / gptzfsboot
if [ "$_tBL" != "GRUB" ] ; then
@@ -139,7 +145,10 @@ setup_zfs_mirror_parts()
_nZFS="$_nZFS ${_zvars}"
fi
done
- echo "$ZTYPE $2 `echo $_nZFS | tr -s ' '`"
+
+ # Export the ZXTRAOPTS
+ ZXTRAOPTS="$ZTYPE $2 `echo $_nZFS | tr -s ' '`"
+ export ZXTRAOPTS
} ;
# Function which creates a unique label name for the specified mount
@@ -243,6 +252,9 @@ setup_gpart_partitions()
fi
fi
+ # Unset ZFS_CLONE_DISKS
+ #ZFS_CLONE_DISKS=""
+
while read line
do
# Check for data on this slice
@@ -371,11 +383,14 @@ setup_gpart_partitions()
echo ${XTRAOPTS} | grep -q -e "mirror" -e "raidz"
if [ $? -eq 0 -a "$FS" = "ZFS" ] ; then
if [ "${_pType}" = "gpt" -o "${_pType}" = "gptslice" ] ; then
- XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}" "${_pDisk}")
+ setup_zfs_mirror_parts "${XTRAOPTS}" "${_pDisk}p${CURPART}" "${_pDisk}" "${SOUT}"
+ XTRAOPTS="${ZXTRAOPTS}"
elif [ "${_pType}" = "apm" ] ; then
- XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}s${CURPART}" "${_pDisk}")
+ setup_zfs_mirror_parts "${XTRAOPTS}" "${_pDisk}s${CURPART}" "${_pDisk}" "${SOUT}"
+ XTRAOPTS="${ZXTRAOPTS}"
else
- XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_wSlice}${PARTLETTER}" "${_pDisk}")
+ setup_zfs_mirror_parts "${XTRAOPTS}" "${_wSlice}${PARTLETTER}" "${_pDisk}" "${SOUT}"
+ XTRAOPTS="${ZXTRAOPTS}"
fi
fi
@@ -388,20 +403,14 @@ setup_gpart_partitions()
# Create the partition
if [ "${_pType}" = "gpt" ] ; then
- if [ "$CURPART" = "2" ] ; then
- # If this is GPT, make sure first partition is aligned to 4k
- sleep 2
- rc_halt "gpart add -a 4k ${SOUT} -t ${PARTYPE} ${_pDisk}"
- else
- sleep 2
- rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
- fi
+ sleep 2
+ aCmd="gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
elif [ "${_pType}" = "gptslice" ]; then
sleep 2
- rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_wSlice}"
+ aCmd="gpart add ${SOUT} -t ${PARTYPE} ${_wSlice}"
elif [ "${_pType}" = "apm" ]; then
sleep 2
- rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
+ aCmd="gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
else
sleep 2
@@ -412,7 +421,28 @@ setup_gpart_partitions()
if [ "$CURPART" = "1" -a "$PARTYPE" = "freebsd-zfs" ] ; then
aOpt="-a 512b"
fi
- rc_halt "gpart add ${SOUT} ${aOpt} -t ${PARTYPE} -i ${CURPART} ${_wSlice}"
+ aCmd="gpart add ${SOUT} ${aOpt} -t ${PARTYPE} -i ${CURPART} ${_wSlice}"
+ fi
+
+ # Run the gpart add command now
+ rc_halt "$aCmd"
+
+ # Check if we need to clone this layout to a ZFS mirror/raidz disk
+ if [ -n "$ZFS_CLONE_DISKS" ] ; then
+ for zC in $ZFS_CLONE_DISKS
+ do
+ echo_log "Cloning disk layout to ZFS disk ${zC}"
+ rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${zC}"
+ if [ "$PARTYPE" = "freebsd-swap" ] ; then
+ # If this is the first device, save the original swap dev
+ if [ -z "$ZFS_SWAP_DEVS" ] ; then
+ ZFS_SWAP_DEVS="${_pDisk}p${CURPART}"
+ fi
+ # Save this swap device, we will gmirror it later
+ ZFS_SWAP_DEVS="${ZFS_SWAP_DEVS} ${zC}p${CURPART}"
+ export ZFS_SWAP_DEVS
+ fi
+ done
fi
# Check if this is a root / boot partition, and stamp the right loader
View
2 src-sh/pc-sysinstall/backend/functions-cleanup.sh
@@ -387,7 +387,7 @@ run_final_cleanup()
{
# Check if we need to run any gmirror setup
ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null
- if [ $? -eq 0 ]
+ if [ $? -eq 0 -o -n "$ZFS_SWAP_DEVS" ]
then
# Lets setup gmirror now
setup_gmirror
View
14 src-sh/pc-sysinstall/backend/functions-disk.sh
@@ -287,13 +287,13 @@ stop_all_gmirror()
GPROV="`gmirror list | grep ". Name: mirror/" | cut -d '/' -f 2`"
for gprov in $GPROV
do
- gmirror list | grep -q "Name: ${DISK}" 2>/dev/null
- if [ $? -eq 0 ]
- then
- echo_log "Stopping mirror $gprov $DISK"
- rc_nohalt "gmirror remove $gprov $DISK"
- rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=4096"
- fi
+ dName=`gmirror list | grep -v 'mirror/' | grep "Name: " | awk '{print $3}'`
+ for rmDisk in $dName
+ do
+ echo_log "Stopping mirror $gprov $rmDisk"
+ rc_nohalt "gmirror remove $gprov $rmDisk"
+ rc_nohalt "dd if=/dev/zero of=/dev/${rmDisk} count=4096"
+ done
done
};
View
17 src-sh/pc-sysinstall/backend/functions-mountdisk.sh
@@ -246,17 +246,24 @@ mount_all_filesystems()
UFS+J) mount_partition ${PARTDEV}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;;
ZFS) mount_partition ${PARTDEV} ${PARTFS} ${PARTMNT} ;;
SWAP)
+
+ if [ -n "$ZFS_SWAP_DEVS" ] ; then
+ SWAPDEV="/dev/mirror/swapmirror"
+ else
+ SWAPDEV="$PARTDEV"
+ fi
+
# Lets enable this swap now
if [ "$PARTENC" = "ON" ]
then
- echo_log "Enabling encrypted swap on ${PARTDEV}"
- rc_halt "geli onetime -d -e 3des ${PARTDEV}"
+ echo_log "Enabling encrypted swap on ${SWAPDEV}"
+ rc_halt "geli onetime -d -e 3des ${SWAPDEV}"
sleep 5
- rc_halt "swapon ${PARTDEV}.eli"
+ rc_halt "swapon ${SWAPDEV}.eli"
else
- echo_log "swapon ${PARTDEV}"
+ echo_log "swapon ${SWAPDEV}"
sleep 5
- rc_halt "swapon ${PARTDEV}"
+ rc_halt "swapon ${SWAPDEV}"
fi
;;
IMAGE)
View
15 src-sh/pc-sysinstall/backend/functions-newfs.sh
@@ -256,7 +256,13 @@ setup_filesystems()
SWAP)
rc_halt "sync"
- rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
+ if [ -n "$ZFS_SWAP_DEVS" ] ; then
+ setup_gmirror_swap "$ZFS_SWAP_DEVS"
+ sleep 5
+ rc_halt "glabel label ${PARTLABEL} /dev/mirror/swapmirror"
+ else
+ rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
+ fi
rc_halt "sync"
sleep 2
;;
@@ -271,3 +277,10 @@ setup_filesystems()
done
};
+
+
+# Takes a list of args to setup as a swapmirror
+setup_gmirror_swap()
+{
+ rc_halt "gmirror label swapmirror ${@}"
+}

0 comments on commit 3018894

Please sign in to comment.