Strona domowa GDR!a Tor Hidden Service

V 3.8


Creating a disk image in FreeBSD

What?

Sometimes you just need a small filesystem in an image file. In Linux, mkfs accepts any file as its argument - it's not that easy with FreeBSD. I decided to share this because there was no clear documentation I could quickly find in Google.

OK, Get to business now

First, create an empty file, just as in Linux

uranus# dd if=/dev/zero of=partfile.dd bs=1M count=1100
1100+0 records in
1100+0 records out
1153433600 bytes transferred in 10.793702 secs (106861725 bytes/sec)

Then, you need to attach it as a memory disk

uranus# mdconfig -a -t vnode -f partfile.dd -u 0
mdconfig: ioctl(/dev/mdctl): Device busy

Oops, device 0 is already taken (-u 0 is responsible for device number). Let's see what's available

uranus# mdconfig -l
md0 md1 

So let's use md2.

uranus# mdconfig -a -t vnode -f partfile.dd -u 2

It succeeded, yay! Now we're free to create a filesystem.

uranus# bsdlabel -w -B md2 auto
uranus# newfs -m 0 md2a
Warning: changing optimization to space because minfree is less than 8%
/dev/md2a: 1100.0MB (2252784 sectors) block size 16384, fragment size 2048
		using 6 cylinder groups of 183.72MB, 11758 blks, 23552 inodes.
super-block backups (for fsck -b #) at:
 160, 376416, 752672, 1128928, 1505184, 1881440

And the moment of truth: Will it mount?

 uranus# mount /dev/md2a /media

Yes it will.

Now, how to get rid of it?

uranus# umount /media
uranus# mdconfig -d -u 2
uranus# rm partfile.dd
URL encoded in QR Code Statystyki:

Email
Comments