Creating an image of a USB-Stick on the same USB-Stick

I have a USB-Stick with 4 partitions:
- EFI
- UFS with BSD Installation instance / created from the FreeBSD-13.1-RELEASE-amd64-mini-memstick.img
- FAT partition for exchange with other platform OSes
- FAT partition where the image file should been placed

I'd like to create an image of the first 3 partitions on the 4th partition in ONE file using dd - creating this image from the entire medium seems impossible, but who knows?
 
there is a peice of SW that works on linux for this, adding more then one OS on a usb stick but I hardly think someone developed it to work on FBSD, I just don't remember what it is called.
 
You need to create a memory disk image that contains the geometry you want. You can do so with truncate, mdconfig, and gpart. Then write the image to the character device /dev/da0 (NOT /dev/da0s1a, etc).
 
What is the use case you have in mind? Maybe there is a better solution, maybe Ventoy is what you are seeking.

If you insist on your method, I'm not sure how to do that with dd(1), but the original installation image can be modified to your needs.

Create space for the first FAT partition:
Code:
truncate -s +1G FreeBSD-13.1-RELEASE-amd64-mini-memstick.img

Attach the image as a memory disk to the system:
Code:
mdconfig FreeBSD-13.1-RELEASE-amd64-mini-memstick.img
md0
(The unit number md0 may differ if other memory disks are attached to the system)

Add FAT partition:
Code:
gpart add -t fat32 md0

Create MS-DOS FAT file system:
Code:
newfs_msdos -c 1 -F 32 /dev/md0s3

Detach memory disk from system:
Code:
mdconfig -d -u md0

dd(1) image on USB, create second FAT partition and file system, copy image on that partition.
 
If you do use the clone method don't forget to exclude your image file.
You don't need a clone of a clone of a clone ....
clone -x image_file.img / /mnt
 
Thank you all for your advice - a first solution for me is the following:
mdconfig -t malloc -s 1024m -u md0
dd if=/dev/da0 of=/dev/md0 bs=128m
mkdir USBData
mount -o rw -t msdosfs /dev/da0s3 USBData
dd if=/dev/md0 bs=128m | gzip > USBData/MyImage.img
umount USBData
rmdir USBData
 
Back
Top