moosefs icon indicating copy to clipboard operation
moosefs copied to clipboard

[BUG] `mfsbdev` versus `losetup`: can't work with existing disk image

Open onlyjob opened this issue 1 year ago • 2 comments

I can't manipulate existing disk image with mfsbdev due to bug(s). First, let's have a look at losetup where things work as expected (this is important for comparison and illustration of the problem):

# stat thinkpad_disk.raw
  File: thinkpad__disk.raw
  Size: 128035676160    Blocks: 250069680  IO Block: 65536  regular file

# losetup -v /dev/loop0 \
    /mnt/mfs/HDD_RAW/thinkpad_disk.raw

# lsblk
loop0        7:0    0 119.2G  0 loop

# partprobe /dev/loop0        ## this is needed to read partitions of the disk image.

# lsblk
loop0        7:0    0 119.2G  0 loop
├─loop0p1  259:1    0   100M  0 part
└─loop0p2  259:2    0 119.1G  0 part

## Note: disk is ready to use.
## `ntfswipe -v -v --unused --pagefile /dev/loop0p2` works, etc.

# parted /dev/loop0
GNU Parted 3.5
Using /dev/loop0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: Loopback device (loopback)
Disk /dev/loop0: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  106MB  105MB  primary  ntfs         boot
 2      106MB   128GB  128GB  primary  ntfs

###############################

# lsblk -b        ## get disk and partitions' size in bytes.
NAME       MAJ:MIN RM          SIZE RO TYPE  MOUNTPOINTS
loop0        7:0    0  128035676160  0 loop
├─loop0p1  259:1    0     104857600  0 part
└─loop0p2  259:2    0  127928369152  0 part

Now I'm trying to do the same using mfsbdev:

# modprobe -v nbd
insmod /lib/modules/6.12.9+bpo-rt-amd64/kernel/drivers/block/nbd.ko.xz

# mfsbdev start
mfsmaster accepted connection with parameters: read-write,restricted_ip,admin ; root mapped to root:root

# sudo mfsbdev map -f /HDD_RAW/thinkpad_disk.raw -n loop
## Note: absolute path did not work so `/mnt/mfs` had to be removed from the path.

# lsblk
nbd0        43:0    0 119.2G  0 disk
├─nbd0p1    43:1    0   800M  0 part
└─nbd0p2    43:2    0 118.5G  0 part

# Note: I didn't have to run `partprobe` to notify kernel of partitions. But if I do...
# (Note the problem: first partition should be `100M`, not `800M`.)

# partprobe /dev/nbd0
Error: Can't have a partition outside the disk!

# parted /dev/nbd0
GNU Parted 3.5
Using /dev/nbd0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: Can't have a partition outside the disk!
Ignore/Cancel?

# lsblk -b
nbd0        43:0    0  128035676160  0 disk
├─nbd0p1    43:1    0     838860800  0 part
└─nbd0p2    43:2    0  127188426752  0 part

So mbsbdev got the size of the disk properly but somehow first partition is 800M instead of 100M and the second partition (i.e. end of the disk) is cropped, being smaller than it should be.

onlyjob avatar Feb 26 '25 03:02 onlyjob

My guess is that the partition sizes in the image are stored in blocks, not in bytes and that losetup uses different block size (correct for this image) than mfsbdev (incorrect for this image). mfsbdev has an -b blocksize option to the map command. Play with it and see if it helps :)

chogata avatar Feb 27 '25 12:02 chogata

Thanks! Explicit argument -b 512 to mfsbdev map seems to help.

onlyjob avatar Feb 27 '25 14:02 onlyjob