0

I have a disk image with 2 partitions. When I do #losetup -f <file> only /dev/loop0 appears. How do I make /dev/loop0p0 and /dev/loop0p1 appear? Using #parted /dev/loop0 it does show the 2 partitions are present. I need the 2 partitions present as seperate devices to chroot into the main partition and set up grub on the esp partition.

# sudo losetup -f disk.img 

Got:

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0     5G  0 loop 
sda      8:0    0 223,6G  0 disk 
├─sda1   8:1    0   300M  0 part /boot/efi
├─sda2   8:2    0 214,5G  0 part /
└─sda3   8:3    0   8,8G  0 part [SWAP]

Expected:

loop0
├─loop0p0
└─loop1p1

Parted showing the partitions do in fact exist:

# parted
[ ... ]
(parted) print list,all
Model: Loopback device (loopback)
Disk /dev/loop0: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  135MB   134MB   fat32        efi   boot, esp
 2      135MB   5368MB  5232MB  ext4         main

[ ... ]
AnnoyinC
  • 103
  • 1
  • 4

1 Answers1

1

Add the -P switch to losetup, like this:

losetup -Pf disk.img

This will create loop devices for each partition, like /dev/loop8p3. Note that partition scanning depends on sector sizes, which are assumed to be 512 by default. If the image was made from something which had different sector sizes, then you need to specify the --sector-size switch as well.

Lacek
  • 7,233
  • 24
  • 28