From: Jean-Baptiste Boric Date: Tue, 6 Oct 2015 06:58:08 +0000 (+0200) Subject: Boot-to-ramdisk image generation scripts X-Git-Url: http://zhaoyanbai.com/repos/%22http:/static/doc/zpipe.c?a=commitdiff_plain;h=refs%2Fpull%2F140%2Fhead;p=minix.git Boot-to-ramdisk image generation scripts Scripts for generating boot-to-ramdisk images are now available. These can be used for example to boot from PXE or from a USB stick, as the ramdisk are self-contained and do not rely on any block devices after being loaded into RAM. The image generation framework has also been slightly cleaned up in order to better accomodate tarball sets bundling in images. Change-Id: I65a176832bd0d6954b430fa8305f90af0bd606c1 --- diff --git a/etc/rc b/etc/rc index d38ff0bf5..f9fcd2140 100755 --- a/etc/rc +++ b/etc/rc @@ -1,5 +1,10 @@ # /etc/rc - System startup script run by init before going multiuser. +if sysenv bootramdisk >/dev/null +then + /bin/sh /etc/rc.ramdisk +fi + # Are we booting from CD? bootcd="`/bin/sysenv bootcd`" @@ -138,9 +143,12 @@ autoboot|start) fsck -x / $fflag $fsckopts mount -a - # Unmount and free now defunct ramdisk - umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk" - ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk" + if [ -z "`sysenv bootramdisk`" ] + then + # Unmount and free now defunct ramdisk + umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk" + ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk" + fi # Initialize files. >/var/run/utmp # /etc/utmp keeps track of logins diff --git a/minix/drivers/storage/ramdisk/rc b/minix/drivers/storage/ramdisk/rc index 5849f8572..de2a3a6a8 100644 --- a/minix/drivers/storage/ramdisk/rc +++ b/minix/drivers/storage/ramdisk/rc @@ -55,7 +55,7 @@ fi if /bin/sysenv rootdevname >/dev/null then rootdevname=/dev/`/bin/sysenv rootdevname` else - if ! sysenv cdproberoot >/dev/null + if (! sysenv cdproberoot) && (! sysenv bootramdisk) >/dev/null then echo "rootdevname not set" exit 1 fi @@ -81,6 +81,11 @@ then loadramdisk "$ramimagename" || echo "WARNING: loadramdisk failed" fi +if sysenv bootramdisk >/dev/null +then + rootdevname=imgrd +fi + echo "Root device name is $rootdevname" if ! sysenv cdproberoot >/dev/null @@ -92,8 +97,14 @@ fi # Change root from temporary boot ramdisk to the configure # root device -/bin/mount -n $bin_img"$rootdevname" / +if ! sysenv bootramdisk >/dev/null +then + /bin/mount -n $bin_img"$rootdevname" / +fi /bin/mount -e -n -t procfs none /proc || echo "WARNING: couldn't mount procfs" -exec /bin/sh /etc/rc `sysenv bootopts` "$@" +if ! sysenv bootramdisk >/dev/null +then + exec /bin/sh /etc/rc `sysenv bootopts` "$@" +fi diff --git a/releasetools/image.defaults b/releasetools/image.defaults index 4a69d0303..e2a5f617a 100644 --- a/releasetools/image.defaults +++ b/releasetools/image.defaults @@ -16,5 +16,10 @@ : ${PKG_INFO=pkg_info} : ${BUNDLE_PACKAGES=} +: ${BUNDLE_SETS=0} + : ${RC=../local/rc.${ARCH}} : ${ASR_HACK=0} + +# where the kernel & boot modules will be +MODDIR=${DESTDIR}/boot/minix/.temp diff --git a/releasetools/image.functions b/releasetools/image.functions index 5aa581b11..5423a425a 100644 --- a/releasetools/image.functions +++ b/releasetools/image.functions @@ -8,7 +8,8 @@ # # $1 : directory to add # $2 : spec file -add_dir_spec() { +add_dir_spec() +{ echo "./$1 type=dir uid=0 gid=0 mode=0755" >> ${WORK_DIR}/$2 } @@ -17,7 +18,8 @@ add_dir_spec() { # # $1 : file to add # $2 : spec file -add_file_spec() { +add_file_spec() +{ echo "./$1 type=file uid=0 gid=0 mode=0755 size=$(wc -c < ${ROOT_DIR}/${1})" >> ${WORK_DIR}/$2 } @@ -27,7 +29,8 @@ add_file_spec() { # $1 : symlink to add # $2 : link to # $3 : spec file -add_link_spec() { +add_link_spec() +{ echo "./$1 type=link uid=0 gid=0 mode=0755 link=$2" >> ${WORK_DIR}/$3 } @@ -40,7 +43,8 @@ add_link_spec() { # spec files are put in WORK_DIR, the file system created in ROOT_DIR # # $1 : sets to extract -build_workdir() { +build_workdir() +{ # Extract sets mkdir -p ${ROOT_DIR} for set in $1; do @@ -64,19 +68,28 @@ build_workdir() { # Build specifications files cp ${ROOT_DIR}/etc/mtree/set* ${WORK_DIR} ${ROOT_DIR}/usr/bin/MAKEDEV -s -m all >> ${WORK_DIR}/extra.dev + + if [ ${BUNDLE_SETS} -eq 1 ] + then + echo " * Bundling sets..." + workdir_add_sets + fi } # # Add tarball sets to the workdir (for installation CD) # -workdir_add_sets() { +workdir_add_sets() +{ # Add sets to the root - mkdir -p ${ROOT_DIR}/${ARCH}/binary/sets; - add_dir_spec "${ARCH}" extra.sets - add_dir_spec "${ARCH}/binary" extra.sets - add_dir_spec "${ARCH}/binary/sets" extra.sets + mkdir -p ${ROOT_DIR}/usr/${ARCH}/binary/sets; + add_dir_spec "usr/${ARCH}" extra.sets + add_dir_spec "usr/${ARCH}/binary" extra.sets + add_dir_spec "usr/${ARCH}/binary/sets" extra.sets + + add_link_spec "${ARCH}" "usr/${ARCH}" extra.sets - DEST_SETS_DIR="${ARCH}/binary/sets" + DEST_SETS_DIR="usr/${ARCH}/binary/sets" for set in ${SETS_DIR}/*.tgz; do # Copy set itself cp ${set} ${ROOT_DIR}/${DEST_SETS_DIR} @@ -107,10 +120,37 @@ workdir_add_sets() { add_file_spec "${DEST_SETS_DIR}/SHA512" extra.sets } +# +# Add HDD files to the workdir +# +workdir_add_hdd_files() +{ + # create a fstab entry in /etc + cat >${ROOT_DIR}/etc/fstab <${ROOT_DIR}/etc/fstab <${ROOT_DIR}/etc/fstab <${ROOT_DIR}/etc/fstab <${ROOT_DIR}/etc/fstab <${ROOT_DIR}/boot.cfg < ${WORK_DIR}/extra.boot + +# move all modules back to ROOT_DIR +mv ${WORK_DIR}/kernel ${WORK_DIR}/mod* ${ROOT_DIR}/ +add_file_spec "kernel" extra.boot +for i in ${ROOT_DIR}/mod*; do + add_file_spec $(basename $i) extra.boot +done + +# add boot.cfg +cat >${ROOT_DIR}/boot.cfg <