Creating a File System from a file

Posted on 2004-11-10
Last Modified: 2013-12-09

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.

Question by:LPTech
    1 Comment
    LVL 61

    Accepted 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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now