diff --git a/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh b/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh index ccb8d19ec273..d0343b4dcb1d 100755 --- a/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh +++ b/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh @@ -1,98 +1,98 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Create partitions on a target disk ############################# . ${PROGDIR}/backend/functions.sh if [ -z "${1}" ] ; then echo "Error: No disk specified!" exit 1 fi if [ -z "${2}" ] ; then echo "Error: No size specified!" exit 1 fi if [ ! -e "/dev/${1}" ] ; then echo "Error: Disk /dev/${1} does not exist!" exit 1 fi DISK="${1}" MB="${2}" TYPE="${3}" STARTBLOCK="${4}" TOTALBLOCKS="`expr $MB \* 2048`" # If no TYPE specified, default to MBR if [ -z "$TYPE" ] ; then TYPE="mbr" ; fi # Sanity check the gpart type case $TYPE in apm|APM) ;; bsd|BSD) ;; ebr|EBR) ;; pc98|pc98) ;; gpt|GPT) ;; mbr|MBR) ;; vtoc8|VTOC8) ;; *) echo "Error: Unknown gpart type: $TYPE" ; exit 1 ;; esac # Lets figure out what number this partition will be LASTSLICE="`gpart show $DISK | grep -v -e $DISK -e '\- free \-' -e '^$' | awk 'END {print $3}'`" if [ -z "${LASTSLICE}" ] ; then LASTSLICE="1" else LASTSLICE="`expr $LASTSLICE + 1`" fi SLICENUM="${LASTSLICE}" # Set a 4k Aligned start block if none specified if [ "${SLICENUM}" = "1" -a -z "$STARTBLOCK" ] ; then STARTBLOCK="2016" fi # If this is an empty disk, see if we need to create a new scheme for it gpart show ${DISK} >/dev/null 2>/dev/null if [ $? -eq 0 -a "${SLICENUM}" = "1" ] ; then gpart create -s ${TYPE} ${DISK} fi # If we have a starting block, use it -if [ -z "$STARTBLOCK" ] ; then +if [ -n "$STARTBLOCK" ] ; then sBLOCK="-b $STARTBLOCK" fi gpart add ${sBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK} exit "$?" diff --git a/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh b/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh index e819d740dd28..5b3069558e39 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh @@ -1,670 +1,678 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Functions related to disk operations using bsdlabel # Check if we are are provided a geli password on the nextline of the config check_for_enc_pass() { CURLINE="${1}" get_next_cfg_line "${CFGF}" "${CURLINE}" echo ${VAL} | grep -q "^encpass=" 2>/dev/null if [ $? -eq 0 ] ; then # Found a password, return it get_value_from_string "${VAL}" return fi export VAL="" return }; # On check on the disk-label line if we have any extra vars for this device -# Only enabled for ZFS devices now, may add other xtra options in future for other FS's get_fs_line_xvars() { ACTIVEDEV="${1}" LINE="${2}" echo $LINE | grep -q ' (' 2>/dev/null if [ $? -eq 0 ] ; then # See if we are looking for ZFS specific options echo $LINE | grep -q '^ZFS' 2>/dev/null if [ $? -eq 0 ] ; then ZTYPE="NONE" ZFSVARS="`echo $LINE | cut -d '(' -f 2- | cut -d ')' -f 1 | xargs`" echo $ZFSVARS | grep -qE "^(disk|file|mirror|raidz(1|2)?|spare|log|cache):" 2>/dev/null if [ $? -eq 0 ] ; then ZTYPE=`echo $ZFSVARS | cut -f1 -d:` ZFSVARS=`echo $ZFSVARS | sed "s|$ZTYPE: ||g" | sed "s|$ZTYPE:||g"` fi # Return the ZFS options if [ "${ZTYPE}" = "NONE" ] ; then VAR="${ACTIVEDEV} ${ZFSVARS}" else VAR="${ZTYPE} ${ACTIVEDEV} ${ZFSVARS}" fi export VAR return fi # End of ZFS block + # See if we are looking for UFS specific newfs options + echo $LINE | grep -q '^UFS' 2>/dev/null + if [ $? -eq 0 ] ; then + FSVARS="`echo $LINE | cut -d '(' -f 2- | cut -d ')' -f 1 | xargs`" + VAR="${FSVARS}" + export VAR + return + fi + fi # End of xtra-options block # If we got here, set VAR to empty and export export VAR="" return }; # Init each zfs mirror disk with a boot sector so we can failover setup_zfs_mirror_parts() { _nZFS="" # Using mirroring, setup boot partitions on each disk _mirrline="`echo ${1} | sed 's|mirror ||g'`" for _zvars in $_mirrline do echo "Looping through _zvars: $_zvars" >>${LOGOUT} echo "$_zvars" | grep -q "${2}" 2>/dev/null if [ $? -eq 0 ] ; then continue ; fi if [ -z "$_zvars" ] ; then continue ; fi is_disk "$_zvars" >/dev/null 2>/dev/null if [ $? -eq 0 ] ; then echo "Setting up ZFS mirror disk $_zvars" >>${LOGOUT} init_gpt_full_disk "$_zvars" >/dev/null 2>/dev/null rc_halt "gpart add -t freebsd-zfs ${_zvars}" >/dev/null 2>/dev/null _nZFS="$_nZFS ${_zvars}p2" else _nZFS="$_nZFS ${_zvars}" fi done echo "mirror $2 `echo $_nZFS | tr -s ' '`" } ; # Function which creates a unique label name for the specified mount gen_glabel_name() { MOUNT="$1" TYPE="$2" NUM="0" MAXNUM="20" # Check if we are doing /, and rename it if [ "$MOUNT" = "/" ] then NAME="rootfs" else # If doing a swap partition, also rename it if [ "${TYPE}" = "SWAP" ] then NAME="swap" else NAME="`echo $MOUNT | sed 's|/||g' | sed 's| ||g'`" fi fi # Loop through and break when we find our first available label while Z=1 do glabel status | grep -q "${NAME}${NUM}" 2>/dev/null if [ $? -ne 0 ] then break else NUM=$((NUM+1)) fi if [ $NUM -gt $MAXNUM ] then exit_err "Cannot allocate additional glabel name for $NAME" break fi done export VAL="${NAME}${NUM}" }; # Function to setup partitions using gpart setup_gpart_partitions() { local _dTag="$1" local _pDisk="$2" local _wSlice="$3" local _sNum="$4" local _pType="$5" FOUNDPARTS="1" # Lets read in the config file now and setup our partitions if [ "${_pType}" = "gpt" ] ; then CURPART="2" else PARTLETTER="a" CURPART="1" rc_halt "gpart create -s BSD ${_wSlice}" fi while read line do # Check for data on this slice echo $line | grep -q "^${_dTag}-part=" 2>/dev/null if [ $? -eq 0 ] then FOUNDPARTS="0" # Found a slice- entry, lets get the slice info get_value_from_string "${line}" STRING="$VAL" # We need to split up the string now, and pick out the variables FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1` SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3` # Check if we have a .eli extension on this FS echo ${FS} | grep -q ".eli" 2>/dev/null if [ $? -eq 0 ] then FS="`echo ${FS} | cut -d '.' -f 1`" ENC="ON" check_for_enc_pass "${line}" if [ "${VAL}" != "" ] ; then # We have a user supplied password, save it for later ENCPASS="${VAL}" fi else ENC="OFF" fi # Check if the user tried to setup / as an encrypted partition check_for_mount "${MNT}" "/" if [ $? -eq 0 -a "${ENC}" = "ON" ] then export USINGENCROOT="0" fi # Now check that these values are sane case $FS in UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP) ;; *) exit_err "ERROR: Invalid file system specified on $line" ;; esac # Check that we have a valid size number expr $SIZE + 1 >/dev/null 2>/dev/null if [ $? -ne 0 ]; then exit_err "ERROR: The size specified on $line is invalid" fi # Check that the mount-point starts with / echo "$MNT" | grep -qe "^/" -e "^none" 2>/dev/null if [ $? -ne 0 ]; then exit_err "ERROR: The mount-point specified on $line is invalid" fi if [ "$SIZE" = "0" ] then SOUT="" else SOUT="-s ${SIZE}M" fi # Check if we found a valid root partition check_for_mount "${MNT}" "/" if [ $? -eq 0 ] ; then export FOUNDROOT="1" if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then export FOUNDROOT="0" fi if [ "${CURPART}" = "1" -a "$_pType" = "mbr" ] ; then export FOUNDROOT="0" fi fi check_for_mount "${MNT}" "/boot" if [ $? -eq 0 ] ; then export USINGBOOTPART="0" if [ "${CURPART}" != "2" -a "${_pType}" = "gpt" ] ; then exit_err "/boot partition must be first partition" fi if [ "${CURPART}" != "1" -a "${_pType}" = "mbr" ] ; then exit_err "/boot partition must be first partition" fi if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ] ; then exit_err "/boot partition must be formatted with UFS" fi fi # Generate a unique label name for this mount gen_glabel_name "${MNT}" "${FS}" PLABEL="${VAL}" # Get any extra options for this fs / line if [ "${_pType}" = "gpt" ] ; then get_fs_line_xvars "${_pDisk}p${CURPART}" "${STRING}" else get_fs_line_xvars "${_wSlice}" "${STRING}" fi XTRAOPTS="${VAR}" # Check if using zfs mirror echo ${XTRAOPTS} | grep -q "mirror" 2>/dev/null - if [ $? -eq 0 ] ; then + if [ $? -eq 0 -a "$FS" = "ZFS" ] ; then if [ "${_pType}" = "gpt" ] ; then XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}") else XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_wSlice}") fi fi # Figure out the gpart type to use case ${FS} in ZFS) PARTYPE="freebsd-zfs" ;; SWAP) PARTYPE="freebsd-swap" ;; *) PARTYPE="freebsd-ufs" ;; esac # Create the partition if [ "${_pType}" = "gpt" ] ; then if [ "$CURPART" = "2" ] ; then # If this is GPT, make sure first partition is aligned to 4k rc_halt "gpart add -b 2016 ${SOUT} -t ${PARTYPE} ${_pDisk}" else rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}" fi else rc_halt "gpart add ${SOUT} -t ${PARTYPE} -i ${CURPART} ${_wSlice}" fi # Check if this is a root / boot partition, and stamp the right loader for TESTMNT in `echo ${MNT} | sed 's|,| |g'` do if [ "${TESTMNT}" = "/" -a -z "${BOOTTYPE}" ] ; then BOOTTYPE="${PARTYPE}" fi if [ "${TESTMNT}" = "/boot" ] ; then BOOTTYPE="${PARTYPE}" fi done # Save this data to our partition config dir if [ "${_pType}" = "gpt" ] ; then _dFile="`echo $_pDisk | sed 's|/|-|g'`" echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${_dFile}p${CURPART} # Clear out any headers sleep 2 dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 2>/dev/null # If we have a enc password, save it as well if [ -n "${ENCPASS}" ] ; then echo "${ENCPASS}" >${PARTDIR}-enc/${_dFile}p${CURPART}-encpass fi else # MBR Partition _dFile="`echo $_wSlice | sed 's|/|-|g'`" echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${_dFile}${PARTLETTER} # Clear out any headers sleep 2 dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 2>/dev/null # If we have a enc password, save it as well if [ -n "${ENCPASS}" ] ; then echo "${ENCPASS}" >${PARTDIR}-enc/${_dFile}${PARTLETTER}-encpass fi fi # Increment our parts counter if [ "$_pType" = "gpt" ] ; then CURPART=$((CURPART+1)) # If this is a gpt partition, we can continue and skip the MBR part letter stuff continue else CURPART=$((CURPART+1)) if [ "$CURPART" = "3" ] ; then CURPART="4" ; fi fi # This partition letter is used, get the next one case ${PARTLETTER} in a) PARTLETTER="b" ;; b) PARTLETTER="d" ;; d) PARTLETTER="e" ;; e) PARTLETTER="f" ;; f) PARTLETTER="g" ;; g) PARTLETTER="h" ;; h) PARTLETTER="ERR" ;; *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;; esac fi # End of subsection locating a slice in config echo $line | grep -q "^commitDiskLabel" 2>/dev/null if [ $? -eq 0 -a "${FOUNDPARTS}" = "0" ] then # If this is the boot disk, stamp the right gptboot if [ ! -z "${BOOTTYPE}" -a "$_pType" = "gpt" ] ; then case ${BOOTTYPE} in freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${_pDisk}" ;; freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${_pDisk}" ;; esac fi # Make sure to stamp the MBR loader if [ "$_pType" = "mbr" ] ; then rc_halt "gpart bootcode -b /boot/boot ${_wSlice}" fi # Found our flag to commit this label setup, check that we found at least 1 partition if [ "${CURPART}" = "2" ] ; then exit_err "ERROR: commitDiskLabel was called without any partition entries for it!" fi break fi done <${CFGF} }; # Reads through the config and sets up a BSDLabel for the given slice populate_disk_label() { if [ -z "${1}" ] then exit_err "ERROR: populate_disk_label() called without argument!" fi # Set some vars from the given working slice diskid="`echo $1 | cut -d ':' -f 1`" disk="`echo $1 | cut -d ':' -f 1 | sed 's|-|/|g'`" slicenum="`echo $1 | cut -d ':' -f 2`" type="`echo $1 | cut -d ':' -f 3`" # Set WRKSLICE based upon format we are using if [ "$type" = "mbr" ] ; then wrkslice="${diskid}s${slicenum}" fi if [ "$type" = "gpt" ] ; then wrkslice="${diskid}p${slicenum}" fi if [ ! -e "${SLICECFGDIR}/${wrkslice}" ] ; then exit_err "ERROR: Missing SLICETAG data. This shouldn't happen - please let the developers know" fi disktag="`cat ${SLICECFGDIR}/${wrkslice}`" slicedev="`echo $wrkslice | sed 's|-|/|g'`" # Setup the partitions with gpart setup_gpart_partitions "${disktag}" "${disk}" "${slicedev}" "${slicenum}" "${type}" }; # Function which reads in the disk slice config, and performs it setup_disk_label() { # We are ready to start setting up the label, lets read the config and do the actions # First confirm that we have a valid WORKINGSLICES if [ -z "${WORKINGSLICES}" ]; then exit_err "ERROR: No slices were setup! Please report this to the maintainers" fi # Check that the slices we have did indeed get setup and gpart worked for i in $WORKINGSLICES do disk="`echo $i | cut -d '-' -f 1`" pnum="`echo $i | cut -d '-' -f 2`" type="`echo $i | cut -d '-' -f 3`" if [ "$type" = "mbr" -a ! -e "${disk}s${pnum}" ] ; then exit_err "ERROR: The partition ${i} doesn't exist! gpart failure!" fi if [ "$type" = "gpt" -a ! -e "${disk}p${pnum}" ] ; then exit_err "ERROR: The partition ${i} doesn't exist! gpart failure!" fi done # Setup some files which we'll be referring to export LABELLIST="${TMPDIR}/workingLabels" rm $LABELLIST >/dev/null 2>/dev/null # Set our flag to determine if we've got a valid root partition in this setup export FOUNDROOT="-1" # Check if we are using a /boot partition export USINGBOOTPART="1" # Set encryption on root check export USINGENCROOT="1" # Make the tmp directory where we'll store FS info & mount-points rm -rf ${PARTDIR} >/dev/null 2>/dev/null mkdir -p ${PARTDIR} >/dev/null 2>/dev/null rm -rf ${PARTDIR}-enc >/dev/null 2>/dev/null mkdir -p ${PARTDIR}-enc >/dev/null 2>/dev/null for i in $WORKINGSLICES do populate_disk_label "${i}" done # Check if we made a root partition if [ "$FOUNDROOT" = "-1" ] then exit_err "ERROR: No root (/) partition specified!!" fi # Check if we made a root partition if [ "$FOUNDROOT" = "1" -a "${USINGBOOTPART}" != "0" ] then exit_err "ERROR: (/) partition isn't first partition on disk!" fi if [ "${USINGENCROOT}" = "0" -a "${USINGBOOTPART}" != "0" ] then exit_err "ERROR: Can't encrypt (/) with no (/boot) partition!" fi }; check_fstab_mbr() { local SLICE local FSTAB if [ -z "$2" ] then return 1 fi SLICE="$1" FSTAB="$2/etc/fstab" if [ -f "${FSTAB}" ] then PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'` cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTLETTER}" = "a" ] then FOUNDROOT="0" else FOUNDROOT="1" fi ROOTIMAGE="1" export FOUNDROOT export ROOTIMAGE fi cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/boot$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTLETTER}" = "a" ] then USINGBOOTPART="0" else exit_err "/boot partition must be first partition" fi export USINGBOOTPART fi return 0 fi return 1 }; check_fstab_gpt() { local SLICE local FSTAB if [ -z "$2" ] then return 1 fi SLICE="$1" FSTAB="$2/etc/fstab" if [ -f "${FSTAB}" ] then PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'` cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTNUMBER}" = "2" ] then FOUNDROOT="0" else FOUNDROOT="1" fi ROOTIMAGE="1" export FOUNDROOT export ROOTIMAGE fi cat "${FSTAB}" | awk '{ print $2 }' | grep -qE '^/boot$' 2>&1 if [ $? -eq 0 ] then if [ "${PARTNUMBER}" = "2" ] then USINGBOOTPART="0" else exit_err "/boot partition must be first partition" fi export USINGBOOTPART fi return 0 fi return 1 }; check_disk_layout() { local SLICES local TYPE local DISK local RES local F DISK="$1" TYPE="MBR" if [ -z "${DISK}" ] then return 1 fi SLICES_MBR=`ls /dev/${DISK}s[1-4]*[a-h]* 2>/dev/null` SLICES_GPT=`ls /dev/${DISK}p[0-9]* 2>/dev/null` SLICES_SLICE=`ls /dev/${DISK}[a-h]* 2>/dev/null` if [ -n "${SLICES_MBR}" ] then SLICES="${SLICES_MBR}" TYPE="MBR" RES=0 fi if [ -n "${SLICES_GPT}" ] then SLICES="${SLICES_GPT}" TYPE="GPT" RES=0 fi if [ -n "${SLICES_SLICE}" ] then SLICES="${SLICES_SLICE}" TYPE="MBR" RES=0 fi for slice in ${SLICES} do F=1 mount ${slice} /mnt 2>/dev/null if [ $? -ne 0 ] then continue fi if [ "${TYPE}" = "MBR" ] then check_fstab_mbr "${slice}" "/mnt" F="$?" elif [ "${TYPE}" = "GPT" ] then check_fstab_gpt "${slice}" "/mnt" F="$?" fi if [ ${F} -eq 0 ] then umount /mnt break fi umount /mnt done return ${RES} }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-disk.sh b/usr.sbin/pc-sysinstall/backend/functions-disk.sh index c63f7afd7ecf..73c3eb4c179f 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-disk.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-disk.sh @@ -1,849 +1,849 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Functions related to disk operations using gpart # See if device is a full disk or partition/slice is_disk() { for _dsk in `sysctl -n kern.disks` do [ "$_dsk" = "${1}" ] && return 0 done return 1 } # Get a MBR partitions sysid get_partition_sysid_mbr() { INPART="0" DISK="$1" PARTNUM=`echo ${2} | sed "s|${DISK}s||g"` fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null while read i do echo "$i" | grep -q "The data for partition" 2>/dev/null if [ $? -eq 0 ] ; then INPART="0" PART="`echo ${i} | cut -d ' ' -f 5`" if [ "$PART" = "$PARTNUM" ] ; then INPART="1" fi fi # In the partition section if [ "$INPART" = "1" ] ; then echo "$i" | grep -q "^sysid" 2>/dev/null if [ $? -eq 0 ] ; then SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`" break fi fi done < ${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${SYSID}" }; # Get the partitions MBR label get_partition_label_mbr() { INPART="0" DISK="$1" PARTNUM=`echo ${2} | sed "s|${DISK}s||g"` fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null while read i do echo "$i" | grep -q "The data for partition" 2>/dev/null if [ $? -eq 0 ] ; then INPART="0" PART="`echo ${i} | cut -d ' ' -f 5`" if [ "$PART" = "$PARTNUM" ] ; then INPART="1" fi fi # In the partition section if [ "$INPART" = "1" ] ; then echo "$i" | grep -q "^sysid" 2>/dev/null if [ $? -eq 0 ] ; then LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`" break fi fi done < ${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${LABEL}" }; # Get a GPT partitions label get_partition_label_gpt() { DISK="${1}" PARTNUM=`echo ${2} | sed "s|${DISK}p||g"` gpart show ${DISK} >${TMPDIR}/disk-${DISK} while read i do SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`" if [ "${SLICE}" = "${PARTNUM}" ] ; then LABEL="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4`" break fi done <${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${LABEL}" }; # Get a partitions startblock get_partition_startblock() { DISK="${1}" PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"` gpart show ${DISK} >${TMPDIR}/disk-${DISK} while read i do SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`" if [ "$SLICE" = "${PARTNUM}" ] ; then SB="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 1`" break fi done <${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${SB}" }; # Get a partitions blocksize get_partition_blocksize() { DISK="${1}" PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"` gpart show ${DISK} >${TMPDIR}/disk-${DISK} while read i do SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`" if [ "$SLICE" = "${PARTNUM}" ] ; then BS="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 2`" break fi done <${TMPDIR}/disk-${DISK} rm ${TMPDIR}/disk-${DISK} export VAL="${BS}" }; # Function which returns the partitions on a target disk get_disk_partitions() { gpart show ${1} >/dev/null 2>/dev/null if [ $? -ne 0 ] ; then export VAL="" return fi type=`gpart show ${1} | awk '/^=>/ { printf("%s",$5); }'` SLICES="`gpart show ${1} | grep -v ${1} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4 | sed '/^$/d'`" for i in ${SLICES} do case $type in MBR) name="${1}s${i}" ;; GPT) name="${1}p${i}";; *) name="${1}s${i}";; esac if [ -z "${RSLICES}" ] then RSLICES="${name}" else RSLICES="${RSLICES} ${name}" fi done export VAL="${RSLICES}" }; # Function which returns a target disks cylinders get_disk_cyl() { cyl=`diskinfo -v ${1} | grep "# Cylinders" | tr -s ' ' | cut -f 2` export VAL="${cyl}" }; # Function which returns a target disks sectors get_disk_sectors() { sec=`diskinfo -v ${1} | grep "# Sectors" | tr -s ' ' | cut -f 2` export VAL="${sec}" }; # Function which returns a target disks heads get_disk_heads() { head=`diskinfo -v ${1} | grep "# Heads" | tr -s ' ' | cut -f 2` export VAL="${head}" }; # Function which returns a target disks mediasize in sectors get_disk_mediasize() { mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2` export VAL="${mediasize}" }; # Function which exports all zpools, making them safe to overwrite potentially export_all_zpools() { # Export any zpools for i in `zpool list -H -o name` do zpool export -f ${i} done }; # Function to delete all gparts before starting an install delete_all_gpart() { echo_log "Deleting all gparts" local DISK="$1" # Check for any swaps to stop for i in `swapctl -l | grep "$DISK" | awk '{print $1}'` do swapoff ${i} >/dev/null 2>/dev/null done # Delete the gparts now for i in `gpart show ${DISK} 2>/dev/null | tr -s ' ' | cut -d ' ' -f 4` do if [ "/dev/${i}" != "${DISK}" -a "${i}" != "-" ] ; then rc_nohalt "gpart delete -i ${i} ${DISK}" fi done # Destroy the disk geom rc_nohalt "gpart destroy ${DISK}" # Make sure we clear any hidden gpt tables clear_backup_gpt_table "${DISK}" # Wipe out front of disk rc_nohalt "dd if=/dev/zero of=${DISK} count=3000" }; # Function to export all zpools before starting an install stop_all_zfs() { # Export all zpools again, so that we can overwrite these partitions potentially for i in `zpool list -H -o name` do zpool export -f ${i} done }; # Function which stops all gmirrors before doing any disk manipulation stop_all_gmirror() { local DISK="`echo ${1} | sed 's|/dev/||g'`" 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 done }; # Make sure we don't have any geli providers active on this disk stop_all_geli() { local _geld="`echo ${1} | sed 's|/dev/||g'`" cd /dev for i in `ls ${_geld}*` do echo $i | grep -q '.eli' 2>/dev/null if [ $? -eq 0 ] then echo_log "Detaching GELI on ${i}" rc_halt "geli detach ${i}" fi done }; # Function which reads in the disk slice config, and performs it setup_disk_slice() { # Cleanup any slice / mirror dirs rm -rf ${SLICECFGDIR} >/dev/null 2>/dev/null mkdir ${SLICECFGDIR} rm -rf ${MIRRORCFGDIR} >/dev/null 2>/dev/null mkdir ${MIRRORCFGDIR} # Start with disk0 and gm0 disknum="0" gmnum="0" # Make sure all zpools are exported export_all_zpools # We are ready to start setting up the disks, lets read the config and do the actions while read line do echo $line | grep -q "^disk${disknum}=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" DISK="$VAL" echo "${DISK}" | grep -q '^/dev/' if [ $? -ne 0 ] ; then DISK="/dev/$DISK" ; fi # Before we go further, lets confirm this disk really exists if [ ! -e "${DISK}" ] ; then exit_err "ERROR: The disk ${DISK} does not exist!" fi # Make sure we stop any gmirrors on this disk stop_all_gmirror ${DISK} # Make sure we stop any geli stuff on this disk stop_all_geli ${DISK} # Make sure we don't have any zpools loaded stop_all_zfs fi # Lets look if this device will be mirrored on another disk echo $line | grep -q "^mirror=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" MIRRORDISK="$VAL" echo "${MIRRORDISK}" | grep -q '^/dev/' if [ $? -ne 0 ] ; then MIRRORDISK="/dev/$MIRRORDISK" ; fi # Before we go further, lets confirm this disk really exists if [ ! -e "${MIRRORDISK}" ] then exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!" fi fi # Lets see if we have been given a mirror balance choice echo $line | grep -q "^mirrorbal=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" MIRRORBAL="$VAL" fi echo $line | grep -q "^partition=" 2>/dev/null if [ $? -eq 0 ] then # Found a partition= entry, lets read / set it get_value_from_string "${line}" strip_white_space "$VAL" PTYPE=`echo $VAL|tr A-Z a-z` # We are using free space, figure out the slice number if [ "${PTYPE}" = "free" ] then # Lets figure out what number this slice will be LASTSLICE="`gpart show ${DISK} \ | grep -v ${DISK} \ | grep -v ' free' \ | tr -s '\t' ' ' \ | cut -d ' ' -f 4 \ | sed '/^$/d' \ | tail -n 1`" if [ -z "${LASTSLICE}" ] then LASTSLICE="1" else LASTSLICE=$((LASTSLICE+1)) fi if [ $LASTSLICE -gt 4 ] then exit_err "ERROR: BSD only supports primary partitions, and there are none availble on $DISK" fi fi fi # Check if we have an image file defined echo $line | grep -q "^image=" 2>/dev/null if [ $? -eq 0 ] ; then # Found an image= entry, lets read / set it get_value_from_string "${line}" strip_white_space "$VAL" IMAGE="$VAL" if [ ! -f "$IMAGE" ] ; then exit_err "$IMAGE file does not exist" fi fi # Check if we have a partscheme specified echo $line | grep -q "^partscheme=" 2>/dev/null if [ $? -eq 0 ] ; then # Found a partscheme= entry, lets read / set it get_value_from_string "${line}" strip_white_space "$VAL" PSCHEME="$VAL" if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then exit_err "Unknown partition scheme: $PSCHEME" fi fi echo $line | grep -q "^bootManager=" 2>/dev/null if [ $? -eq 0 ] then # Found a bootManager= entry, lets read /set it get_value_from_string "${line}" strip_white_space "$VAL" BMANAGER="$VAL" fi echo $line | grep -q "^commitDiskPart" 2>/dev/null if [ $? -eq 0 ] then # Found our flag to commit this disk setup / lets do sanity check and do it if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ] then case ${PTYPE} in all) # If we have a gmirror, lets set it up if [ -n "$MIRRORDISK" ]; then # Default to round-robin if the user didn't specify if [ -z "$MIRRORBAL" ]; then MIRRORBAL="round-robin" ; fi echo "$MIRRORDISK:$MIRRORBAL:gm${gmnum}" >${MIRRORCFGDIR}/$DISK init_gmirror "$gmnum" "$MIRRORBAL" "$DISK" "$MIRRORDISK" # Reset DISK to the gmirror device DISK="/dev/mirror/gm${gmnum}" gmnum=$((gmknum+1)) fi if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then PSCHEME="MBR" tmpSLICE="${DISK}s1" else tmpSLICE="${DISK}p1" fi run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}" ;; s1|s2|s3|s4) tmpSLICE="${DISK}${PTYPE}" # Get the number of the slice we are working on s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" run_gpart_slice "${DISK}" "${BMANAGER}" "${s}" ;; free) tmpSLICE="${DISK}s${LASTSLICE}" run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}" ;; image) if [ -z "${IMAGE}" ] then exit_err "ERROR: partition type image specified with no image!" fi ;; *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;; esac if [ -n "${IMAGE}" ] then local DEST if [ -n "${tmpSLICE}" ] then DEST="${tmpSLICE}" else DEST="${DISK}" fi write_image "${IMAGE}" "${DEST}" check_disk_layout "${DEST}" fi # Now save which disk this is, so we can parse it later during slice partition setup if [ -z "${IMAGE}" ] then _sFile=`echo $tmpSLICE | sed 's|/|-|g'` echo "disk${disknum}" >${SLICECFGDIR}/$_sFile fi # Increment our disk counter to look for next disk and unset unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE disknum=$((disknum+1)) else exit_err "ERROR: commitDiskPart was called without procceding disk= and partition= entries!!!" fi fi done <${CFGF} }; # Init the gmirror device init_gmirror() { local _mNum=$1 local _mBal=$2 local _mDisk=$3 # Create this mirror device - rc_halt "gmirror label -vb ${_mBal} gm${_mNum} /dev/${_mDisk}" + rc_halt "gmirror label -vb ${_mBal} gm${_mNum} ${_mDisk}" sleep 3 } # Stop all gjournals on disk / slice stop_gjournal() { _gdsk="`echo $1 | sed 's|/dev/||g'`" # Check if we need to shutdown any journals on this drive ls /dev/${_gdsk}*.journal >/dev/null 2>/dev/null if [ $? -eq 0 ] then cd /dev for i in `ls ${_gdsk}*.journal` do rawjournal="`echo ${i} | cut -d '.' -f 1`" gjournal stop -f ${rawjournal} >>${LOGOUT} 2>>${LOGOUT} gjournal clear ${rawjournal} >>${LOGOUT} 2>>${LOGOUT} done fi } ; # Function to wipe the potential backup gpt table from a disk clear_backup_gpt_table() { echo_log "Clearing gpt backup table location on disk" rc_nohalt "dd if=/dev/zero of=${1} bs=1m count=1" rc_nohalt "dd if=/dev/zero of=${1} bs=1m oseek=`diskinfo ${1} | awk '{print int($3 / (1024*1024)) - 4;}'`" } ; # Function which runs gpart and creates a single large GPT partition scheme init_gpt_full_disk() { _intDISK=$1 # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Stop any journaling stop_gjournal "${_intDISK}" # Remove any existing partitions delete_all_gpart "${_intDISK}" sleep 2 echo_log "Running gpart on ${_intDISK}" rc_halt "gpart create -s GPT ${_intDISK}" rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}" echo_log "Stamping boot sector on ${_intDISK}" rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}" } # Function which runs gpart and creates a single large MBR partition scheme init_mbr_full_disk() { _intDISK=$1 _intBOOT=$2 startblock="2016" # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Stop any journaling stop_gjournal "${_intDISK}" # Remove any existing partitions delete_all_gpart "${_intDISK}" sleep 2 echo_log "Running gpart on ${_intDISK}" rc_halt "gpart create -s mbr ${_intDISK}" # Lets figure out disk size in blocks # Get the cyl of this disk get_disk_cyl "${_intDISK}" cyl="${VAL}" # Get the heads of this disk get_disk_heads "${_intDISK}" head="${VAL}" # Get the tracks/sectors of this disk get_disk_sectors "${_intDISK}" sec="${VAL}" # Multiply them all together to get our total blocks totalblocks="`expr ${cyl} \* ${head} 2>/dev/null`" totalblocks="`expr ${totalblocks} \* ${sec} 2>/dev/null`" if [ -z "${totalblocks}" ] then totalblocks=`gpart show "${_intDISK}"|tail -2|head -1|awk '{ print $2 }'` fi # Now set the ending block to the total disk block size sizeblock="`expr ${totalblocks} - ${startblock}`" # Install new partition setup echo_log "Running gpart add on ${_intDISK}" rc_halt "gpart add -b ${startblock} -s ${sizeblock} -t freebsd -i 1 ${_intDISK}" sleep 2 echo_log "Cleaning up ${_intDISK}s1" rc_halt "dd if=/dev/zero of=${_intDISK}s1 count=1024" if [ "$_intBOOT" = "bsd" ] ; then echo_log "Stamping boot0 on ${_intDISK}" rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}" else echo_log "Stamping boot1 on ${_intDISK}" rc_halt "gpart bootcode -b /boot/boot1 ${_intDISK}" fi } # Function which runs gpart and creates a single large slice run_gpart_full() { DISK=$1 BOOT=$2 SCHEME=$3 if [ "$SCHEME" = "MBR" ] ; then init_mbr_full_disk "$DISK" "$BOOT" slice=`echo "${DISK}:1:mbr" | sed 's|/|-|g'` else init_gpt_full_disk "$DISK" slice=`echo "${DISK}:1:gpt" | sed 's|/|-|g'` fi # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; # Function which runs gpart on a specified s1-4 slice run_gpart_slice() { DISK=$1 if [ -n "$2" ] then BMANAGER="$2" fi # Set the slice we will use later slice="${1}s${3}" # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} # Get the number of the slice we are working on slicenum="$3" # Stop any journaling stop_gjournal "${slice}" # Make sure we have disabled swap on this drive if [ -e "${slice}b" ] then swapoff ${slice}b >/dev/null 2>/dev/null swapoff ${slice}b.eli >/dev/null 2>/dev/null fi # Modify partition type echo_log "Running gpart modify on ${DISK}" rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}" sleep 2 # Clean up old partition echo_log "Cleaning up $slice" rc_halt "dd if=/dev/zero of=${DISK}s${slicenum} count=1024" sleep 1 if [ "${BMANAGER}" = "bsd" ] then echo_log "Stamping boot sector on ${DISK}" rc_halt "gpart bootcode -b /boot/boot0 ${DISK}" fi # Set the slice to the format we'll be using for gpart later slice=`echo "${1}:${3}:mbr" | sed 's|/|-|g'` # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; # Function which runs gpart and creates a new slice from free disk space run_gpart_free() { DISK=$1 SLICENUM=$2 if [ -n "$3" ] then BMANAGER="$3" fi # Set our sysctl so we can overwrite any geom using drives sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} slice="${DISK}s${SLICENUM}" slicenum="${SLICENUM}" # Working on the first slice, make sure we have MBR setup gpart show ${DISK} >/dev/null 2>/dev/null if [ $? -ne 0 -a "$SLICENUM" = "1" ] ; then echo_log "Initializing disk, no existing MBR setup" rc_halt "gpart create -s mbr ${DISK}" fi # Lets get the starting block first if [ "${slicenum}" = "1" ] then startblock="63" else # Lets figure out where the prior slice ends checkslice=$((slicenum-1)) # Get starting block of this slice sblk=`gpart show ${DISK} | grep -v ${DISK} | tr -s '\t' ' ' | sed '/^$/d' | grep " ${checkslice} " | cut -d ' ' -f 2` blksize=`gpart show ${DISK} | grep -v ${DISK} | tr -s '\t' ' ' | sed '/^$/d' | grep " ${checkslice} " | cut -d ' ' -f 3` startblock=$((sblk+blksiz)) fi # No slice after the new slice, lets figure out the free space remaining and use it # Get the cyl of this disk get_disk_cyl "${DISK}" cyl="${VAL}" # Get the heads of this disk get_disk_heads "${DISK}" head="${VAL}" # Get the tracks/sectors of this disk get_disk_sectors "${DISK}" sec="${VAL}" # Multiply them all together to get our total blocks totalblocks=$((cyl*head)) totalblocks=$((totalblocks*sec)) # Now set the ending block to the total disk block size sizeblock=$((totalblocks-startblock)) # Install new partition setup echo_log "Running gpart on ${DISK}" rc_halt "gpart add -b ${startblock} -s ${sizeblock} -t freebsd -i ${slicenum} ${DISK}" sleep 2 echo_log "Cleaning up $slice" rc_halt "dd if=/dev/zero of=${slice} count=1024" sleep 1 if [ "${BMANAGER}" = "bsd" ] then echo_log "Stamping boot sector on ${DISK}" rc_halt "gpart bootcode -b /boot/boot0 ${DISK}" fi slice=`echo "${DISK}:${SLICENUM}:mbr" | sed 's|/|-|g'` # Lets save our slice, so we know what to look for in the config file later on if [ -z "$WORKINGSLICES" ] then WORKINGSLICES="${slice}" export WORKINGSLICES else WORKINGSLICES="${WORKINGSLICES} ${slice}" export WORKINGSLICES fi }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh b/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh index 75b5a410bc72..5d32466e6a54 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh @@ -1,441 +1,455 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Functions which perform the extraction / installation of system to disk . ${BACKEND}/functions-mountoptical.sh # Performs the extraction of data to disk from a uzip or tar archive start_extract_uzip_tar() { if [ -z "$INSFILE" ] then exit_err "ERROR: Called extraction with no install file set!" fi # Check if we have a .count file, and echo it out for a front-end to use in progress bars if [ -e "${INSFILE}.count" ] then echo "INSTALLCOUNT: `cat ${INSFILE}.count`" fi # Check if we are doing an upgrade, and if so use our exclude list if [ "${INSTALLMODE}" = "upgrade" ] then TAROPTS="-X ${PROGDIR}/conf/exclude-from-upgrade" else TAROPTS="" fi echo_log "pc-sysinstall: Starting Extraction" case ${PACKAGETYPE} in uzip) + if ! kldstat -v | grep -q "geom_uzip" ; then + exit_err "Kernel module geom_uzip not loaded" + fi + # Start by mounting the uzip image MDDEVICE=`mdconfig -a -t vnode -o readonly -f ${INSFILE}` mkdir -p ${FSMNT}.uzip mount -r /dev/${MDDEVICE}.uzip ${FSMNT}.uzip if [ $? -ne 0 ] then exit_err "ERROR: Failed mounting the ${INSFILE}" fi cd ${FSMNT}.uzip # Copy over all the files now! tar cvf - . 2>/dev/null | tar -xpv -C ${FSMNT} ${TAROPTS} -f - 2>&1 | tee -a ${FSMNT}/.tar-extract.log if [ $? -ne 0 ] then cd / echo "TAR failure occurred:" >>${LOGOUT} cat ${FSMNT}/.tar-extract.log | grep "tar:" >>${LOGOUT} umount ${FSMNT}.uzip mdconfig -d -u ${MDDEVICE} exit_err "ERROR: Failed extracting the tar image" fi # All finished, now lets umount and cleanup cd / umount ${FSMNT}.uzip mdconfig -d -u ${MDDEVICE} ;; tar) tar -xpv -C ${FSMNT} -f ${INSFILE} ${TAROPTS} >&1 2>&1 if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting the tar image" fi ;; esac # Check if this was a FTP download and clean it up now if [ "${INSTALLMEDIUM}" = "ftp" ] then echo_log "Cleaning up downloaded archive" rm ${INSFILE} rm ${INSFILE}.count >/dev/null 2>/dev/null rm ${INSFILE}.md5 >/dev/null 2>/dev/null fi echo_log "pc-sysinstall: Extraction Finished" }; # Performs the extraction of data to disk from a directory with split files start_extract_split() { if [ -z "${INSDIR}" ] then exit_err "ERROR: Called extraction with no install directory set!" fi echo_log "pc-sysinstall: Starting Extraction" # Used by install.sh DESTDIR="${FSMNT}" export DESTDIR HERE=`pwd` DIRS=`ls -d ${INSDIR}/*|grep -Ev '(uzip|kernels|src)'` for dir in ${DIRS} do cd "${dir}" if [ -f "install.sh" ] then echo_log "Extracting" `basename ${dir}` echo "y" | sh install.sh >/dev/null if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting ${dir}" fi else exit_err "ERROR: ${dir}/install.sh does not exist" fi done cd "${HERE}" KERNELS=`ls -d ${INSDIR}/*|grep kernels` cd "${KERNELS}" if [ -f "install.sh" ] then echo_log "Extracting" `basename ${KERNELS}` echo "y" | sh install.sh generic >/dev/null if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting ${KERNELS}" fi rm -rf "${FSMNT}/boot/kernel" mv "${FSMNT}/boot/GENERIC" "${FSMNT}/boot/kernel" else exit_err "ERROR: ${KERNELS}/install.sh does not exist" fi cd "${HERE}" SOURCE=`ls -d ${INSDIR}/*|grep src` cd "${SOURCE}" if [ -f "install.sh" ] then echo_log "Extracting" `basename ${SOURCE}` echo "y" | sh install.sh all >/dev/null if [ $? -ne 0 ] then exit_err "ERROR: Failed extracting ${SOURCE}" fi else exit_err "ERROR: ${SOURCE}/install.sh does not exist" fi cd "${HERE}" echo_log "pc-sysinstall: Extraction Finished" }; # Function which will attempt to fetch the install file before we start # the install fetch_install_file() { get_value_from_cfg ftpPath if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" fi FTPPATH="${VAL}" # Check if we have a /usr partition to save the download if [ -d "${FSMNT}/usr" ] then OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}" else OUTFILE="${FSMNT}/.fetch-${INSFILE}" fi # Do the fetch of the archive now fetch_file "${FTPPATH}/${INSFILE}" "${OUTFILE}" "1" # Check to see if there is a .count file for this install fetch_file "${FTPPATH}/${INSFILE}.count" "${OUTFILE}.count" "0" # Check to see if there is a .md5 file for this install fetch_file "${FTPPATH}/${INSFILE}.md5" "${OUTFILE}.md5" "0" # Done fetching, now reset the INSFILE to our downloaded archived export INSFILE="${OUTFILE}" }; # Function which will download freebsd install files fetch_split_files() { get_ftpHost if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" fi FTPHOST="${VAL}" get_ftpDir if [ -z "$VAL" ] then exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" fi FTPDIR="${VAL}" # Check if we have a /usr partition to save the download if [ -d "${FSMNT}/usr" ] then OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}" else OUTFILE="${FSMNT}/.fetch-${INSFILE}" fi DIRS="base catpages dict doc games info manpages proflibs kernels src" if [ "${FBSD_ARCH}" = "amd64" ] then DIRS="${DIRS} lib32" fi for d in ${DIRS} do mkdir -p "${OUTFILE}/${d}" done NETRC="${OUTFILE}/.netrc" cat <"${NETRC}" machine ${FTPHOST} login anonymous password anonymous macdef INSTALL bin prompt EOF for d in ${DIRS} do cat <>"${NETRC}" cd ${FTPDIR}/${d} lcd ${OUTFILE}/${d} mreget * EOF done cat <>"${NETRC}" bye EOF # Fetch the files via ftp echo "$ INSTALL" | ftp -N "${NETRC}" "${FTPHOST}" # Done fetching, now reset the INSFILE to our downloaded archived export INSFILE="${OUTFILE}" } # Function which does the rsync download from the server specified in cfg start_rsync_copy() { # Load our rsync config values get_value_from_cfg rsyncPath if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncPath is unset! Please check your config and try again." fi export RSYNCPATH="${VAL}" get_value_from_cfg rsyncHost if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncHost is unset! Please check your config and try again." fi export RSYNCHOST="${VAL}" get_value_from_cfg rsyncUser if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncUser is unset! Please check your config and try again." fi export RSYNCUSER="${VAL}" get_value_from_cfg rsyncPort if [ -z "${VAL}" ]; then exit_err "ERROR: rsyncPort is unset! Please check your config and try again." fi export RSYNCPORT="${VAL}" COUNT=1 while z=1 do if [ ${COUNT} -gt ${RSYNCTRIES} ] then exit_err "ERROR: Failed rsync command!" break fi rsync -avvzHsR \ --rsync-path="rsync --fake-super" \ -e "ssh -p ${RSYNCPORT}" \ ${RSYNCUSER}@${RSYNCHOST}:${RSYNCPATH}/./ ${FSMNT} if [ $? -ne 0 ] then echo "Rsync failed! Tries: ${COUNT}" else break fi COUNT=$((COUNT+1)) done }; start_image_install() { if [ -z "${IMAGE_FILE}" ] then exit_err "ERROR: installMedium set to image but no image file specified!" fi # We are ready to start mounting, lets read the config and do it while read line do echo $line | grep -q "^disk0=" 2>/dev/null if [ $? -eq 0 ] then # Found a disk= entry, lets get the disk we are working on get_value_from_string "${line}" strip_white_space "$VAL" DISK="$VAL" fi echo $line | grep -q "^commitDiskPart" 2>/dev/null if [ $? -eq 0 ] then # Found our flag to commit this disk setup / lets do sanity check and do it if [ -n "${DISK}" ] then # Write the image write_image "${IMAGE_FILE}" "${DISK}" # Increment our disk counter to look for next disk and unset unset DISK break else exit_err "ERROR: commitDiskPart was called without procceding disk= and partition= entries!!!" fi fi done <${CFGF} }; # Entrance function, which starts the installation process init_extraction() { # Figure out what file we are using to install from via the config get_value_from_cfg installFile if [ -n "${VAL}" ] then export INSFILE="${VAL}" else # If no installFile specified, try our defaults if [ "$INSTALLTYPE" = "FreeBSD" ] then case $PACKAGETYPE in uzip) INSFILE="${FBSD_UZIP_FILE}" ;; tar) INSFILE="${FBSD_TAR_FILE}" ;; split) INSDIR="${FBSD_BRANCH_DIR}" # This is to trick opt_mount into not failing INSFILE="${INSDIR}" ;; esac else case $PACKAGETYPE in uzip) INSFILE="${UZIP_FILE}" ;; tar) INSFILE="${TAR_FILE}" ;; esac fi export INSFILE fi # Lets start by figuring out what medium we are using case ${INSTALLMEDIUM} in dvd|usb) # Lets start by mounting the disk opt_mount if [ -n "${INSDIR}" ] then INSDIR="${CDMNT}/${INSDIR}" ; export INSDIR start_extract_split else INSFILE="${CDMNT}/${INSFILE}" ; export INSFILE start_extract_uzip_tar fi ;; ftp) if [ "$PACKAGETYPE" = "split" ] then fetch_split_files INSDIR="${INSFILE}" ; export INSDIR start_extract_split else fetch_install_file start_extract_uzip_tar fi ;; sftp) ;; rsync) start_rsync_copy ;; image) start_image_install ;; + local) + get_value_from_cfg localPath + if [ -z "$VAL" ] + then + exit_err "Install medium was set to local, but no localPath was provided!" + fi + LOCALPATH=$VAL + INSFILE="${LOCALPATH}/${INSFILE}" ; export INSFILE + start_extract_uzip_tar + ;; *) exit_err "ERROR: Unknown install medium" ;; esac }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-localize.sh b/usr.sbin/pc-sysinstall/backend/functions-localize.sh index 38cda791c2c6..7ee898cb3f1b 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-localize.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-localize.sh @@ -1,540 +1,540 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Functions which runs commands on the system . ${BACKEND}/functions.sh . ${BACKEND}/functions-parse.sh # Function which localizes a FreeBSD install localize_freebsd() { sed -i.bak "s/lang=en_US/lang=${LOCALE}/g" ${FSMNT}/etc/login.conf rm ${FSMNT}/etc/login.conf.bak }; localize_x_desktops() { # Check for and customize KDE lang ########################################################################## # Check if we can localize KDE via skel if [ -e "${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals" ] ; then sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals sed -i '' "s/Country=us/Country=${COUNTRY}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/usr/share/skel/.kde4/share/config/kdeglobals fi # Check if we have a KDE root config if [ -e "${FSMNT}/root/.kde4/share/config/kdeglobals" ] ; then sed -i '' "s/Language=en_US/Language=${SETLANG}:${LOCALE}/g" ${FSMNT}/root/.kde4/share/config/kdeglobals fi # Check for KDM if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc" ] ; then sed -i '' "s/Language=en_US/Language=${LOCALE}.UTF-8/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc fi # Check for and customize GNOME / GDM lang ########################################################################## # See if GDM is enabled and customize its lang cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q "gdm_enable=\"YES\"" 2>/dev/null if [ "$?" = "0" ] ; then echo "gdm_lang=\"${LOCALE}.UTF-8\"" >> ${FSMNT}/etc/rc.conf fi }; # Function which localizes a PC-BSD install localize_pcbsd() { # Check if we have a localized splash screen and copy it if [ -e "${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx" ] then cp ${FSMNT}/usr/local/share/pcbsd/splash-screens/loading-screen-${SETLANG}.pcx ${FSMNT}/boot/loading-screen.pcx fi }; localize_x_keyboard() { KEYMOD="$1" KEYLAY="$2" KEYVAR="$3" COUNTRY="$4" OPTION="grp:alt_shift_toggle" SETXKBMAP="" if [ "${COUNTRY}" = "NONE" -o "${COUNTRY}" = "us" -o "${COUNTRY}" = "C" ] ; then #In this case we don't need any additional language COUNTRY="" OPTION="" else COUNTRY=",${COUNTRY}" fi if [ "${KEYMOD}" != "NONE" ] then SETXKBMAP="-model ${KEYMOD}" KXMODEL="${KEYMOD}" else KXMODEL="pc104" fi if [ "${KEYLAY}" != "NONE" ] then localize_key_layout "$KEYLAY" SETXKBMAP="${SETXKBMAP} -layout ${KEYLAY}" KXLAYOUT="${KEYLAY}" else KXLAYOUT="us" fi if [ "${KEYVAR}" != "NONE" ] then SETXKBMAP="${SETXKBMAP} -variant ${KEYVAR}" KXVAR="(${KEYVAR})" else KXVAR="" fi # Setup .xprofile with our setxkbmap call now if [ ! -z "${SETXKBMAP}" ] then if [ ! -e "${FSMNT}/usr/share/skel/.xprofile" ] then echo "#!/bin/sh" >${FSMNT}/usr/share/skel/.xprofile fi # Save the keyboard layout for user / root X logins echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/share/skel/.xprofile chmod 755 ${FSMNT}/usr/share/skel/.xprofile cp ${FSMNT}/usr/share/skel/.xprofile ${FSMNT}/root/.xprofile # Save it for KDM if [ -e "${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup" ] ; then echo "setxkbmap ${SETXKBMAP}" >>${FSMNT}/usr/local/kde4/share/config/kdm/Xsetup fi fi # Create the kxkbrc configuration using these options if [ -d "${FSMNT}/usr/share/skel/.kde4/share/config" ] ; then echo "[Layout] DisplayNames=${KXLAYOUT}${COUNTRY} IndicatorOnly=false LayoutList=${KXLAYOUT}${KXVAR}${COUNTRY} Model=${KXMODEL} Options=${OPTION} ResetOldOptions=true ShowFlag=true ShowSingle=false SwitchMode=WinClass Use=true " >${FSMNT}/usr/share/skel/.kde4/share/config/kxkbrc fi }; localize_key_layout() { KEYLAYOUT="$1" # Set the keylayout in rc.conf case ${KEYLAYOUT} in am) KEYLAYOUT_CONSOLE="hy.armscii-8" ;; ch) KEYLAYOUT_CONSOLE="swissgerman.iso" ;; cz) KEYLAYOUT_CONSOLE="cz.iso2" ;; de) KEYLAYOUT_CONSOLE="german.iso" ;; dk) KEYLAYOUT_CONSOLE="danish.iso" ;; ee) KEYLAYOUT_CONSOLE="estonian.iso" ;; es) KEYLAYOUT_CONSOLE="spanish.iso" ;; fi) KEYLAYOUT_CONSOLE="finnish.iso" ;; is) KEYLAYOUT_CONSOLE="icelandic.iso" ;; jp) KEYLAYOUT_CONSOLE="jp.106" ;; nl) KEYLAYOUT_CONSOLE="dutch.iso.acc" ;; no) KEYLAYOUT_CONSOLE="norwegian.iso" ;; pl) KEYLAYOUT_CONSOLE="pl_PL.ISO8859-2" ;; ru) KEYLAYOUT_CONSOLE="ru.koi8-r" ;; sk) KEYLAYOUT_CONSOLE="sk.iso2" ;; se) KEYLAYOUT_CONSOLE="swedish.iso" ;; tr) KEYLAYOUT_CONSOLE="tr.iso9.q" ;; gb) KEYLAYOUT_CONSOLE="uk.iso" ;; *) if [ ! -z "${KEYLAYOUT}" ] then KEYLAYOUT_CONSOLE="${KEYLAYOUT}.iso" fi ;; esac if [ -n "${KEYLAYOUT_CONSOLE}" ] then echo "keymap=\"${KEYLAYOUT_CONSOLE}\"" >>${FSMNT}/etc/rc.conf fi }; # Function which prunes other l10n files from the KDE install localize_prune_langs() { get_value_from_cfg localizeLang KEEPLANG="$VAL" if [ -z "$KEEPLANG" ] ; then KEEPLANG="en" fi export KEEPLANG echo_log "Pruning other l10n files, keeping ${KEEPLANG}" # Create the script to do uninstalls echo '#!/bin/sh for i in `pkg_info -xEI kde-l10n` do echo "$i" | grep "${KEEPLANG}-kde" if [ $? -ne 0 ] ; then pkg_delete ${i} fi done ' > ${FSMNT}/.pruneLangs.sh chmod 755 ${FSMNT}/.pruneLangs.sh chroot ${FSMNT} /.pruneLangs.sh >/dev/null 2>/dev/null rm ${FSMNT}/.pruneLangs.sh }; # Function which sets COUNTRY SETLANG and LOCALE based upon $1 localize_get_codes() { TARGETLANG="${1}" # Setup the presets for the specific lang case $TARGETLANG in af) COUNTRY="C" SETLANG="af" LOCALE="af_ZA" ;; ar) COUNTRY="C" SETLANG="ar" LOCALE="en_US" ;; az) COUNTRY="C" SETLANG="az" LOCALE="en_US" ;; ca) COUNTRY="es" SETLANG="es:ca" LOCALE="ca_ES" ;; be) COUNTRY="be" SETLANG="be" LOCALE="be_BY" ;; bn) COUNTRY="bn" SETLANG="bn" LOCALE="en_US" ;; bg) COUNTRY="bg" SETLANG="bg" LOCALE="bg_BG" ;; cs) COUNTRY="cz" SETLANG="cs" LOCALE="cs_CZ" ;; da) COUNTRY="dk" SETLANG="da" LOCALE="da_DK" ;; de) COUNTRY="de" SETLANG="de" LOCALE="de_DE" ;; en_GB) COUNTRY="gb" SETLANG="en_GB:cy" LOCALE="en_GB" ;; el) COUNTRY="gr" SETLANG="el:gr" LOCALE="el_GR" ;; es) COUNTRY="es" SETLANG="es" LOCALE="es_ES" ;; es_LA) COUNTRY="us" SETLANG="es:en_US" LOCALE="es_ES" ;; et) COUNTRY="ee" SETLANG="et" LOCALE="et_EE" ;; fr) COUNTRY="fr" SETLANG="fr" LOCALE="fr_FR" ;; he) COUNTRY="il" SETLANG="he:ar" LOCALE="he_IL" ;; hr) COUNTRY="hr" SETLANG="hr" LOCALE="hr_HR" ;; hu) COUNTRY="hu" SETLANG="hu" LOCALE="hu_HU" ;; it) COUNTRY="it" SETLANG="it" LOCALE="it_IT" ;; ja) COUNTRY="jp" SETLANG="ja" LOCALE="ja_JP" ;; ko) COUNTRY="kr" SETLANG="ko" LOCALE="ko_KR" ;; nl) COUNTRY="nl" SETLANG="nl" LOCALE="nl_NL" ;; nn) COUNTRY="no" SETLANG="nn" LOCALE="en_US" ;; pa) COUNTRY="pa" SETLANG="pa" LOCALE="en_US" ;; pl) COUNTRY="pl" SETLANG="pl" LOCALE="pl_PL" ;; pt) COUNTRY="pt" SETLANG="pt" LOCALE="pt_PT" ;; pt_BR) COUNTRY="br" SETLANG="pt_BR" LOCALE="pt_BR" ;; ru) COUNTRY="ru" SETLANG="ru" LOCALE="ru_RU" ;; sl) COUNTRY="si" SETLANG="sl" LOCALE="sl_SI" ;; sk) COUNTRY="sk" SETLANG="sk" LOCALE="sk_SK" ;; sv) COUNTRY="se" SETLANG="sv" LOCALE="sv_SE" ;; uk) COUNTRY="ua" SETLANG="uk" LOCALE="uk_UA" ;; vi) COUNTRY="vn" SETLANG="vi" LOCALE="en_US" ;; zh_CN) COUNTRY="cn" SETLANG="zh_CN" LOCALE="zh_CN" ;; zh_TW) COUNTRY="tw" SETLANG="zh_TW" LOCALE="zh_TW" ;; *) COUNTRY="C" SETLANG="${TARGETLANG}" LOCALE="en_US" ;; esac export COUNTRY SETLANG LOCALE }; # Function which sets the timezone on the system set_timezone() { TZONE="$1" cp ${FSMNT}/usr/share/zoneinfo/${TZONE} ${FSMNT}/etc/localtime }; # Function which enables / disables NTP set_ntp() { ENABLED="$1" if [ "$ENABLED" = "yes" -o "${ENABLED}" = "YES" ] then cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null if [ $? -ne 0 ] then echo 'ntpd_enable="YES"' >>${FSMNT}/etc/rc.conf echo 'ntpd_sync_on_start="YES"' >>${FSMNT}/etc/rc.conf fi else cat ${FSMNT}/etc/rc.conf 2>/dev/null | grep -q 'ntpd_enable="YES"' 2>/dev/null if [ $? -ne 0 ] then sed -i.bak 's|ntpd_enable="YES"||g' ${FSMNT}/etc/rc.conf fi fi }; # Starts checking for localization directives run_localize() { KEYLAYOUT="NONE" KEYMOD="NONE" KEYVAR="NONE" while read line do # Check if we need to do any localization echo $line | grep -q "^localizeLang=" 2>/dev/null if [ $? -eq 0 ] then # Set our country / lang / locale variables get_value_from_string "$line" localize_get_codes ${VAL} get_value_from_string "$line" # If we are doing PC-BSD install, localize it as well as FreeBSD base if [ "${INSTALLTYPE}" != "FreeBSD" ] then localize_pcbsd "$VAL" fi # Localize FreeBSD localize_freebsd "$VAL" # Localize any X pkgs localize_x_desktops "$VAL" fi # Check if we need to do any keylayouts echo $line | grep -q "^localizeKeyLayout=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" KEYLAYOUT="$VAL" fi # Check if we need to do any key models echo $line | grep -q "^localizeKeyModel=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" KEYMOD="$VAL" fi # Check if we need to do any key variant echo $line | grep -q "^localizeKeyVariant=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" KEYVAR="$VAL" fi # Check if we need to set a timezone - echo $line | -q grep "^timeZone=" 2>/dev/null + echo $line | grep -q "^timeZone=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" set_timezone "$VAL" fi # Check if we need to set a timezone echo $line | grep -q "^enableNTP=" 2>/dev/null if [ $? -eq 0 ] ; then get_value_from_string "$line" set_ntp "$VAL" fi done <${CFGF} if [ "${INSTALLTYPE}" != "FreeBSD" ] ; then # Do our X keyboard localization localize_x_keyboard "${KEYMOD}" "${KEYLAYOUT}" "${KEYVAR}" "${COUNTRY}" fi # Check if we want to prunt any other KDE lang files to save some disk space get_value_from_cfg localizePrune if [ "${VAL}" = "yes" -o "${VAL}" = "YES" ] ; then localize_prune_langs fi # Update the login.conf db, even if we didn't localize, its a good idea to make sure its up2date run_chroot_cmd "/usr/bin/cap_mkdb /etc/login.conf" >/dev/null 2>/dev/null }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-newfs.sh b/usr.sbin/pc-sysinstall/backend/functions-newfs.sh index 96ca49b900ed..d5edff10e3a0 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-newfs.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-newfs.sh @@ -1,228 +1,228 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Functions related to disk operations using newfs # Function which performs the ZFS magic setup_zfs_filesystem() { PART="$1" PARTFS="$2" PARTMNT="$3" EXT="$4" PARTGEOM="$5" ZPOOLOPTS="$6" ROOTSLICE="`echo ${PART} | rev | cut -b 2- | rev`" ZPOOLNAME=$(get_zpool_name "${PART}") # Sleep a few moments, let the disk catch its breath sleep 5 sync # Check if we have some custom zpool arguments and use them if so if [ ! -z "${ZPOOLOPTS}" ] ; then rc_halt "zpool create -m none -f ${ZPOOLNAME} ${ZPOOLOPTS}" else # No zpool options, create pool on single device rc_halt "zpool create -m none -f ${ZPOOLNAME} ${PART}${EXT}" fi # Disable atime for this zfs partition, speed increase rc_nohalt "zfs set atime=off ${ZPOOLNAME}" # Check if we have multiple zfs mounts specified for i in `echo ${PARTMNT} | sed 's|,| |g'` do # Check if we ended up with needing a zfs bootable partition if [ "${i}" = "/" -o "${i}" = "/boot" ] then if [ "$HAVEBOOT" = "YES" ] ; then continue ; fi if [ "${PARTGEOM}" = "MBR" ] then # Lets stamp the proper ZFS boot loader echo_log "Setting up ZFS boot loader support" rc_halt "zpool set bootfs=${ZPOOLNAME} ${ZPOOLNAME}" rc_halt "zpool export ${ZPOOLNAME}" rc_halt "dd if=/boot/zfsboot of=${ROOTSLICE} count=1" rc_halt "dd if=/boot/zfsboot of=${PART}${EXT} skip=1 seek=1024" rc_halt "zpool import ${ZPOOLNAME}" fi fi done }; # Runs newfs on all the partiions which we've setup with bsdlabel setup_filesystems() { # Create the keydir rm -rf ${GELIKEYDIR} >/dev/null 2>/dev/null mkdir ${GELIKEYDIR} # Lets go ahead and read through the saved partitions we created, and determine if we need to run # newfs on any of them for PART in `ls ${PARTDIR}` do PARTDEV="`echo $PART | sed 's|-|/|g'`" if [ ! -e "${PARTDEV}" ] then exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?" fi PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d ':' -f 4`" PARTGEOM="`cat ${PARTDIR}/${PART} | cut -d ':' -f 5`" PARTXTRAOPTS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 6`" PARTIMAGE="`cat ${PARTDIR}/${PART} | cut -d ':' -f 7`" # Make sure journaling isn't enabled on this device if [ -e "${PARTDEV}.journal" ] then rc_nohalt "gjournal stop -f ${PARTDEV}.journal" rc_nohalt "gjournal clear ${PARTDEV}" fi # Setup encryption if necessary if [ "${PARTENC}" = "ON" -a "${PARTFS}" != "SWAP" ] then echo_log "Creating geli provider for ${PARTDEV}" if [ -e "${PARTDIR}-enc/${PART}-encpass" ] ; then # Using a passphrase rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1" rc_halt "geli init -J ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}" rc_halt "geli attach -j ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}" else # No Encryption password, use key file rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1" rc_halt "geli init -b -s 4096 -P -K ${GELIKEYDIR}/${PART}.key ${PARTDEV}" rc_halt "geli attach -p -k ${GELIKEYDIR}/${PART}.key ${PARTDEV}" fi EXT=".eli" else # No Encryption EXT="" fi case ${PARTFS} in UFS) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 - rc_halt "newfs ${PARTDEV}${EXT}" + rc_halt "newfs ${PARTXTRAOPTS} ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; UFS+S) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 - rc_halt "newfs -U ${PARTDEV}${EXT}" + rc_halt "newfs ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; UFS+SUJ) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 - rc_halt "newfs -U ${PARTDEV}${EXT}" + rc_halt "newfs ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "tunefs -j enable ${PARTDEV}${EXT}" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; UFS+J) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" sleep 2 rc_halt "newfs ${PARTDEV}${EXT}" sleep 2 rc_halt "gjournal label -f ${PARTDEV}${EXT}" sleep 2 - rc_halt "newfs -O 2 -J ${PARTDEV}${EXT}.journal" + rc_halt "newfs ${PARTXTRAOPTS} -O 2 -J ${PARTDEV}${EXT}.journal" sleep 2 rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" rc_halt "sync" # Set flag that we've found a boot partition if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then HAVEBOOT="YES" fi sleep 2 ;; ZFS) echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" setup_zfs_filesystem "${PARTDEV}" "${PARTFS}" "${PARTMNT}" "${EXT}" "${PARTGEOM}" "${PARTXTRAOPTS}" ;; SWAP) rc_halt "sync" rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" rc_halt "sync" sleep 2 ;; IMAGE) write_image "${PARTIMAGE}" "${PARTDEV}" sleep 2 ;; *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac done }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-parse.sh b/usr.sbin/pc-sysinstall/backend/functions-parse.sh index 4f96ca338d95..8b9d4180f61b 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-parse.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-parse.sh @@ -1,229 +1,229 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # functions.sh # Library of functions which pc-sysinstall may call upon for parsing the config # which gets the value of a setting in the provided line get_value_from_string() { if [ -n "${1}" ] then - export VAL="`echo ${1} | cut -d '=' -f 2`" + export VAL="`echo ${1} | cut -d '=' -f 2-15`" else echo "Error: Did we forgot to supply a string to parse?" exit 1 fi }; # Get the value from the cfg file including spaces get_value_from_cfg_with_spaces() { if [ -n "${1}" ] then - export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2` + export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2-15` else exit_err "Error: Did we forgot to supply a setting to grab?" fi }; # Get the value from the cfg file get_value_from_cfg() { if [ -n "${1}" ] then - export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` + export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2-15 | tr -d ' '` else exit_err "Error: Did we forgot to supply a setting to grab?" fi }; # Checks the value of a setting in the provided line with supplied possibilities # 1 = setting we are checking, 2 = list of valid values if_check_value_exists() { if [ -n "${1}" -a -n "${2}" ] then # Get the first occurance of the setting from the config, strip out whitespace VAL=`grep "^${1}" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` if [ -z "${VAL}" ] then # This value doesn't exist, lets return return 0 fi VALID="1" for i in ${2} do VAL=`echo "$VAL"|tr A-Z a-z` if [ "$VAL" = "${i}" ] then VALID="0" fi done if [ "$VALID" = "1" ] then exit_err "Error: ${1} is set to unknown value $VAL" fi else exit_err "Error: Did we forgot to supply a string to parse and setting to grab?" fi }; # Checks the value of a setting in the provided line with supplied possibilities # 1 = setting we are checking, 2 = list of valid values check_value() { if [ -n "${1}" -a -n "${2}" ] then # Get the first occurance of the setting from the config, strip out whitespace VAL=`grep "^${1}" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` VALID="1" for i in ${2} do if [ "$VAL" = "${i}" ] then VALID="0" fi done if [ "$VALID" = "1" ] then exit_err "Error: ${1} is set to unknown value $VAL" fi else exit_err "Error: Did we forgot to supply a string to parse and setting to grab?" fi }; # Checks for the presense of the supplied arguements in the config file # 1 = values to confirm exist file_sanity_check() { if [ -n "$CFGF" -a -n "$1" ] then for i in $1 do grep -q "^${i}=" $CFGF 2>/dev/null if [ $? -eq 0 ] then LN=`grep "^${i}=" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` if [ -z "${LN}" ] then echo "Error: Config fails sanity test! ${i}= is empty" exit 1 fi else echo "Error: Config fails sanity test! Missing ${i}=" exit 1 fi done else echo "Error: Missing config file, and / or values to sanity check for!" exit 1 fi }; # Function which merges the contents of a new config into the specified old one # Only works with = type configurations merge_config() { OLDCFG="${1}" NEWCFG="${2}" FINALCFG="${3}" # Copy our oldcfg to the new one, which will be used as basis cp ${OLDCFG} ${FINALCFG} # Remove blank lines from new file cat ${NEWCFG} | sed '/^$/d' > ${FINALCFG}.tmp # Set our marker if we've found any FOUNDMERGE="NO" while read newline do echo ${newline} | grep -q "^#" 2>/dev/null if [ $? -ne 0 ] ; then VAL="`echo ${newline} | cut -d '=' -f 1`" cat ${OLDCFG} | grep -q ${VAL} 2>/dev/null if [ $? -ne 0 ] ; then if [ "${FOUNDMERGE}" = "NO" ] ; then echo "" >> ${FINALCFG} echo "# Auto-merged values from newer ${NEWCFG}" >> ${FINALCFG} FOUNDMERGE="YES" fi echo "${newline}" >> ${FINALCFG} fi fi done < ${FINALCFG}.tmp rm ${FINALCFG}.tmp }; # Loop to check for a specified mount-point in a list check_for_mount() { MNTS="${1}" FINDMNT="${2}" # Check if we found a valid root partition for CHECKMNT in `echo ${MNTS} | sed 's|,| |g'` do if [ "${CHECKMNT}" = "${FINDMNT}" ] ; then return 0 fi done return 1 }; # Function which returns the next line in the specified config file get_next_cfg_line() { CURFILE="$1" CURLINE="$2" FOUND="1" while read line do if [ "$FOUND" = "0" ] ; then export VAL="$line" return fi if [ "$line" = "${CURLINE}" ] ; then FOUND="0" fi done <${CURFILE} # Got here, couldn't find this line or at end of file, set VAL to "" export VAL="" }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-unmount.sh b/usr.sbin/pc-sysinstall/backend/functions-unmount.sh index ce0db9b1f4e1..23630f7674a4 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-unmount.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-unmount.sh @@ -1,210 +1,210 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Functions which unmount all mounted disk filesystems # Unmount all mounted partitions under specified dir umount_all_dir() { _udir="$1" _umntdirs=`mount | sort -r | grep "on $_udir" | cut -d ' ' -f 3` for _ud in $_umntdirs do umount -f ${_ud} done } # Script that adds our gmirror devices for syncing start_gmirror_sync() { cd ${MIRRORCFGDIR} for DISK in `ls *` do MIRRORDISK="`cat ${DISK} | cut -d ':' -f 1`" MIRRORBAL="`cat ${DISK} | cut -d ':' -f 2`" MIRRORNAME="`cat ${DISK} | cut -d ':' -f 3`" # Start the mirroring service rc_nohalt "gmirror forget ${MIRRORNAME}" rc_halt "gmirror insert ${MIRRORNAME} /dev/${MIRRORDISK}" done }; # Unmounts all our mounted file-systems unmount_all_filesystems() { # Copy the logfile to disk before we unmount cp ${LOGOUT} ${FSMNT}/root/pc-sysinstall.log cd / # Start by unmounting any ZFS partitions zfs_cleanup_unmount # Lets read our partition list, and unmount each ################################################################## for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d ':' -f 4`" if [ "${PARTENC}" = "ON" ] then EXT=".eli" else EXT="" fi if [ "${PARTFS}" = "SWAP" ] then rc_nohalt "swapoff ${PARTDEV}${EXT}" fi # Check if we've found "/", and unmount that last if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] then rc_halt "umount -f ${PARTDEV}${EXT}" # Re-check if we are missing a label for this device and create it again if so if [ ! -e "/dev/label/${PARTLABEL}" ] then case ${PARTFS} in UFS) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;; UFS+S) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;; UFS+SUJ) glabel label ${PARTLABEL} ${PARTDEV}${EXT} ;; UFS+J) glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal ;; *) ;; esac fi fi # Check if we've found "/" and make sure the label exists if [ "$PARTMNT" = "/" -a "${PARTFS}" != "ZFS" ] then if [ ! -e "/dev/label/${PARTLABEL}" ] then case ${PARTFS} in UFS) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;; UFS+S) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;; UFS+SUJ) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}" ;; UFS+J) ROOTRELABEL="glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal" ;; *) ;; esac fi fi done # Last lets the /mnt partition ######################################################### rc_nohalt "umount -f ${FSMNT}" # If are using a ZFS on "/" set it to legacy if [ ! -z "${FOUNDZFSROOT}" ] then rc_halt "zfs set mountpoint=legacy ${FOUNDZFSROOT}" fi # If we need to relabel "/" do it now if [ ! -z "${ROOTRELABEL}" ] then ${ROOTRELABEL} fi # Unmount our CDMNT rc_nohalt "umount -f ${CDMNT}" >/dev/null 2>/dev/null # Check if we need to run any gmirror syncing ls ${MIRRORCFGDIR}/* >/dev/null 2>/dev/null if [ $? -eq 0 ] then # Lets start syncing now start_gmirror_sync fi }; # Unmounts any filesystems after a failure unmount_all_filesystems_failure() { cd / # if we did a fresh install, start unmounting if [ "${INSTALLMODE}" = "fresh" ] then # Lets read our partition list, and unmount each ################################################################## if [ -d "${PARTDIR}" ] then for PART in `ls ${PARTDIR}` do PARTDEV=`echo $PART | sed 's|-|/|g'` PARTFS="`cat ${PARTDIR}/${PART} | cut -d ':' -f 1`" PARTMNT="`cat ${PARTDIR}/${PART} | cut -d ':' -f 2`" PARTENC="`cat ${PARTDIR}/${PART} | cut -d ':' -f 3`" if [ "${PARTFS}" = "SWAP" ] then if [ "${PARTENC}" = "ON" ] then - rc_nohalt "swapoff ${PARTDEV}.eli" + swapoff ${PARTDEV}.eli >/dev/null 2>/dev/null else - rc_nohalt "swapoff ${PARTDEV}" + swapoff ${PARTDEV} >/dev/null 2>/dev/null fi fi # Check if we've found "/" again, don't need to mount it twice if [ "$PARTMNT" != "/" -a "${PARTMNT}" != "none" -a "${PARTFS}" != "ZFS" ] then - rc_nohalt "umount -f ${PARTDEV}" - rc_nohalt "umount -f ${FSMNT}${PARTMNT}" + umount -f ${PARTDEV} >/dev/null 2>/dev/null + umount -f ${FSMNT}${PARTMNT} >/dev/null 2>/dev/null fi done # Last lets the /mnt partition ######################################################### - rc_nohalt "umount -f ${FSMNT}" + umount -f ${FSMNT} >/dev/null 2>/dev/null fi else # We are doing a upgrade, try unmounting any of these filesystems - chroot ${FSMNT} /sbin/umount -a >>${LOGOUT} >>${LOGOUT} - umount -f ${FSMNT}/usr >>${LOGOUT} 2>>${LOGOUT} - umount -f ${FSMNT}/dev >>${LOGOUT} 2>>${LOGOUT} - umount -f ${FSMNT} >>${LOGOUT} 2>>${LOGOUT} - rc_nohalt "sh ${TMPDIR}/.upgrade-unmount" + chroot ${FSMNT} /sbin/umount -a >/dev/null 2>/dev/null + umount -f ${FSMNT}/usr >/dev/null 2>/dev/null + umount -f ${FSMNT}/dev >/dev/null 2>/dev/null + umount -f ${FSMNT} >/dev/null 2>/dev/null + sh ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null fi # Unmount our CDMNT - rc_nohalt "umount ${CDMNT}" + umount ${CDMNT} >/dev/null 2>/dev/null }; diff --git a/usr.sbin/pc-sysinstall/backend/functions.sh b/usr.sbin/pc-sysinstall/backend/functions.sh index 4987bf45c7f3..9a98ee2bf144 100755 --- a/usr.sbin/pc-sysinstall/backend/functions.sh +++ b/usr.sbin/pc-sysinstall/backend/functions.sh @@ -1,531 +1,531 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # functions.sh # Library of functions which pc-sysinstall may call upon # Function which displays the help-index file display_help() { if [ -e "${PROGDIR}/doc/help-index" ] then cat ${PROGDIR}/doc/help-index else echo "Error: ${PROGDIR}/doc/help-index not found" exit 1 fi }; # Function which displays the help for a specified command display_command_help() { if [ -z "$1" ] then echo "Error: No command specified to display help for" exit 1 fi if [ -e "${PROGDIR}/doc/help-${1}" ] then cat ${PROGDIR}/doc/help-${1} else echo "Error: ${PROGDIR}/doc/help-${1} not found" exit 1 fi }; # Function to convert bytes to megabytes convert_byte_to_megabyte() { if [ -z "${1}" ] then echo "Error: No bytes specified!" exit 1 fi expr -e ${1} / 1048576 }; # Function to convert blocks to megabytes convert_blocks_to_megabyte() { if [ -z "${1}" ] ; then echo "Error: No blocks specified!" exit 1 fi expr -e ${1} / 2048 }; # Takes $1 and strips the whitespace out of it, returns VAL strip_white_space() { if [ -z "${1}" ] then echo "Error: No value setup to strip whitespace from!" exit 1 fi export VAL=`echo "$1" | tr -d ' '` }; # Displays an error message and exits with error 1 exit_err() { # Echo the message for the users benefit - echo "$1" + echo "EXITERROR: $1" # Save this error to the log file - echo "${1}" >>$LOGOUT + echo "EXITERROR: ${1}" >>$LOGOUT # Check if we need to unmount any file-systems after this failure unmount_all_filesystems_failure echo "For more details see log file: $LOGOUT" exit 1 }; # Run-command, don't halt if command exits with non-0 rc_nohalt() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_nohalt()" fi echo "Running: ${CMD}" >>${LOGOUT} ${CMD} >>${LOGOUT} 2>>${LOGOUT} }; # Run-command, halt if command exits with non-0 rc_halt() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_halt()" fi echo "Running: ${CMD}" >>${LOGOUT} eval ${CMD} >>${LOGOUT} 2>>${LOGOUT} STATUS="$?" if [ "${STATUS}" != "0" ] then exit_err "Error ${STATUS}: ${CMD}" fi }; # Run-command w/echo to screen, halt if command exits with non-0 rc_halt_echo() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_halt_echo()" fi echo "Running: ${CMD}" >>${LOGOUT} ${CMD} 2>&1 | tee -a ${LOGOUT} STATUS="$?" if [ "$STATUS" != "0" ] then exit_err "Error ${STATUS}: $CMD" fi }; # Run-command w/echo, don't halt if command exits with non-0 rc_nohalt_echo() { CMD="$1" if [ -z "${CMD}" ] then exit_err "Error: missing argument in rc_nohalt_echo()" fi echo "Running: ${CMD}" >>${LOGOUT} ${CMD} 2>&1 | tee -a ${LOGOUT} }; # Echo to the screen and to the log echo_log() { STR="$1" if [ -z "${STR}" ] then exit_err "Error: missing argument in echo_log()" fi echo "${STR}" | tee -a ${LOGOUT} }; # Make sure we have a numeric is_num() { expr $1 + 1 2>/dev/null return $? } # Function which uses "fetch" to download a file, and display a progress report fetch_file() { FETCHFILE="$1" FETCHOUTFILE="$2" EXITFAILED="$3" SIZEFILE="${TMPDIR}/.fetchSize" EXITFILE="${TMPDIR}/.fetchExit" rm ${SIZEFILE} 2>/dev/null >/dev/null rm ${FETCHOUTFILE} 2>/dev/null >/dev/null fetch -s "${FETCHFILE}" >${SIZEFILE} SIZE="`cat ${SIZEFILE}`" SIZE="`expr ${SIZE} / 1024`" echo "FETCH: ${FETCHFILE}" echo "FETCH: ${FETCHOUTFILE}" >>${LOGOUT} ( fetch -o ${FETCHOUTFILE} "${FETCHFILE}" >/dev/null 2>/dev/null ; echo "$?" > ${EXITFILE} ) & PID="$!" while z=1 do if [ -e "${FETCHOUTFILE}" ] then DSIZE=`du -k ${FETCHOUTFILE} | tr -d '\t' | cut -d '/' -f 1` if [ $(is_num "$DSIZE") ] ; then if [ $SIZE -lt $DSIZE ] ; then DSIZE="$SIZE"; fi echo "SIZE: ${SIZE} DOWNLOADED: ${DSIZE}" echo "SIZE: ${SIZE} DOWNLOADED: ${DSIZE}" >>${LOGOUT} fi fi # Check if the download is finished ps -p ${PID} >/dev/null 2>/dev/null if [ $? -ne 0 ] then break; fi sleep 2 done echo "FETCHDONE" EXIT="`cat ${EXITFILE}`" if [ "${EXIT}" != "0" -a "$EXITFAILED" = "1" ] then exit_err "Error: Failed to download ${FETCHFILE}" fi return $EXIT }; # Function to return a the zpool name for this device get_zpool_name() { DEVICE="$1" # Set the base name we use for zpools BASENAME="tank" if [ ! -d "${TMPDIR}/.zpools" ] ; then mkdir -p ${TMPDIR}/.zpools fi if [ -e "${TMPDIR}/.zpools/${DEVICE}" ] ; then cat ${TMPDIR}/.zpools/${DEVICE} return 0 else # Need to generate a zpool name for this device NUM=`ls ${TMPDIR}/.zpools/ | wc -l | sed 's| ||g'` NEWNAME="${BASENAME}${NUM}" mkdir -p ${TMPDIR}/.zpools/`dirname $DEVICE` echo "$NEWNAME" >${TMPDIR}/.zpools/${DEVICE} echo "${NEWNAME}" return fi }; iscompressed() { local FILE local RES FILE="$1" RES=1 if echo "${FILE}" | \ grep -qiE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' 2>&1 then RES=0 fi return ${RES} } get_compression_type() { local FILE local SUFFIX FILE="$1" SUFFIX=`echo "${FILE}" | sed -E 's|^(.+)\.(.+)$|\2|'` VAL="" SUFFIX=`echo "${SUFFIX}" | tr A-Z a-z` case "${SUFFIX}" in z) VAL="lzw" ;; lzo) VAL="lzo" ;; lzw) VAL="lzw" ;; lzma) VAL="lzma" ;; gz) VAL="gzip" ;; bz2) VAL="bzip2" ;; xz) VAL="xz" ;; zip) VAL="zip" ;; esac export VAL } write_image() { local DEVICE_FILE IMAGE_FILE="$1" DEVICE_FILE="$2" if [ -z "${IMAGE_FILE}" ] then exit_err "ERROR: Image file not specified!" fi if [ -z "${DEVICE_FILE}" ] then exit_err "ERROR: Device file not specified!" fi if [ ! -f "${IMAGE_FILE}" ] then exit_err "ERROR: '${IMAGE_FILE}' does not exist!" fi DEVICE_FILE="${DEVICE_FILE#/dev/}" DEVICE_FILE="/dev/${DEVICE_FILE}" if [ ! -c "${DEVICE_FILE}" ] then exit_err "ERROR: '${DEVICE_FILE}' is not a character device!" fi if iscompressed "${IMAGE_FILE}" then local COMPRESSION get_compression_type "${IMAGE_FILE}" COMPRESSION="${VAL}" case "${COMPRESSION}" in lzw) rc_halt "uncompress ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.Z}" ;; lzo) rc_halt "lzop -d $IMAGE_{FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.lzo}" ;; lzma) rc_halt "lzma -d ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.lzma}" ;; gzip) rc_halt "gunzip ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.gz}" ;; bzip2) rc_halt "bunzip2 ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.bz2}" ;; xz) rc_halt "xz -d ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.xz}" ;; zip) rc_halt "unzip ${IMAGE_FILE} -c | dd of=${DEVICE_FILE}" IMAGE_FILE="${IMAGE_FILE%.zip}" ;; *) exit_err "ERROR: ${COMPRESSION} compression is not supported" ;; esac else rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE}" fi }; # Setup and install on a new disk / partition install_fresh() { # Lets start setting up the disk slices now setup_disk_slice if [ -z "${ROOTIMAGE}" ] then # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels setup_disk_label # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs # to setup the filesystems setup_filesystems # Lets mount the partitions now mount_all_filesystems # We are ready to begin extraction, lets start now init_extraction # Check if we have any optional modules to load install_components # Check if we have any packages to install install_packages # Do any localization in configuration run_localize # Save any networking config on the installed system save_networking_install # Now add any users setup_users - # Now run any commands specified - run_commands - # Do any last cleanup / setup before unmounting run_final_cleanup + # Now run any commands specified + run_commands + # Unmount and finish up unmount_all_filesystems fi echo_log "Installation finished!" }; # Extract the system to a pre-mounted directory install_extractonly() { # We are ready to begin extraction, lets start now init_extraction # Check if we have any optional modules to load install_components # Check if we have any packages to install install_packages # Do any localization in configuration run_localize # Save any networking config on the installed system save_networking_install # Now add any users setup_users # Now run any commands specified run_commands # Set a hostname on the install system setup_hostname # Set the root_pw if it is specified set_root_pw echo_log "Installation finished!" }; install_image() { # We are ready to begin extraction, lets start now init_extraction echo_log "Installation finished!" }; install_upgrade() { # We're going to do an upgrade, skip all the disk setup # and start by mounting the target drive/slices mount_upgrade # Start the extraction process init_extraction # Do any localization in configuration run_localize # Now run any commands specified run_commands # Merge any old configuration files merge_old_configs # Check if we have any optional modules to load install_components # Check if we have any packages to install install_packages # All finished, unmount the file-systems unmount_upgrade echo_log "Upgrade finished!" }; diff --git a/usr.sbin/pc-sysinstall/backend/parseconfig.sh b/usr.sbin/pc-sysinstall/backend/parseconfig.sh index eeb6ce0049a7..2e16751bd626 100755 --- a/usr.sbin/pc-sysinstall/backend/parseconfig.sh +++ b/usr.sbin/pc-sysinstall/backend/parseconfig.sh @@ -1,129 +1,125 @@ #!/bin/sh #- # Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Main install configuration parsing script # # Source our functions scripts . ${BACKEND}/functions.sh . ${BACKEND}/functions-bsdlabel.sh . ${BACKEND}/functions-cleanup.sh . ${BACKEND}/functions-disk.sh . ${BACKEND}/functions-extractimage.sh . ${BACKEND}/functions-installcomponents.sh . ${BACKEND}/functions-installpackages.sh . ${BACKEND}/functions-localize.sh . ${BACKEND}/functions-mountdisk.sh . ${BACKEND}/functions-networking.sh . ${BACKEND}/functions-newfs.sh . ${BACKEND}/functions-packages.sh . ${BACKEND}/functions-parse.sh . ${BACKEND}/functions-runcommands.sh . ${BACKEND}/functions-ftp.sh . ${BACKEND}/functions-unmount.sh . ${BACKEND}/functions-upgrade.sh . ${BACKEND}/functions-users.sh # Check that the config file exists if [ ! -e "${1}" ] then echo "ERROR: Install configuration $1 does not exist!" exit 1 fi # Set our config file variable CFGF="$1" -# Check the dirname of the provided CFGF and make sure its a full path -DIR="`dirname ${CFGF}`" -if [ "${DIR}" = "." ] -then - CFGF="`pwd`/${CFGF}" -fi +# Resolve any relative pathing +CFGF="`realpath ${CFGF}`" export CFGF # Start by doing a sanity check, which will catch any obvious mistakes in the config file_sanity_check "installMode installType installMedium packageType" # We passed the Sanity check, lets grab some of the universal config settings and store them check_value installMode "fresh upgrade extract" check_value installType "PCBSD FreeBSD" -check_value installMedium "dvd usb ftp rsync image" +check_value installMedium "dvd usb ftp rsync image local" check_value packageType "uzip tar rsync split" if_check_value_exists partition "all s1 s2 s3 s4 free image" if_check_value_exists mirrorbal "load prefer round-robin split" # We passed all sanity checks! Yay, lets start the install echo "File Sanity Check -> OK" # Lets load the various universal settings now get_value_from_cfg installMode export INSTALLMODE="${VAL}" get_value_from_cfg installType export INSTALLTYPE="${VAL}" get_value_from_cfg installMedium export INSTALLMEDIUM="${VAL}" get_value_from_cfg packageType export PACKAGETYPE="${VAL}" # Check if we are doing any networking setup start_networking # If we are not doing an upgrade, lets go ahead and setup the disk case "${INSTALLMODE}" in fresh) if [ "${INSTALLMEDIUM}" = "image" ] then install_image else install_fresh fi ;; extract) # Extracting only, make sure we have a valid target directory get_value_from_cfg installLocation export FSMNT="${VAL}" if [ -z "$FSMNT" ] ; then exit_err "Missing installLocation=" ; fi if [ ! -d "$FSMNT" ] ; then exit_err "No such directory: $FSMNT" ; fi install_extractonly ;; upgrade) install_upgrade ;; *) exit 1 ;; esac exit 0 diff --git a/usr.sbin/pc-sysinstall/examples/README b/usr.sbin/pc-sysinstall/examples/README index 2eb1e6f2973f..cc269a229787 100644 --- a/usr.sbin/pc-sysinstall/examples/README +++ b/usr.sbin/pc-sysinstall/examples/README @@ -1,388 +1,394 @@ pc-sysinstall README This file documents many of the variables used in pc-sysinstall config scripts ################################################################# # hostname= Using hostname= will set the specified hostname on the installed system When hostname= is not present, pc-sysinstall will auto-generate a hostname such as freebsd-XXXX or pcbsd-XXXX # installMode=(fresh/upgrade/extract) Set the type of install we are doing. Fresh installs will format and mount the target disks before extracting the install images to the system. Using this mode it is also possible to do a system restore, by specifying a full system backup as the install source. Upgrades will mount the target disk, and extract the system archive to the disk, overwriting files on the disk. The conf/exclude-from-upgrade file can be used to specify additional files to exclude from overwriting during the install process. Extract will skip any disk setup, and perform an installation to the directory specified by "installLocation=". This location should be a directory with your pre-mounted file-systems ready for file extraction. When using the "extract" option, /etc/fstab on the installed system will *not* be automatically configured. # installLocation= Used only when installMode is set to extract. This is set to the location you want to extract your system to, and should already be mounted properly. # installInteractive=(yes or no) Set if the installer is running in interactive mode, and is able to prompt for input from the user, defaults to no ######################################################################## # NETWORK SETTINGS ######################################################################## # netDev=(AUTO-DHCP or ) netDev specifies what type of networking to enable for the installer Can be set to AUTO-DHCP or to a network interface, such as et0 When set to AUTO-DHCP, pc-sysinstall will probe for all network devices and attempt to set DHCP mode on each, until a working network connection is established If netDev= is set to a network interface such as et0, the following options will need to be set in order to enable the interface # netIP=(IP address such as 192.168.0.100) Set netIP to an address that you wish to have the interface specified in netDev set to Only used when netDev is not set to AUTO-DHCP # netMask=(Netmask such as 255.255.255.0) Set netMask to the address you with to have the interface specified in netDev set to Only used when netDev is not set to AUTO-DHCP # netNameServer=(DNS Server such as 192.168.0.1) Set netNameServer to the DNS address you want to use during the install Only used when netDev is not set to AUTO-DHCP # netDefaultRouter=(192.168.0.1) Set netDefaultRouter to the gateway you wish to have the installer use Only used when netDev is not set to AUTO-DHCP # netSaveDev=(AUTO-DHCP or network interface) netSaveDev specifies what networking to enable on the installed system When set to AUTO-DHCP, pc-sysinstall will probe all network interfaces, and set them all to DHCP in the systems /etc/rc.conf file. Wireless devices will also have the corresponding wlan[0-9] device created. When set to a network interface, pc-sysinstall will set the target device with the settings specified by the variables below. # netSaveIP=192.168.0.49 # netSaveMask=255.255.255.0 # netSaveNameServer=208.67.222.222 # netSaveDefaultRouter=192.168.0.1 ######################################################################## # DISK SLICE SETTINGS ######################################################################## The following section specifies the target disk(s) to be used in the install or upgrade. # disk0=(disk device, such as ad0) The diskX= variable should be set to the target device for this drive, such as ad0, da0 The first should begin with disk0=, and additional drives to disk1=, disk2 if additional disks are to be setup. When doing an upgrade, the disk0= line should be set to the root device or root zpool of the target system to update. I.E: # disk0=tank0 # disk0=ada0s1a # partition=(all, free, s1, s1, s3, s4, image) After setting disk[0-9], the partition= variable is used to specify which target partition we will be working with for this device. Setting this to "all" will setup the disk with a single FreeBSD slice as "s1" Setting this to "free" will allow pc-sysinstall to search for the first available primary slice with free space, and create the slice. Setting this to "s1, s2, s3 or s4" will use the specified MBR slice. Setting this to "image" will use an image to configure the disk. (This tag is unused for upgrades) # partscheme=(MBR/GPT) When performing a "full" disk (partition=all), the partscheme= variable is used to determine the partition scheme type gpart will be using on the disk. Valid choices are MBR or GPT. # mirror=(disk device such as ad1) Setting the mirror= variable will setup the target device as a gmirror of the diskX= device. The mirror device must be the same size or larger than the drive being mirrored. # mirrorbal=(load, prefer, round-robin, split) Allows the setting of the mirror balance method to be used, if not specified this defaults to "round-robin" # bootManager=(none, bsd) Setting this option will instruct pc-sysinstall to install the BSD boot Manager, or leave it empty # image=(/path/to/image/file) (/mountpoint) Setting this option will instruct pc-sysinstall to write the image file specified by the path to the disk. # commitDiskPart This command must be placed at the end of the diskX= section, before starting the listing of any additional diskX= directives. ######################################################################## # DISK PARTITION / MOUNT SETTINGS ######################################################################## The following settings specify the partitioning / mount points to setup on the target partition -# disk0-part=UFS+S 500 / +# disk0-part=UFS+S 500 / (-n -o time) # disk0-part=SWAP 2000 none # disk0-part=UFS.eli 500 /usr # encpass=mypass # disk0-part=UFS+J 500 /tmp # disk0-part=ZFS 0 /data,/storage (mirror: ad1) # commitDiskLabel The above values instructs pc-sysinstall which partitions / mounts to create on the target drive / slice, specified by "disk0". (disk0 will resolve to the drive / slice specified in the previous section) The notation is as follows: Available FileSystems: UFS - Standard UFS2 FileSystem UFS+S - UFS2 + Softupdates enabled UFS+SUJ - UFS2 + Soft Updates + Journaling enabled UFS+J - UFS2 + Journaling through gjournal ZFS - Z File System, pools / mounts created automatically SWAP - BSD Swap space partition, mountpoint should be set to "none" Adding the ".eli" extension to any of the above file systems will enable disk encryption via geli (UFS.eli, UFS+S.eli, UFS+SUJ.eli, UFS+J.eli, ZFS.eli, SWAP.eli) If you with to use a passphrase with this encrypted partition, on the next line the flag "encpass=" should be entered: encpass=mypass All sizes are expressed in MegaBytes Specifying a size 0 instructs pc-sysinstall to use the rest of the available slice size, and should only be used for the last partition / mount +When using "UFS" and its various types, it is possible to specify custom options +for newfs using (). For examplei: +disk0-part=UFS+SUJ 1000 / (-o time) +In this case "-o time" would be passed to newfs when creating the "/" filesystem. + + When using "ZFS" specifically, it is possible to specify additional disks / partitions to include in the zpool. By using the syntax: (mirror: ad1,ad2) or (raidz: ad1,ad2), it is possible to include the disk "ad1" into the zpool for this partition, using the raidz / mirror methods. If you with to just include the disk into the pool in "basic" mode, then use (ad1,ad2) with no flags ######################################################################## # INSTALL OPTIONS / SOURCES ######################################################################## The following settings specify the type, locations and sources for this installation # installMedium=(dvd, usb, ftp, rsync, image) Set installMedium= to the source type we will be using for this install. Available Types: dvd - Search for and mount the DVD which contains the install archive usb - Search for and mount the USB drive which contains the install archive ftp - The install archive will be fetched from a FTP / HTTP server before install rsync - Pull the system data from a ssh + rsync server, specified with variables below image - Install system from an image # installType=(PCBSD, FreeBSD) Set the type of system we are installing, PCBSD or FreeBSD # installFile=fbsd-release.tbz The installer archive, if not using the defaults specified in conf/pc-sysinstall.conf # packageType=(tar, uzip, split) The archive type we are extracting from when using dvd, usb or ftp # ftpPath=ftp://ftp.pcbsd.org/pub/8.0/netinstall Location of the installer archive when using a installMedium=ftp # rsyncPath=life-preserver/back-2009-11-12T14_53_14 The location of the rsync data on the remote server when using installMedium=rsync # rsyncUser=rsyncuser The username to use for the ssh server running rsync # rsyncHost=192.168.0.50 The rsync / ssh server we wish to connect to # rsyncPort=22 The port to use when connecting to a ssh + rsync server # installComponents=amarok,firefox,ports The specified components to install, view available with "./pc-sysinstall list-components" ######################################################################## # UPGRADE OPTIONS ######################################################################## Options specific to performing an upgrade # upgradeKeepDesktopProfile=(yes/no) This option allows you to specify if you wish to keep your existing users desktop profile data. The default is NO, and your existing profile will be moved to .kde4.preUpgrade automatically. ######################################################################## # USER OPTIONS ######################################################################## Options for setting up usernames and passwords on the installed system # rootPass=root Set the root password of the installed system to the specified plaintext string # rootEncPass= Set the root password of the installed system to the specified encrypted string The below variables are used to setup a user on the installed system Be sure to call commitUser after after adding these values, and before starting another user block # userName=kris # userComment=Kris Moore # userPass=mypass or # userEncPass= # userShell=/bin/csh # userHome=/home/kris # userGroups=wheel,operator # commitUser ######################################################################## # RUN COMMANDS ######################################################################## The following variables can be set to run commands post-installation, allowing the user to further tweak / modify the system # runCommand= Run the specified command within chroot of the installed system # runScript= runScript will copy the specified script into FSMNT, and run it in chroot of the system Useful when you have a 3rd party script on the DVD / USB, and you want to copy it into the installed system and run # runExtCommand= runExtCommand is used when you wish to run a command outside the chroot The variable $FSMNT is set to the mount-point of your installed system ######################################################################## # PC-BSD SPECIFIC OPTIONS ######################################################################## Options for time-zones and NTP on the installed system # timeZone= timeZone can be set to the zone file in /usr/share/zoneinfo/ that is to be used example: America/New_York # enableNTP= (yes / no) set enableNTP to yes or no to enable or disable the NTP service on the system ######################################################################## # PC-BSD SPECIFC OPTIONS ######################################################################## Options specific to installing PC-BSD, such as localization, and KDE settings # localizeLang=en localizeLang will set the system console and Desktop to the target language # localizeKeyLayout=en localizeKeyLayout updates the system's xorg config to set the keyboard layout # localizeKeyModel=pc104 localizeKeyModel updates the system's xorg config to set the keyboard model # localizeKeyVariant=intl localizeKeyVariant is used to update the xorg config to set the keyboard variant # autoLoginUser=kris Setting autoLoginUser will enable the specified user to log into the desktop automatically without entering a password $FreeBSD$