3 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
4 WS=$(realpath $SCRIPT_DIR/..)
8 rootfs="${WS}/lunaix_rootfs.${fs}"
11 if [ ! -d "${USR}" ]; then
12 echo "build the user target first!"
17 if [ ! "$EUID" -eq 0 ]; then
18 echo "==================="
19 echo " mkrootfs require root privilege to manipulate disk image"
20 echo " you maybe prompted for password"
21 echo "==================="
26 tmp_mnt="$(mktemp -d)"
29 echo "an error occured, reverting..."
35 echo "revert: ${tmp_mnt}"
36 ${prefix} rm -rf "${tmp_mnt}"
39 echo "revert: ${rootfs}"
43 echo "${prefix} rm umount ${tmp_mnt}"
51 dd if=/dev/zero of="${rootfs}" count=${size_mb} bs=1M \
54 mkfs.${fs} -L lunaix-rootfs -r 0 "${rootfs}" \
57 ${prefix} mount -o loop "${rootfs}" "${tmp_mnt}" \
60 ${prefix} chmod -R o+rwx ${tmp_mnt} \
64 cd "${tmp_mnt}" || cleanup tmpmnt img
66 ${prefix} ${SCRIPT_DIR}/mkrootfs-layout ${tmp_mnt} ${USR}
69 if [ "$has_err" -eq 2 ]; then
70 cleanup mnt tmpmnt img
77 ${prefix} umount "${tmp_mnt}" || cleanup
79 ${prefix} rm -d "${tmp_mnt}" || cleanup
81 ${prefix} chmod o+rw ${rootfs} || cleanup
83 if [ ! "${has_err:-0}" -eq 0 ]; then
84 echo "done, but with error."