local-path-provisioner icon indicating copy to clipboard operation
local-path-provisioner copied to clipboard

[Question] Using loopback device to manage space

Open Moosemorals opened this issue 2 years ago • 3 comments

Hi folks, I'm looking for help/advice on adapting the setup/teardown scripts to create loopback devices as disks, to put a hard limit on the space allocated for each volume.

My current rough idea looks like the scripts below (which have only had very light testing so far).

Mostly, I'm looking for someone to tell me what obvious thing I'm missing that means this hasn't been done already.

Thanks.

setup:

NAME=$( basename $absolutePath )
# Store images in the folder above $absolutePath
IMAGE="$absolutePath/../$NAME.img"
# Create a backing file of the right size
dd if=/dev/zero of=$IMAGE count=$sizeInBytes iflag=count_bytes status=progress 
# Give it a filesystem 
# TOOD: Check if we've been asked for a filesystem!
mkfs.ext4 $IMAGE
# Add the new filesystem to host/node fstab
echo "$IMAGE $absolutePath ext4 loop 0 0" >> /etc/fstab
# Mount the device
mount $absolutePath

teardown:

IMAGE=$( grep $absolutePath /etc/fstab | awk '{print $1}' )
umount $absolutePath
sed -i "/$absolutePath/d' /etc/fstab
rm $IMAGE

To think about

  • Rather than giving the caller the root (with /lost+found), create a folder in the mount and give them that
  • Permissions?
  • Chose your own filesystem
  • A better way of naming/storing/identifying images

Moosemorals avatar Jun 03 '22 10:06 Moosemorals

Looks good. Is there any hindrance in the setup/teardown scripts?

derekbit avatar Jun 22 '22 05:06 derekbit