github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/loopback.sh (about)

     1  #!/bin/bash
     2  
     3  if ! [ -x "$(command -v losetup)" ]; then
     4    echo "Error: losetup not installed (apt-get mount or klibc-utils)" >&2
     5    exit 1
     6  fi
     7  
     8  ## required:
     9  while (( "$#" )); do
    10    case "${1}" in
    11      --mountpath) mountpath=$2; shift; shift;;
    12      --size) size=$2; shift; shift;;
    13      *) echo "fatal: unknown argument '${1}'"; exit 1;;
    14    esac
    15  done
    16  
    17  [[ ! -z $mountpath ]] || { echo "Error: mountpath not defined"; exit 1; }
    18  [[ ! -z $size ]] || { echo "Error: size not defined"; exit 1; }
    19  
    20  sz=`numfmt --from=iec ${size}` || exit_error $?
    21  let mbcount=$sz/1048576 # IEC mebibytes
    22  if [ $mbcount -lt 100 ] ; then
    23    echo "the minimum loopback size is 100M (have ${size})"
    24    exit 1
    25  fi
    26  
    27  mkdir -p $mountpath
    28  dd if=/dev/zero of="${mountpath}.img" bs=1M count=1024
    29  losetup -fP "${mountpath}.img"
    30  mkfs.ext4 "${mountpath}.img" > /dev/null
    31  device=$(losetup -l | grep "${mountpath}.img" | awk '{print $1}')
    32  mount -o loop "${device}" $mountpath