Hacker News new | ask | show | jobs
by peterwwillis 2963 days ago
Yes, you can use losetup.

  ~# dd if=/dev/zero of=image.img bs=1M count=100
  ~# LODEVICE=$(losetup --find --show image.img)
  ~# fdisk $LODEVICE
  ~# losetup -d $LODEVICE
^ The above creates a 100MB disk image, binds it to a loopback device, runs fdisk, and then detaches it. I'm not sure how formatting the partition would work but presumably those tools have an offset option too?

edit: this page explains using offsets for mke2fs and doesn't require losetup: https://superuser.com/questions/737072/userspace-manipulatio...

also, losetup can now scan the device for partition tables and make partition-specific loopbacks! https://stackoverflow.com/a/15200862

2 comments

Extlinux on an ext4 partition doesn't need an offset. Or at least didn't when I wrote this: http://www.blackkettle.org/posts/archive/2013-08-19-bootable...
I have built block-level bootable system images for the TS-7800 using this mechanism.

https://www.embeddedarm.com/products/TS-7800

That was before I found multistrap.