[HOW TO] using loopback files

Morning, 

Sometimes, you want to have a specified mount point for backing up. But, you could not find any free mount point. 

Also I explain why do we need to have a specified mount point.
1. To mark as a backup mount point other purpose, then nobody have a mistake with this. 
2. Clearly mount point for managing 

So, why did I us "loopback file? 
Using "loopback file", I do it. Loopback filesystems are very interesting components of Linux-like systems. Daily, we create filesystems on device (disk drive partitions). These storage devices are available as device files such as /dev/device_name. Then we mount it at a directory called a mount point. On the other hand, loopback filesystems are those that we create in files rather than a physical device. We can then mount those files as filesystems at a mount point. It is logical disk inside a file on your physical disk.

How I do it? 
Create raw file with "dd" command
$ dd if=/dev/zero of=loopbackfile.img bs=1GB count=1

then I have a 1GB file loopbackfile.img. Then I format this file to ext4 using mkfs command as follows:
$ mkfs.ext4 loopbackfile.img

and create a new directory 
$mkdir /mnt/loopback

mount the loopback file to /mnt/loopback as follows
$ mount -o loop loopbackfile.img /mnt/loopback

option "-o loop" is used to mount loopback filesystems. Also it attaches to a device called /dev/loop1 or loop2.

then I use "df -h" command
/dev/loop0      976M  2,6M  907M   1% /mnt/loopback

finally, I should add "mount -o loop loopbackfile.img /mnt/loopback" to /etc/fstab. Why? because it will follow the system startup and already have the mount point. I could not remember to add it every system boot. Of course, I need to use it as a static partition on this case. If you don't need it, you can ignore this. 

Good luck! 

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

0 nhận xét:

Post a Comment