0

I am trying to create a disk image file with an EXT2 partition, however the partition is not found and entire loop device is seen as free/unpartitioned space. My computer can read Ext2 formatted disks, so that isn't the issue.

Here is my script:

#!/bin/bash

build=build

rm -f $build/disk.img

dd if=/dev/zero of=$build/disk.img bs=1048576 count=$1

driveLoop=$(sudo losetup -f)
sudo losetup $driveLoop $build/disk.img

sudo parted $driveLoop --script -- mklabel gpt
sudo parted $driveLoop --script -- mkpart primary ext2 64s 100%

sudo mkfs.ext2 $driveLoop\p1

sudo losetup -d $driveLoop

sudo chown $USER $build/disk.img

FAT partitions seem to work, but since I'm trying to get EXT partitions to work it's not very helpful. I've tried using Ext3 and Ext4, but they have the same problem. Using MBR doesn't seem to fix/change the problem either.

  • Not sure what the exact question is but I can't help but notice the "driveLoop" vs "diskLoop" discrepancy in your script. Setting the `nounset` option would have helped (try running your script with `bash -o xtrace -o nounset`). And remember to quote your parameter expansions. – Stéphane Chazelas Dec 24 '22 at 21:29
  • The `chown` is likely not necessary as the file was created by a `dd` running as the current user. – Stéphane Chazelas Dec 24 '22 at 21:31
  • Why dd when you could have used `truncate` or at least `fallocate` if you do need the underlying disk space to be allocated. – Stéphane Chazelas Dec 24 '22 at 21:33
  • Did you set `loop.max_part` to a reasonable number? The kernel may not pick up partitions at all. – Hermann Dec 24 '22 at 21:56
  • @Hermann Didn't know that was a thing, was set to 0, seems to be working now after I set it to a value that wasn't 0, thanks. – PerkyElixir22 Dec 24 '22 at 22:23

1 Answers1

0

It looks like partition discovery is not enabled for loop devices. Set loop.max_part to a non-zero value, see this question.

Hermann
  • 5,789
  • 2
  • 17
  • 32