Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to create a 100GB file to use as a file-system. The file will be stored on an encrypted volume, so the file/file-system itself does not need to be (further) encrypted. Searching has revealed many different methods of doing this. Some use losetup, some don't. Is the following an acceptable method?

$ dd if=/dev/zero of=~/theFile.img bs=1M count=10240
$ mkfs.ext4 ~/theFile.img   # will prompt about block special device
$ sudo mount -o loop ~/theFile.img /media/mountPoint
share|improve this question

2 Answers 2

up vote 5 down vote accepted
  1. BS and COUNT should be lowercase:

    dd if=/dev/zero of=~/theFile.img bs=1M count=10240

  2. you need to make the /media/MountPoint directory if it doesn't already exist:

    sudo mkdir -p /media/MountPoint

Apart from those two things, what you have there should work.

It's usually better to be explicit than rely on implicit behaviour, so you might want to change the mount line to:

sudo mount -t ext4 -o loop ~/theFile.img /media/mountPoint

share|improve this answer
1  
Thanks for the corrections. It was the M in 1M that had to be uppercase. Don't know why I put bs and count in uppercase too. Thanks for the improved mount. –  SabreWolfy Jul 25 '12 at 9:34
    
I've accepted a suggested edit to my question to correct the uppercase mistake and to explicitly specify a loop device in the mount. –  SabreWolfy Jul 25 '12 at 9:38

Except for the capital letters in the dd options and not including the loop option in mount, I find this perfectly valid. mkfs is warning you that is not using a block device to make sure that you know what you're doing.

Anyway, at the end, you will be using a loop device:

$ dd if=/dev/zero of=~/theFile.img bs=1M count=10
$ /sbin/mkfs.ext4 theFile.img
$ sudo mount -o loop theFile.img /mnt/tmp/
$ df -h

/dev/loop0            9,7M  1,1M  8,1M  12% /mnt/tmp
share|improve this answer
1  
The -o loop may or may not be required...depends on the version of mount. My current version doesn't require it, but I remember having to specify it in the past. Still, like i said - it's better to be explicit than implicit in scripts, serves as documentation of WTF Was I Thinking When I Did That? –  cas Jul 25 '12 at 9:39
    
Agreed. (Note: I'm using mount 2.17.2-9 from the current Debian Stable) –  rpet Jul 25 '12 at 10:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.