Home > Uncategorized > Linux Tip: Create a file and use it as a filesystem

Linux Tip: Create a file and use it as a filesystem

Creating and formating a 2GB file:
dd if=/dev/zero of=FILENAME bs=1024 count=1 seek=$((2*1024*1024-1))
mkfs -t ext3 FILENAME

Mounting:
mount -t ext3 -o loop FILENAME MOUNTPOINT

UPDATE: 29 MAR 2013
With a slight variation of the above, you can also create a sparse file. For example:

dd if=/dev/zero of=~/sparse.file bs=1k seek=2000000 count=0
mkfs.ext4 sparse.file

dd moves forward 2.0 GB and writes nothing. That will reserve the 2.0 GB sparse
file, but it will grow in size only as files are added.

More uses of the dd command can be found at Learn the dd command

Advertisements
Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: