From 3373ecde5ca05e50431b3c471dc2273cd4aa0684 Mon Sep 17 00:00:00 2001 From: imp Date: Sat, 9 Oct 2010 08:52:09 +0000 Subject: Initial patches to install images... PR: 150921 --- .../pc-sysinstall/backend/functions-bsdlabel.sh | 80 +++++---- usr.sbin/pc-sysinstall/backend/functions-disk.sh | 60 ++++--- .../backend/functions-extractimage.sh | 42 +++++ .../pc-sysinstall/backend/functions-mountdisk.sh | 10 +- usr.sbin/pc-sysinstall/backend/functions-newfs.sh | 6 + usr.sbin/pc-sysinstall/backend/functions.sh | 189 ++++++++++++++++----- usr.sbin/pc-sysinstall/backend/parseconfig.sh | 11 +- usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf | 4 + usr.sbin/pc-sysinstall/examples/README | 5 +- 9 files changed, 305 insertions(+), 102 deletions(-) (limited to 'usr.sbin/pc-sysinstall') diff --git a/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh b/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh index 2a0ac3d..f5cf86a 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh @@ -165,7 +165,6 @@ setup_mbr_partitions() WRKSLICE="$2" FOUNDPARTS="1" - # Lets setup the BSDLABEL BSDLABEL="${TMPDIR}/bsdLabel-${WRKSLICE}" export BSDLABEL @@ -193,6 +192,11 @@ setup_mbr_partitions() SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3` + if echo $STRING | grep -E '^/.+' >/dev/null 2>&1 + then + IMAGE=`echo ${STRING} | cut -f1 -d' '` + fi + # Check if we have a .eli extension on this FS echo ${FS} | grep ".eli" >/dev/null 2>/dev/null if [ "$?" = "0" ] @@ -254,7 +258,7 @@ setup_mbr_partitions() # Check if we found a valid root partition check_for_mount "${MNT}" "/" if [ "$?" = "0" ] ; then - FOUNDROOT="0" ; export FOUNDROOT + FOUNDROOT="0" ; export FOUNDROOT fi # Check if we have a "/boot" instead @@ -267,7 +271,7 @@ setup_mbr_partitions() fi fi - else + else # Done with the a: partitions # Check if we found a valid root partition not on a: @@ -306,7 +310,7 @@ setup_mbr_partitions() fi # Save this data to our partition config dir - echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}" >${PARTDIR}/${WRKSLICE}${PARTLETTER} + echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${WRKSLICE}${PARTLETTER} # If we have a enc password, save it as well if [ ! -z "${ENCPASS}" ] ; then @@ -327,6 +331,8 @@ setup_mbr_partitions() *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;; esac + unset IMAGE + fi # End of subsection locating a slice in config echo $line | grep "^commitDiskLabel" >/dev/null 2>/dev/null @@ -567,7 +573,7 @@ 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}" -a -z "${WORKINGIMAGES}" ]; then + if [ -z "${WORKINGSLICES}" ]; then exit_err "ERROR: No slices were setup! Please report this to the maintainers" fi @@ -612,12 +618,6 @@ setup_disk_label() populate_disk_label "${i}" done - for i in $WORKINGIMAGES - do - image=`echo "${i}"|cut -f2 -d:` - check_image_layout "${image}" - done - # Check if we made a root partition if [ "$FOUNDROOT" = "-1" ] then @@ -653,7 +653,7 @@ check_fstab_mbr() then PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'` - grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1 + cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/$' >/dev/null 2>&1 if [ "$?" = "0" ] then if [ "${PARTLETTER}" = "a" ] @@ -662,10 +662,14 @@ check_fstab_mbr() else FOUNDROOT="1" fi + + ROOTIMAGE="1" + export FOUNDROOT + export ROOTIMAGE fi - grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1 + cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/boot$' >/dev/null 2>&1 if [ "$?" = "0" ] then if [ "${PARTLETTER}" = "a" ] @@ -700,7 +704,7 @@ check_fstab_gpt() then PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'` - grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1 + cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/$' >/dev/null 2>&1 if [ "$?" = "0" ] then if [ "${PARTNUMBER}" = "2" ] @@ -709,10 +713,14 @@ check_fstab_gpt() else FOUNDROOT="1" fi + + ROOTIMAGE="1" + export FOUNDROOT + export ROOTIMAGE fi - grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1 + cat "${FSTAB}" | awk '{ print $2 }' | grep -E '^/boot$' >/dev/null 2>&1 if [ "$?" = "0" ] then if [ "${PARTNUMBER}" = "2" ] @@ -731,42 +739,45 @@ check_fstab_gpt() return 1 }; -check_image_layout() +check_disk_layout() { local SLICES - local IMAGE local TYPE + local DISK local RES - local MD local F - IMAGE="$1" + DISK="$1" TYPE="MBR" - if [ -z "${IMAGE}" ] + if [ -z "${DISK}" ] then return 1 fi - MD=`mdconfig -af "${IMAGE}"` - if [ "$?" != "0" ] + 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 - return 1 + SLICES="${SLICES_MBR}" + TYPE="MBR" + RES=0 fi - - SLICES=`ls /dev/${MD}s[1-4]*[a-h]* 2>/dev/null` - if [ "$?" != "0" ] + if [ -n "${SLICES_GPT}" ] then - SLICES=`ls /dev/${MD}p[0-9]* 2>/dev/null` - if [ -n "${SLICES}" ] - then - TYPE="GPT" - RES=0 - fi - else + 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 @@ -796,6 +807,5 @@ check_image_layout() umount /mnt done - mdconfig -d -u "${MD}" return ${RES} }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-disk.sh b/usr.sbin/pc-sysinstall/backend/functions-disk.sh index f676cd6..1ff33fa 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-disk.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-disk.sh @@ -400,12 +400,12 @@ setup_disk_slice() 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`" + | grep -v ${DISK} \ + | grep -v ' free' \ + | tr -s '\t' ' ' \ + | cut -d ' ' -f 4 \ + | sed '/^$/d' \ + | tail -n 1`" if [ -z "${LASTSLICE}" ] then @@ -466,7 +466,7 @@ setup_disk_slice() if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then PSCHEME="MBR" tmpSLICE="${DISK}s1" - else + else tmpSLICE="${DISK}p1" fi @@ -486,29 +486,44 @@ setup_disk_slice() ;; image) - if [ -n "${IMAGE}" ] + if [ -z "${IMAGE}" ] then - write_image "${IMAGE}" "${DISK}" - else - exit_err "ERROR: partition type image specified with no image!" + exit_err "ERROR: partition type image specified with no image!" fi - - IMAGE="${DISK}:${IMAGE}" - if [ -z "${WORKINGIMAGES}" ] - then - WORKINGIMAGES="${IMAGE}" - else - WORKINGIMAGES="${WORKINGIMAGES} ${IMAGE}" - fi - - export WORKINGIMAGES ;; *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;; esac + + + if [ -n "${IMAGE}" ] + then + local DEST + + if [ -n "${tmpSLICE}" ] + then + DEST="${tmpSLICE}" + else + DEST="${DISK}" + fi + + if iscompressed "${IMAGE}" + then + local COMPRESSION + + get_compression_type "${IMAGE}" + COMPRESSION="${VAL}" + + decompress_file "${IMAGE}" "${COMPRESSION}" + IMAGE="${VAL}" + 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 [ -n "${tmpSLICE}" ] + if [ -z "${IMAGE}" ] then echo "disk${disknum}" >${SLICECFGDIR}/$tmpSLICE fi @@ -524,7 +539,6 @@ setup_disk_slice() echo "$MIRRORDISK:$MIRRORBAL" >${MIRRORCFGDIR}/$DISK fi - # Increment our disk counter to look for next disk and unset unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE disknum="`expr $disknum + 1`" diff --git a/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh b/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh index c7c7ed7..3077f2a 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh @@ -147,6 +147,7 @@ start_extract_split() 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" @@ -328,6 +329,46 @@ start_rsync_copy() }; +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 "^disk0=" >/dev/null 2>/dev/null + if [ "$?" = "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 "^commitDiskPart" >/dev/null 2>/dev/null + if [ "$?" = "0" ] + then + # Found our flag to commit this disk setup / lets do sanity check and do it + if [ ! -z "${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() @@ -393,6 +434,7 @@ init_extraction() sftp) ;; rsync) start_rsync_copy ;; + image) start_image_install ;; *) exit_err "ERROR: Unknown install medium" ;; esac diff --git a/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh b/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh index 57d70ec..5aa7a2b 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh @@ -127,6 +127,7 @@ mount_all_filesystems() UFS+SUJ) mount_partition ${PART}${EXT} ${PARTFS} ${PARTMNT} "noatime" ;; UFS+J) mount_partition ${PART}${EXT}.journal ${PARTFS} ${PARTMNT} "async,noatime" ;; ZFS) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;; + IMAGE) mount_partition ${PART} ${PARTFS} ${PARTMNT} ;; *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac fi @@ -176,7 +177,14 @@ mount_all_filesystems() rc_halt "swapon /dev/${PART}" fi ;; - *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; + IMAGE) + if [ ! -d "${PARTMNT}" ] + then + mkdir -p "${PARTMNT}" + fi + mount_partition ${PART} ${PARTFS} ${PARTMNT} + ;; + *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac fi done diff --git a/usr.sbin/pc-sysinstall/backend/functions-newfs.sh b/usr.sbin/pc-sysinstall/backend/functions-newfs.sh index 5ac9ebe..1c2b023 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-newfs.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-newfs.sh @@ -100,6 +100,7 @@ setup_filesystems() 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 "/dev/${PART}.journal" ] @@ -204,6 +205,11 @@ setup_filesystems() sleep 2 ;; + IMAGE) + write_image "${PARTIMAGE}" "${PART}" + sleep 2 + ;; + *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;; esac diff --git a/usr.sbin/pc-sysinstall/backend/functions.sh b/usr.sbin/pc-sysinstall/backend/functions.sh index 847d97e..cb3b698 100755 --- a/usr.sbin/pc-sysinstall/backend/functions.sh +++ b/usr.sbin/pc-sysinstall/backend/functions.sh @@ -284,27 +284,123 @@ get_zpool_name() fi }; +iscompressed() +{ + local FILE + local RES + + FILE="$1" + RES=1 + + if echo "${FILE}" | \ + grep -iE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' >/dev/null 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 +} + +decompress_file() +{ + local FILE + local COMPRESSION + + FILE="$1" + COMPRESSION="$2" + + if [ -n "${COMPRESSION}" ] + then + case "${COMPRESSION}" in + lzw) + rc_halt "uncompress ${FILE}" + VAL="${FILE%.Z}" + ;; + + lzo) + rc_halt "lzop -d ${FILE}" + VAL="${FILE%.lzo}" + ;; + + lzma) + rc_halt "lzma -d ${FILE}" + VAL="${FILE%.lzma}" + ;; + + gzip) + rc_halt "gunzip ${FILE}" + VAL="${FILE%.gz}" + ;; + + bzip2) + rc_halt "bunzip2 ${FILE}" + VAL="${FILE%.bz2}" + ;; + + xz) + rc_halt "xz -d ${FILE}" + VAL="${FILE%.xz}" + ;; + + zip) + rc_halt "unzip ${FILE}" + VAL="${FILE%.zip}" + ;; + + *) + exit_err "ERROR: ${COMPRESSION} compression is not supported" + ;; + esac + fi + + export VAL +} + write_image() { + local IMAGE_FILE + local DEVICE_FILE + IMAGE_FILE="$1" DEVICE_FILE="$2" if [ -z "${IMAGE_FILE}" ] then - echo "ERROR: Image file not specified!" - exit 1 + exit_err "ERROR: Image file not specified!" fi if [ -z "${DEVICE_FILE}" ] then - echo "ERROR: Device file not specified!" - exit 1 + exit_err "ERROR: Device file not specified!" fi if [ ! -f "${IMAGE_FILE}" ] then - echo "ERROR: '${IMAGE_FILE}' does not exist!" - exit 1 + exit_err "ERROR: '${IMAGE_FILE}' does not exist!" fi DEVICE_FILE="${DEVICE_FILE#/dev/}" @@ -312,16 +408,21 @@ write_image() if [ ! -c "${DEVICE_FILE}" ] then - echo "ERROR: '${DEVICE_FILE}' is not a character device!" - exit 1 + exit_err "ERROR: '${DEVICE_FILE}' is not a character device!" fi - if [ "${RES}" = "0" ] + if iscompressed "${IMAGE_FILE}" then - rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE} ibs=16k obs=16k" + local COMPRESSION + + get_compression_type "${IMAGE_FILE}" + COMPRESSION="${VAL}" + + decompress_file "${IMAGE_FILE}" "${COMPRESSION}" + IMAGE_FILE="${VAL}" fi - return 0 + rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE} bs=128k" }; install_fresh() @@ -329,45 +430,57 @@ install_fresh() # Lets start setting up the disk slices now setup_disk_slice - # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels - setup_disk_label + 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 + # 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 + # Lets mount the partitions now + mount_all_filesystems - # We are ready to begin extraction, lets start now - init_extraction + # 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 optional modules to load + install_components - # Check if we have any packages to install - install_packages + # Check if we have any packages to install + install_packages - # Do any localization in configuration - run_localize + # Do any localization in configuration + run_localize - # Save any networking config on the installed system - save_networking_install + # Save any networking config on the installed system + save_networking_install - # Now add any users - setup_users + # Now add any users + setup_users - # Now run any commands specified - run_commands + # Now run any commands specified + run_commands - # Do any last cleanup / setup before unmounting - run_final_cleanup + # Do any last cleanup / setup before unmounting + run_final_cleanup - # Unmount and finish up - unmount_all_filesystems + # Unmount and finish up + unmount_all_filesystems + fi echo_log "Installation finished!" -} +}; + +install_image() +{ + # We are ready to begin extraction, lets start now + init_extraction + + echo_log "Installation finished!" +}; install_upgrade() { @@ -397,4 +510,4 @@ install_upgrade() 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 af4f974..15611fd 100755 --- a/usr.sbin/pc-sysinstall/backend/parseconfig.sh +++ b/usr.sbin/pc-sysinstall/backend/parseconfig.sh @@ -73,7 +73,7 @@ file_sanity_check "installMode disk0 installType installMedium packageType" check_value installMode "fresh upgrade" check_value bootManager "bsd none" check_value installType "PCBSD FreeBSD" -check_value installMedium "dvd usb ftp rsync" +check_value installMedium "dvd usb ftp rsync image" 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" @@ -100,7 +100,12 @@ start_networking # If we are not doing an upgrade, lets go ahead and setup the disk case "${INSTALLMODE}" in fresh) - install_fresh + if [ "${INSTALLMEDIUM}" = "image" ] + then + install_image + else + install_fresh + fi ;; upgrade) @@ -108,7 +113,7 @@ case "${INSTALLMODE}" in ;; *) - exit 1 + exit 1 ;; esac diff --git a/usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf b/usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf index 33f3753..6a9f0cb 100644 --- a/usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf +++ b/usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf @@ -68,6 +68,10 @@ FBSD_BRANCH_DIR="${FBSD_BRANCH}" FBSD_ARCH=`uname -m` export FBSD_UZIP_FILE FBSD_TAR_FILE FBSD_BRANCH FBSD_BRANCH_DIR FBSD_ARCH +# Location of image file +IMAGE_FILE="/home/john/tmp/PCBSD8.1-x86-USB.img" +export IMAGE_FILE + # Our internet mirror listing file location NETSERVER="http://updates.pcbsd.org" ARCH="`uname -m`" diff --git a/usr.sbin/pc-sysinstall/examples/README b/usr.sbin/pc-sysinstall/examples/README index 345cca2..c972286 100644 --- a/usr.sbin/pc-sysinstall/examples/README +++ b/usr.sbin/pc-sysinstall/examples/README @@ -153,7 +153,7 @@ specified this defaults to "round-robin" Setting this option will instruct pc-sysinstall to install the BSD boot Manager, or leave it empty -# image=(/path/to/image/file) +# 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. @@ -218,7 +218,7 @@ If you with to just include the disk into the pool in "basic" mode, then use (ad The following settings specify the type, locations and sources for this installation -# installMedium=(dvd, usb, ftp, rsync) +# installMedium=(dvd, usb, ftp, rsync, image) Set installMedium= to the source type we will be using for this install. @@ -227,6 +227,7 @@ Available Types: 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) -- cgit v1.1