losetup: create and attach images to loopback devices in one operation
Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
4b3c1e922c
commit
b540eb5ee7
2 changed files with 2 additions and 4 deletions
|
|
@ -35,9 +35,8 @@ def mount_api(dest):
|
|||
|
||||
@contextlib.contextmanager
|
||||
def loop_device(image):
|
||||
r = subprocess.run(["losetup", "-f"], stdout=subprocess.PIPE, encoding="utf-8", check=True)
|
||||
r = subprocess.run(["losetup", "--partscan", "--show", "--find", image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
|
||||
loop = r.stdout.strip()
|
||||
r = subprocess.run(["losetup", loop, "-P", image], check=True)
|
||||
try:
|
||||
yield loop
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -35,9 +35,8 @@ def mount_api(dest):
|
|||
|
||||
@contextlib.contextmanager
|
||||
def loop_device(image):
|
||||
r = subprocess.run(["losetup", "-f"], stdout=subprocess.PIPE, encoding="utf-8", check=True)
|
||||
r = subprocess.run(["losetup", "--partscan", "--show", "--find", image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
|
||||
loop = r.stdout.strip()
|
||||
r = subprocess.run(["losetup", loop, "-P", image], check=True)
|
||||
try:
|
||||
yield loop
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue