Showing posts with label create img file. Show all posts
Showing posts with label create img file. Show all posts

Thursday, October 4, 2012

How to create, format and mount .img files

Now since I am doing some designs for the PirateBox in the future it will be easier if I would make custom image files that could replace the original one. This would make life easier as there would be no need to mount, backup and change the original image file. 

I am experimenting with some html5 videos in my custom PB design just to see how the server and router handles the "pressure". Also after reading some threads on reddit I am keen to try some browser games on my PB, but these will need a larger container than the default img (20MB). So here is a short note on how to handle these img files.
(Also sorry for the colours, it is just to illustrate parts of the code.)

Creating & formatting img files in Ubuntu


1.   Open terminal and type
dd if=/dev/zero of=file.img bs=1M count=50
This will create a file called "file.img" in your home directory with a size of 50 MB.

What is what?
if=/dev/zero => input file, but since we want an empty container (no input file), we use the "universal" term for "nothing" /dev/zero
of=file.img => output file, file name & location
count=50 => Size of the file in MB

2.   After this image needs to be formatted in some file format (ext4, fat32, ntfs and so on; ext3 for the PirateBox). Now you can either use gparted if you want  some nice GUI or you can use mkfs command:
mkfs ext3 -F file.img
(For a quick and easy way to do this, you can use my script imgKreator from GitHub.)

Mounting the img file


I have tried mounting the PirateBox img file with different software, but that didn't work. So after some help through chat and forums here is the command to mount the img file:

sudo mkdir -p /tmp/mount_tmp/ && sudo mount -o loop,rw,sync piratebox/pbIMG_ws.img /tmp/mount_tmp
What is what?
/tmp/mount_tmp/ => Create the folder where the img will be mounted
piratebox/pbIMG_ws.img => Route to PB image file
/tmp/mount_tmp => Mount location

I personally had issues trying to edit anything in the folder so I am running a mounting script with the second line being:
sudo chmod -R ug+rw /tmp/mount_tmp
Which just gives read+write permission to the folder.(Although this worked for me before, when creating a new file container use sudo chmod 777 otherwise the PB will not recognize the files and although connection to the network can be made, no website will load). After this editing is simple.

To unmount:
sudo unmount piratebox/pbIMG_ws.img

PirateBox: If interested here is a script that will allow you to quickly mount and unmount pbIM_ws.img file that contains the www folder and the UI/html files.