Changing a FreeBSD img file

I hadn't come this neat trick before so I'll repost a a bit of code provided by T-Daemon the other day in case someone is doing a Google search for doing such a thing.
Bash:
Code:
# mdconfig -u 0 FreeBSD-memstick.img

Example mount root file system:
# mount /dev/md0s2a /mnt
# cp file /mnt/root
# umount /mnt

Example mount ESP file system:
# mount_msdosfs /dev/md0s1 /mnt
# cp /boot/loader.efi /mnt/efi/boot/bootx64.efi
# umount /mnt

# mdconfig -du 0


Once again a tip of the hat to T-Daemon
 
I think it would be better to write it longhand:

mdconfig -d -u md0

That might make it more apparent that -u is the unit and using the full device name completes the clue.

Clue? Bundling switches is bog-standard with FreeBSD utilities; anything that uses getopt, so "-d -u 0" is implied, where here deleting the unit created specifically above as md0 is to be expected, no?

Why not look at the manual?
 
Sure than if we are shortening stuff why use units?

mdconfig FreeBSD-memstick.img

Yes, but in a script we're not sure what unit we'll get from mdconfig, and so what unit to delete afterwards.

I'd have used a known free unit, e.g. -u 7 for md7, or added a test on the creation, e.g. perhaps " || exit 1" but this one will fail anyway if md0 is on use.
 
Yes, but in a script we're not sure what unit we'll get from mdconfig, and so what unit to delete afterwards.
mdconfig(8) returns the unit number it created. Which you can capture in a variable, then use that variable further down the line.
 
What does -u mean in mdconfig? (without looking at the manual)
And here I was thinking that we actually promote and encourage people looking at the manual.

I get your point but being snarky certainly won't do anybody any good.
 
And here I was thinking that we actually promote and encourage people looking at the manual.

I get your point but being snarky certainly won't do anybody any good.
When posting on the forums always ask yourself, what jbo might think about it.
Thank you for being so woke.
We love being educated by you all the time.
 
Back
Top