Solved How to mount FreeBSD-13.2-RELEASE-armv7.img file on Linux using the loop devices

Hello to everyone.

I would like to mount the FreeBSD 13.2 img file for arm v7 on Linux using the loop devices. I wrote a litte script to do that,but it does not work. In origin I've got the img file here :

https://download.freebsd.org/releas...eeBSD-13.2-RELEASE-arm-armv7-GENERICSD.img.xz

but later I've resized the space that it offered using the truncate command. Actually I'm on Linux and I want to extract the files that are inside the img file. This is the script that I wrote to do it :

Code:
nano mount-freebsd-img-on-linux.sh :

losetup -fP FreeBSD-13.2-RELEASE-armv7.img
losetup -a
fdisk -l /dev/loop0 mount -r -t ufs -o ufstype=ufs2 /dev/loop0p2 FreeBSD-13.2-
RELEASE-armv7

Unfortunately it does not work,probably because the file system used by the image is not ufs2 :

Code:
./mount-freebsd-img-on-linux.sh

/dev/loop0: (/mnt/zroot2/zroot2/OS/Chromebook/FreeBSD-guestOS/FreeBSD-13.2-
RELEASE-armv7.img)

Disk /dev/loop0: 100 GiB, 107374182400 bytes, 209715200
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

/dev/loop0p1 *      2048    104447    102400   50M  c W95 FAT32 (LBA)
/dev/loop0p2      104448 209715199 209610752  100G a5 FreeBSD

mount: /mnt/zroot2/zroot2/OS/Chromebook/FreeBSD-guestOS/FreeBSD-13.2-RELEASE-
armv7: unknown filesystem type 'ufs'.
dmesg(1) may have more information after failed mount system call.

The partition has code ID = a5. It's not UFS. It is some kind of DOS fs. I tried vfat,but it hasn't been accepted.

The error message seems to indicate my system doesn't recognize UFS2 as a filesystem type. BUT it's not true because I have several disks on my PC that have UFS2 as a fs,and they can be mounted :

Code:
Disk /dev/sdc: 298.09 GiB, 320072933376 bytes, 625142448 sectors
Disk model: WDC WD3200AAJS-0
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: gpt
Disk identifier: 1765E314-F3CF-11EC-8C52-E0D55EE21F22

Device         Start       End   Sectors   Size Type
/dev/sdc1         40    532519    532480   260M EFI System
/dev/sdc2     532520 616562727 616030208 293.7G FreeBSD UFS
/dev/sdc3  616562728 624951335   8388608     4G FreeBSD swap

# mount -r -t ufs -o ufstype=ufs2 /dev/sdc2 /mnt/sdc2
ok
 
One thing that might be a problem is that the loop device specified in the mount command /dev/loop0p2 does not exist (I think what looks like a special filename /dev/loop0p2 is an artifact of the output of fdisk but it does not specify a real special device file). It would be better to create a separate loop device, /dev/loop1, with an offset and size with respect to the disk img file that matches the size and offset of the FreeBSD partition, and then try to mount /dev/loop1 instead of /dev/loop0p2:

losetup -o 51M --sizelimit 100G -r /dev/loop1 FreeBSD-13.2-RELEASE-armv7.img mount -r -t ufs -o ufstype=ufs2 /dev/loop1 FreeBSD-13.2-RELEASE-armv7


Never mind. I see the -P option was used with losetup, so the /dev/loop0p2 special file does exist. So I don't know why it is not working, if it works for other FreeBSD ufs2 filesystems on the system.
 
I successfully mounted the ufs2 filesystem on the FreeBSD-13.2-RELEASE-arm-armv7-GENERICSD.img image on Linux (read only, though, because IIRC Linux does not support read/write for ufs filesystems), but I needed to use /dev/loop0p5 instead of /dev/loop0p2. It seems fdisk is not smart enough to find the actual partition that has the ufs2 filesystem on it. Check the output of ls /dev/loop0* to see the partitions that fdisk is not able to find. I also ran modprobe ufs before trying to mount it.
 
Write support into ufs is a compile-time option marked dangerous in the Linux kernel. You have to recompile the kernel to get it.
 
Thanks. Since I need to recompile the FreeBSD kernel to add the "HVM Xen (for arm 32 bit) guest support with para-virtualized drivers",I've booted FreeBSD. It makes sense to leave Linux for this task and do it directly in FreeBSD.
 
Code:
mario@Z390-AORUS-PRO-DEST:/mnt/zroot2/zroot2/OS/Chromebook/domU/freebsd-xen# modprobe ufs

mario@Z390-AORUS-PRO-DEST:/mnt/zroot2/zroot2/OS/Chromebook/domU/freebsd-xen# sudo losetup -fP FreeBSD
-13.2-RELEASE-armv7.img

mario@Z390-AORUS-PRO-DEST:/mnt/zroot2/zroot2/OS/Chromebook/domU/freebsd-xen# ls /dev/loop0*
/dev/loop0  /dev/loop0p1  /dev/loop0p2  /dev/loop0p5

mario@Z390-AORUS-PRO-DEST:/mnt/zroot2/zroot2/OS/Chromebook/domU/freebsd-xen# mount -t ufs -o ufstype=
ufs2 /dev/loop0p5 ./FreeBSD-xen

mario@Z390-AORUS-PRO-DEST:/mnt/zroot2/zroot2/OS/Chromebook/domU/freebsd-xen# cd FreeBSD-xen

mario@Z390-AORUS-PRO-DEST:/mnt/zroot2/zroot2/OS/Chromebook/domU/freebsd-xen/FreeBSD-xen# ls

bin   COPYRIGHT  entropy  home  libexec  media  net   rescue  sbin  usr
boot  dev        etc      lib   md5      mnt    proc  root    tmp   var
 
Back
Top