0

Looking for some program to create a file of image of the information (.img) to later be able to mount it, I have not found anything simple. In the case of Clonezilla, it requires additional space to unzip the images and then assemble them. And if I need to access the image file and the size has already exceeded the storage space of my disk?

Then I came up with the following idea to create a mountable .img with the information, maybe with some additional commands or utilities it could be improved: It could be that I could create an empty .img image, format it with fsck and I ' m not sure if it would be a good idea, but I could use rsync to synchronize all the current data to the .img image (previously mounted). What do you think of this solution? I'm sure others will like it too because I've seen that later they want to mount their images.

How should I use rsync to do this?

0

I don't know of any soft being able to achieve this, but you can do it using loopdevices.

# Create an image file (100 M in the example, change the count to 1000 for 1G, etc)
dd if=/dev/urandom of=/path/to/image.img bs=1M count=100
# Now we use it as a loop device
sudo losetup /dev/loop0 /path/to/image.img
# Format it using the filesystem of your choice (I'm using ext4 here for the example).
mkfs.ext4 /dev/loop0

# Mount that new filesystem.
mkdir /mnt/loop && mount /dev/loop0 /mnt/loop

# Now we can transfer things to the image using rsync (for example /var/log content)
rsync -avz /var/log/ /mnt/loop/

# Unmount the filesystem and remove the loop device.
umount /mnt/loop
losetup -D /dev/loop0

You can now move image.img and use it somewhere else (or you can just store it on some remote device like you would for a regular file).

In order to use it on an other computer for example :

# Copy image.img using the tool you want (scp, etc...)
# Mount the image
mount -o loop /path/to/image.img /mnt/loop
# Alter content of the image
# Safely unmount the filesystem
umount /mnt/loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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