I'm trying to look into the innards of FAT32, and towards that I'm trying to create a FAT32 image, mount it and do a few file operations on the command line. Per the question here, I know there's no way around using sudo to mount the image. I'm still wondering though why I end up needing sudo in order to do file operations within the mountpoint. A small bash script follows which demonstrates what works and what doesn't. Could someone show me how to do this without root?
DISK=/tmp/disk1.raw
MOUNTPOINT=/tmp/mount1
SIZE=512M
rm -f $DISK
rm -rf $MOUNTPOINT
# create disk image
qemu-img create -f raw $DISK $SIZE
# format disk image
mkfs.fat -v -F 32 $DISK
# make mountpoint
mkdir -p $MOUNTPOINT
# can't be helped
sudo mount -o loop -t msdos $DISK $MOUNTPOINT
# should work but doesn't
mkdir -p $MOUNTPOINT/tmp/
# actually works
sudo mkdir -p $MOUNTPOINT/tmp/
# should work but doesn't
dd of=$MOUNTPOINT/tmp/ticket2.txt if=/dev/zero bs=512 count=9
# actually works
sudo dd of=$MOUNTPOINT/tmp/ticket2.txt if=/dev/zero bs=512 count=9
ls -lR $MOUNTPOINT
sudo umount $MOUNTPOINT
uid
andgid
options for fat filesystems help here? Try adding-o uid=n
to themount
command, wheren
is your user id. – njsg Apr 16 '18 at 17:36