1

On Centos 7.7 I run commands:

# dd if=/dev/zero of=/root/500MB.img bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 0.374844 s, 1.4 GB/s
# losetup --all
# losetup /dev/loop0 ./500MB.img
# losetup --all
/dev/loop0: [64768]:33575036 (/root/500MB.img)
# fdisk -l /dev/loop0

Disk /dev/loop0: 524 MB, 524288000 bytes, 1024000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# fdisk /dev/loop0
[here set partition]
# fdisk -l /dev/loop0

Disk /dev/loop0: 524 MB, 524288000 bytes, 1024000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2b7a6a60

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1            2048     1023999      510976   83  Linux
#

However the /dev/loop0p1 doesn't exist in the system:

# pvcreate /dev/loop0p1
  Device /dev/loop0p1 not found.
# ls -ld /dev/loop0p1
ls: cannot access /dev/loop0p1: No such file or directory
# kpartx -l /dev/loop0
loop0p1 : 0 1021952 /dev/loop0 2048
# ls -ld /dev/loop0p1
ls: cannot access /dev/loop0p1: No such file or directory

Only the loop-disk device exists:

# ls -ld /dev/loop0
brw-rw----. 1 root disk 7, 0 Apr 23 09:31 /dev/loop0

Where is the partition showed on "fdisk -l"?

Update: Fixed thanks to Stephen Kitt's hints. All steps run to fix:

# losetup -d /dev/loop0
# losetup --all
# ls /dev/loop0
/dev/loop0
# fdisk -l /dev/loop0
fdisk: cannot open /dev/loop0: Inappropriate ioctl for device
# fdisk -l ./500MB.img

Disk ./500MB.img: 524 MB, 524288000 bytes, 1024000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2b7a6a60

      Device Boot      Start         End      Blocks   Id  System
./500MB.img1            2048     1023999      510976   83  Linux
# losetup -P /dev/loop0 ./500MB.img
# losetup --all
/dev/loop0: [64768]:33575036 (/root/500MB.img)
# ls -ld /dev/loop0*
brw-rw----. 1 root disk   7, 0 Apr 23 10:16 /dev/loop0
brw-rw----. 1 root disk 259, 0 Apr 23 10:16 /dev/loop0p1
#
3

You need to tell the kernel to scan the partitions; one way to do that is to use losetup, assuming your partition table is written before the device is mounted:

  • run fdisk on your image
  • check the partition table with fdisk -l on the image
  • add the -P option to losetup: losetup -P /dev/loop0 ./500MB.img

The last step will scan the partitions in the loop device, and you’ll see /dev/loop0p1.

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.