Creating a File System from a file


Here is the sequence of commands I use on Linux to create a fs from a file... Is this possible in BSD? And, if so, how do I do it?

# SIZE=1000000
# head -c $SIZE < /dev/zero > myfilename
# losetup /dev/loop0 myfilename
# mke2fs /dev/loop0
# mount -o loop /dev/loop0 /mnt/myfilename

I would like the FS to be read-only.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$ bc # calculate number of blocks in filesystem, even linux sizes filesystems in blocks, but hides the problem about strange sizes
$ dd if=/dev/zero of=myfilename count=1953 # create file in optimal manner
$ sudo vnconfig vnd0 myfilename # create block device on normal file
$ sudo newfs /dev/vnd0 # create default filesystem, ffs, you can partition if you like too
$ sudo mount -o ro /dev/vnd0 /mnt # mount it
$ : : : : # do whatever you like
$ sudo umount /mnt # umount
$ sudo vnconfig -u vnd0 # remove vnode device

kind of to init this partition with few files, if not obvious, you need to mount it without -o ro option first

see "man mount_mfs" in addition to all mentioned commands.

all description is about OpenBSD (the TA you asked in) , if you look for FreeBSD or NetBSD instructions - they are different, just ask if you need them

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.