2

I'm running kpartx from within a python script as part of a custom OS build I'm trying to do. I'm using python sh module to run bash commands.

sh.kpartx("-as", image) is how I attach my image.

Then I create partitions and a file system on each partition. Then ofcourse I unmount the image.

sh.kpartx("-d", image)

The problem is that in my script I use the above attach and detach commands a couple of times and with each time a new /dev/loopX is used. I would expect that after I detach an image from let's say /dev/loop0 on the next attachment I would be able to use it again. This is not the case however and /dev/loop1 is used.

What is going on and why?

  • Where is this sh.kpartx method coming from? I don't see it in my sh module and I don't see it mentioned in the sh documentation. – igal Nov 25 '17 at 16:41
  • 3
    You can substitute any command you want after sh._____ – Shady Programmer Nov 26 '17 at 22:00
0

I suspect that kpartx stores no state, so it doesn't remember whether you originally called in on /dev/loop0, or whether it had to set up the loop device.

Going from the examples in it's man page, losetup is pretty scriptable, so it shouldn't be too much extra work to handle that part yourself.

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.