I installed a very old Slack version (3.2) on VirtualBox and then converted it to RAW format (ext2). However, for some reason I'm unable to mount it using losetup but qemu-nbd works fine. Why?

I tried, losetup -P -f --show slack-3.2.img

but it doesn't create partitions. I modified /etc/default/grub so that GRUB_CMDLINE_LINUX="loop.max_part=63" and grub-mkconfig, etc. but it still won't create the partitions from the image.

I tried, kpartx -av slack-3.2.img and I get

read error, sector 0
read error, sector 1
read error, sector 29

I even tried dd if=slack-3.2.img of=slack.part bs=512 skip=63 count=409185

and sudo losetup -P -f --show slack.part but it still fails. Why won't it work?

sudo fdisk -l slack-3.2.img

Disk slack-3.2.img: 200 MiB, 209715200 bytes, 409600 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
Disklabel type: dos
Disk identifier: 0x00000000

Device         Boot Start    End Sectors   Size Id Type
slack-3.2.img1         63 409247  409185 199.8M 83 Linux
  • About the grub change : did you reboot and check /proc/cmdline for the loop parameter? – Bernhard M. Dec 24 '19 at 21:35

read error, sector 0

This indicates trouble of the kernel to access your file and I have the strong suspicion that vboxfs is causing it. I have a long open bug about it not supporting symlinks and hardlinks and I think they only fixed the former.

qemu-nbd OTOH will just read the file, so it is fine, but the kernel uses mmap and other low level accesses.

A solution would be to copy the image onto a ext2/4 on a (virtual) partition.

  • I copied the image file from the shared folder to a local directory and once I losetup -P /dev/loop0 slack-3.2.img I could see that the loop device was no longer read-only (which didn't happen before) and then I could see the new device /dev/loop0p1. Thanks for your help! – Dennis Dec 25 '19 at 14:53

This is because VirtualBox usually does not use raw files, but images with a special internal format.

To convert it to raw, use

qemu-img convert -O raw INPUT OUTPUT 

An alternative explanation could be that you operate on a file, but many of the operations you try, expect a block device - and you get that from ndb or losetup.

losetup -o $((63 * 512)) /dev/loop7 FILE

Should give you the partition directly.

  • Thanks Bernhard for your reply but your suggestions didn't work. I tried losetup with the offset before and even tried it with the sizelimit option as well but it still failed. – Dennis Dec 24 '19 at 13:20
  • How does it fail? Losetup is just mapping a file onto a block device. Or do you store the file on an unusual filesystem? – Bernhard M. Dec 24 '19 at 21:33
  • Sorry, it doesn't fail, it just doesn't create the new device (/dev/loop0p1) so that I can mount it. But yes, the file is on a filesystem, the vbox filesystem because I'm sharing the file inside a VM (but that shouldn't have an effect?). Basically I'm either on a Mac or a Windows PC desktop, so I'm either using a VirtualBox VM or a Docker container to run Linux commands to be able to mount the VDI file or RAW file. qemu-nbd works fine to mount the device, so I already have a working solution, it's just that I'd like to understand why losetup cannot successfully --partscan the image? – Dennis Dec 25 '19 at 2:43
  • When I read fdisk -l slack-3.2.img and run losetup --offset $((63*512)) --sizelimit $((409185*512)) /dev/loop0 slack-3.2.img I should be able to mount /dev/loop0 but I get the error, mount: /mnt: can't read superblock on /dev/loop0. So I'm wondering if the ext2 file system has changed in some ways from version to version? Because I'm feeling that losetup won't perform --partscan successfully because it's assuming a block size of 1024 bytes? or some other assumption that doesn't apply to old disk formats? – Dennis Dec 25 '19 at 2:57
  • @Dennis "But yes, the file is on a filesystem, the vbox filesystem ... (but that shouldn't have an effect?)" what makes you think that that shouldn't have any effect ;-) ? Please edit that info (with complete details) into your Q. – mosvy Dec 25 '19 at 3:22

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.