installer/mk-prepare-system.sh
f4d17450
 #!/bin/bash
 #################################################
 #       Title:  mk-prepare-system               #
 #        Date:  2014-11-26                      #
 #     Version:  1.0                             #
 #      Author:  mbassiouny@vmware.com           #
 #     Options:                                  #
 #################################################
2f40f1d3
 #   Overview
 #       Preparing the system to install photon
 #   End
f4d17450
 #
2f40f1d3
 set -o errexit      # exit if error...insurance ;
 set -o nounset      # exit if variable not initalized
 set +h          # disable hashall
f4d17450
 source config.inc
 source function.inc
2f40f1d3
 PRGNAME=${0##*/}    # script name minus the path
f4d17450
 
2f40f1d3
 LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"    #   set log file name
 #LOGFILE=/dev/null      #   uncomment to disable log file
f4d17450
 
2f40f1d3
 [ ${EUID} -eq 0 ]   || fail "${PRGNAME}: Need to be root user: FAILURE"
 [ -z ${BUILDROOT} ] && fail "${PRGNAME}: Build root not set: FAILURE"
f4d17450
 
2f40f1d3
 if mountpoint ${BUILDROOT}/run  >/dev/null 2>&1; then umount ${BUILDROOT}/run; fi
 if mountpoint ${BUILDROOT}/sys  >/dev/null 2>&1; then umount ${BUILDROOT}/sys; fi
 if mountpoint ${BUILDROOT}/proc >/dev/null 2>&1; then umount ${BUILDROOT}/proc; fi
6eae06bc
 if mountpoint ${BUILDROOT}/dev  >/dev/null 2>&1; then umount -R ${BUILDROOT}/dev; fi
2f40f1d3
 [ ${EUID} -eq 0 ]   || fail "${PRGNAME}: Need to be root user: FAILURE"
f4d17450
 
6b3c4668
 cd ${BUILDROOT} || fail "${PRGNAME}: Change directory: ${BUILDROOT}: FAILURE"
85b82155
 
f4d17450
 #
2f40f1d3
 #   Setup the filesystem for chapter 06
f4d17450
 #
2f40f1d3
 if [[   $# -gt 0 ]] && [[ $1 == 'install' ]]; then
     mkdir -p ${BUILDROOT}/var/lib/rpm
     mkdir -p ${BUILDROOT}/cache/tdnf
     #Setup the disk
     dd if=/dev/zero of=${BUILDROOT}/cache/swapfile bs=1M count=64
     chmod 600 ${BUILDROOT}/cache/swapfile
adde0296
     mkswap -v1 ${BUILDROOT}/cache/swapfile
     swapon ${BUILDROOT}/cache/swapfile
2f40f1d3
     rpm   --root ${BUILDROOT} --initdb
1d82d2ef
     tdnf install filesystem --installroot ${BUILDROOT} --nogpgcheck --assumeyes
6860f77c
 else
2f40f1d3
     RPMPKG="$(find RPMS -name 'filesystem-[0-9]*.rpm' -print)"
     [ -z ${RPMPKG} ] && fail "  Filesystem rpm package missing: Can not continue"
     run_command "   Installing filesystem" "rpm -Uvh --nodeps --root ${BUILDROOT} --dbpath /var/lib/rpm ${RPMPKG}" "${LOGFILE}"
6860f77c
 fi
  
2f40f1d3
 #   Ommited in the filesystem.spec file - not needed for booting
 [ -e ${BUILDROOT}/dev/console ] || mknod -m 600 ${BUILDROOT}/dev/console c 5 1
85b82155
 [ -e ${BUILDROOT}/dev/null ]    || mknod -m 666 ${BUILDROOT}/dev/null c 1 3
 [ -e ${BUILDROOT}/dev/random ]  || mknod -m 444 ${BUILDROOT}/dev/random c 1 8
 [ -e ${BUILDROOT}/dev/urandom ] || mknod -m 444 ${BUILDROOT}/dev/urandom c 1 9
f4d17450
 
2f40f1d3
 if [[   $# -eq 0 ]] || [[ $1 != 'install' ]]; then
     chown -R 0:0 ${BUILDROOT}/* || :
 fi
f4d17450
 
 #
2f40f1d3
 #   Mount kernel filesystem
f4d17450
 #
6eae06bc
 if ! mountpoint ${BUILDROOT}/dev    >/dev/null 2>&1; then mount --rbind /dev ${BUILDROOT}/dev; mount --make-rslave ${BUILDROOT}/dev; fi
2f40f1d3
 if ! mountpoint ${BUILDROOT}/proc   >/dev/null 2>&1; then mount -t proc proc ${BUILDROOT}/proc; fi
 if ! mountpoint ${BUILDROOT}/sys    >/dev/null 2>&1; then mount -t sysfs sysfs ${BUILDROOT}/sys; fi
 if ! mountpoint ${BUILDROOT}/run    >/dev/null 2>&1; then mount -t tmpfs tmpfs ${BUILDROOT}/run; fi
 if [ -h ${BUILDROOT}/dev/shm ];          then mkdir -pv ${BUILDROOT}/$(readlink ${BUILDROOT}/dev/shm); fi
f4d17450
 exit 0