In the first command, the 512 number is referring to the block size of the image. When a file is written to a disk, it uses x amount of blocks. The remainder of any block not used is wasted space. This is why you sometimes see things listed as size (actual size of the file, folder, etc) and size on disk (amount of space actually taken up on disk, allowing for block size mismatch. Take, for example a 1234 byte file, if we were using 512 byte blocks, then it would actually take up 3 blocks, or 1536 bytes (512 * 3) and 302 bytes (1536 - 1234) bytes would be "wasted".
The loop0 is a loopback device. All files under /dev are actually devices (hence the name :-)). Linux treats devices as files which makes it very easy to accomplish some things when dealing with hardware. i.e. the following command will send an audio file directly to the soundcard to play (no software needed, neat!)
cat sound.wav > /dev/audio
Loopback devices are special pseudo or fake devices that Linux uses in cases like yours. What you are saying in that command is that you want Linux to treat your image file as a hard drive. This allows you to run any command that you would normally run on a hard drive, on your image file.
For the last command, we are simply mounting the file system on your fake drive (your image file) to a location on the local filesystem. With Linux, we use a flat directory structure, which is why every file location (including devices, network drives and external hard drives, etc) begins with '/', which is also referred to as the root of the filesystem. Mounting a filesystem simply puts it in a place accessible tot he rest of the system (somewhere under /).
Now, by default only a user called "root" can mount filesystems. The root user is basically the same as an administrator user on Windows. Someone who can do anything on the computer. In Ubuntu, the root user is hidden for security, so we need to use sudo
. The sudo command, basically means "hey, make me the root user to run this one command".
mount
here is the command that we are running as root (sudo), /dev/loop0 is our fake drive we created earlier, and /mnt is the location that we want the image to be accessible at. /mnt and /media are the standard locations in Linux where we mount filesystems, although this can be anywhere you want. It is best practice to create subfolder under /mnt or /media to mount to, instead of just /mnt. This is because you may have other filesystems mounted there, and if you mount over top of them, they will not be accessible! The only caveat to this, is that you need root privileges to create a folder here, so your last command should really be two commands, and look like this:
sudo mkdir /mnt/myimg
sudo mount /dev/loop0 /mnt/myimg
mkdir
is just the command to make a directory.
sudo umount /mnt
. Replace /mnt with wherever you mounted it. No, detach it from the loop devicesudo losetup -d /dev/loop0
. If you wanted two different images mounted, then you could use /dev/loop1, /dev/loop2, etc. – reverendj1 Jun 15 '12 at 14:00