[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

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.

1 Solution
$ 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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now