Solved How to mount Virtual Hard disk (VHD) file in FreeBSD

Assuming the VHD has a fixed size (not dynamically allocated), then there is no need to use a virtualization software, third party applications or conversion into another formats.

To access the file system attach the image as a memory disk with mdconfig(8) and mount the file system with the appropriate utility.

Example, a VHD with a GPT partition scheme and a ext4 formatted partition. As root
Code:
# kldload ext2fs

# mdconfig  image.vhd
md0

Show the partition table for which partition is to mount:
Code:
 # gpart show md0

Mount the file system:
Code:
# mount -t ext2fs /dev/md0p2 /mnt

Unmount filesystem and detach memory disk:
Code:
# umount /mnt
# mdconfig -du md0
 
Can you do the same with the FreeBSD RAW virtual machine images? Load into mdconfig and mount?

I needed an amd64 image to burn to eMMC and discovered we don't have a GENERIC-SD image for amd64.

I thought about using one of the raw VM images and resizing it smaller.
 
Can you do the same with the FreeBSD RAW virtual machine images? Load into mdconfig and mount?
No problem. Tested on a 13.2-RELEASE, amd64 raw image (build from source):
Code:
# mdconfig vm.raw
md0
# gpart show md0
=>       3  12649619  md0  GPT  (6.0G)
         3       123    1  freebsd-boot  (62K)
       126     66584    2  efi  (33M)
     66710   2097152    3  freebsd-swap  (1.0G)
   2163862  10485760    4  freebsd-ufs  (5.0G)

# mount /dev/md0p4 /mnt
# mount | grep /mnt
/dev/md0p4 on /mnt (ufs, local, soft-updates)

I needed an amd64 image to burn to eMMC and discovered we don't have a GENERIC-SD image for amd64.

I thought about using one of the raw VM images and resizing it smaller.
I can't imagine how the VM can be resized smaller when the UFS file system on the raw image itself can't be shrunk (it can only be grown).

Can't you manually create the partition scheme, boot loader, filesystem, swap partitions on the eMMC, initialize the file systems and extract the base.txz and kernel.txz into the system root partition? In fact can't you use a normal USB or ISO image to install?

What else comes to my mind to keep the raw VM size small is to build from source a image with a modified VMSIZE and world build WITHOUT_DEBUG_FILES, eventually WITHOUT_LIB32 (see src.conf(5)).

/usr/src/release/Makefile.vm
Rich (BB code):
VMTARGETS=      vm-image
VMFORMATS?=     vhd vmdk qcow2 raw
VMSIZE?=        5120m
SWAPSIZE?=      1g
VMBASE?=        vm
 
Back
Top