[SOLVED] Formatting Sparse Disk Image

If it doesn't fit in another category, ask it here.
Post Reply
mattxhand
Posts: 2
Joined: 2011/09/21 17:24:28
Location: USA

[SOLVED] Formatting Sparse Disk Image

Post by mattxhand » 2011/09/21 17:32:23

I have been tasked with a project at work. The task is to 1)create a sparse disk image 2)format the image to ext3 3)mount the image 4)place a file on the new image.

Currently I am am stuck on the part where I format the disk image. So far, this is as far as I have gotten:

#Creating the image
dd if=/dev/null of=fubar.img bs=1 count=1 seek=2G

Any help is appreciated.

User avatar
TrevorH
Forum Moderator
Posts: 26971
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Formatting Sparse Disk Image

Post by TrevorH » 2011/09/21 19:46:52

`man losetup` might help

Also, I always use qemu-img to create a disk image but I think your method will probably work.

User avatar
AlanBartlett
Forum Moderator
Posts: 9323
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

[SOLVED] Formatting Sparse Disk Image

Post by AlanBartlett » 2011/09/21 20:06:49

Welcome to the [i]CentOS[/i] fora.

The recommended reading for all new members starts with the [url=https://www.centos.org/modules/newbb/viewforum.php?forum=47]FAQ & Readme First[/url].

As to task you have been asked to achieve, a brief, quick hint is --

[code]
[b]man mkfs[/b]
[/code]
A somewhat more verbose hint is --

[code]
[ajb@GX1 tmp]$ dd if=/dev/null of=fubar.img bs=1 count=1 seek=2G
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000126929 seconds, 0.0 kB/s
[ajb@GX1 tmp]$ ll
total 56
-rw-r----- 1 ajb ajb 2147483648 Sep 21 20:46 fubar.img
[i]<snip>[/i]
[ajb@GX1 tmp]$ file fubar.img
fubar.img: data
[ajb@GX1 tmp]$ sudo /sbin/mkfs -t ext3 fubar.img
mke2fs 1.39 (29-May-2006)
fubar.img is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[ajb@GX1 tmp]$ ll
total 99400
-rw-r----- 1 ajb ajb 2147483648 Sep 21 20:47 fubar.img
[i]<snip>[/i]
[ajb@GX1 tmp]$ file fubar.img
fubar.img: Linux rev 1.0 ext3 filesystem data (large files)
[ajb@GX1 tmp]$ sudo mount -o loop -t ext3 fubar.img /mnt
[ajb@GX1 tmp]$ mount
[i]<snip>[/i]
/tmp/fubar.img on /mnt type ext3 (rw,loop=/dev/loop0)
[ajb@GX1 tmp]$ ll /mnt
total 16
drwx------ 2 root root 16384 Sep 21 20:46 lost+found
[ajb@GX1 tmp]$ cat > little_file.txt
Hello, world. This is little_file's contents.
[ajb@GX1 tmp]$ cat little_file.txt
Hello, world. This is little_file's contents.
[ajb@GX1 tmp]$ sudo cp little_file.txt /mnt
[ajb@GX1 tmp]$ ll /mnt
total 24
-rw-r----- 1 root root 46 Sep 21 20:54 little_file.txt
drwx------ 2 root root 16384 Sep 21 20:46 lost+found
[ajb@GX1 tmp]$ sudo umount /mnt
[ajb@GX1 tmp]$ mount
[i]<snip>[/i]
[ajb@GX1 tmp]$
[/code]

mattxhand
Posts: 2
Joined: 2011/09/21 17:24:28
Location: USA

Re: Formatting Sparse Disk Image

Post by mattxhand » 2011/09/21 22:04:04

Thanks guys, but I solved it.

Needed to configure the image as loop0, then created the filesystem, and then mount it.

I really appreciate the help.

User avatar
AlanBartlett
Forum Moderator
Posts: 9323
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: [SOLVED] Formatting Sparse Disk Image

Post by AlanBartlett » 2011/09/22 01:47:06

Thank you for reporting back with the method you used.

For posterity, and on your behalf, this thread is marked [SOLVED].

Post Reply

Return to “CentOS 5 - Miscellaneous Questions”