IBM Support

Creating a disk image from a folder

Question & Answer


Question

How can I turn a folder into a disk image?

Answer

As an administrator, you want to be able to turn a folder of various maintenance scripts into a disk image so that you can mount it on a linux server. This gives you more control over the availability of this directory and the permissions to it.

If you have a folder of scripts that you want to be able to mount on multiple systems, you can turn it into a disk image. This document outlines the steps to do this.

The following example shows how to turn a folder called dba (which contains scripts used for maintenance of the NPS system) into a disk image. 

1. First, create a directory to hold the resulting disk image:

mkdir /usr/disk-img-for-dba-filesystem/
cd /usr/disk-img-for-dba-filesystem/


2. Next, create a file to hold the file system.  In this example the count is 768000 kilobytes or 750 MB.

dd if=/dev/zero of=dba.ext3 bs=1024 count=768000

3. Use the losetup command to associate loop devices with regular files or block devices.  The following command sets up loop0 and attaches it to the file created in the previous step:

losetup /dev/loop0 dba.ext3


4. Now put an ext3 file system on that looped device.  (You could format this using other file systems as well.)

mkfs.ext3 /dev/loop0


5. Mount the formatted device to /mnt:

mount /dev/loop0 /mnt


6. Now you can copy the folder contents (which are located in /tmp/dba) to this new mount:

cp -a /tmp/dba/* /mnt


7. Unmount from /mnt:

umount /mnt


8. Now detach the loop0 device:

losetup -d /dev/loop0



The file dba.ext3 is now a disk image which can be mounted manually or added to your fstab for mounting when the server boots.  For example, you could add the following to /etc/fstab to indicate that you want the disk image to be mounted under /dba on the server: 


/usr/disk-img-for-dba-filesystem/dba.ext3    /dba ext3    rw,loop,usrquota,grpquota 0 0



You can then mount the image by running the following command:

mount /dba 


The dba.ext3 disk image can then be moved to other servers and mounted accordingly.  This allows a little more versatility and portability to your directory.

[{"Product":{"code":"SSULQD","label":"IBM PureData System"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":null,"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"1.0.0","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

NZ348381

Document Information

Modified date:
17 October 2019

UID

swg21571703