I'm trying to shrink my raspberry pi images following this tutorial: https://softwarebakery.com/shrinking-images-on-linux

root@host:~# modprobe loop      # no errors returned
root@host:~# lsmod | grep loop  # returns nothing - this is strange…
root@host:~# ls /dev/loop*
/dev/loop0  /dev/loop2  /dev/loop4  /dev/loop6  /dev/loop-control
/dev/loop1  /dev/loop3  /dev/loop5  /dev/loop7
root@host:~# sudo losetup -f
root@host:~# losetup /dev/loop0 myimage.img
losetup: myimage.img: failed to set up loop device: Operation not permitted

Why?? What am I doing wrong?

EDIT: Spending a couple days googling I've found no hints what could be a problem here. But I've noticed that some .img files are working just fine, while others giving "Operation not permitted".

Any clues what can be wrong with the image and possible fix solutions?

  • Are you running inside a container or something? – muru Feb 14 '17 at 5:59
  • Sorry, noob here... how can I check this? What you mean by "container"? – Drew Feb 14 '17 at 6:14
  • Nope I don't create any containter. – Drew Feb 15 '17 at 3:31
  • As far as shrinking Raspian is concerned, it can now be done in one using: github.com/Drewsif/PiShrink – Tariiq Dusmohamud Apr 3 '18 at 13:21

Finally found the answer myself.

I used the Ubuntu VM to shrink my pi images. The host machine - OSX. The image file was in shared folder (host-VM)

In order to be able to mount the .img as loop device make sure to set the permissions of the .img file to 766 or 666.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.