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.
[SOLVED] Formatting Sparse Disk Image
Re: Formatting Sparse Disk Image
`man losetup` might help
Also, I always use qemu-img to create a disk image but I think your method will probably work.
Also, I always use qemu-img to create a disk image but I think your method will probably work.
- AlanBartlett
- Forum Moderator
- Posts: 9345
- Joined: 2007/10/22 11:30:09
- Location: ~/Earth/UK/England/Suffolk
- Contact:
[SOLVED] Formatting Sparse Disk Image
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]
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]
Re: Formatting Sparse Disk Image
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.
Needed to configure the image as loop0, then created the filesystem, and then mount it.
I really appreciate the help.
- AlanBartlett
- Forum Moderator
- Posts: 9345
- Joined: 2007/10/22 11:30:09
- Location: ~/Earth/UK/England/Suffolk
- Contact:
Re: [SOLVED] Formatting Sparse Disk Image
Thank you for reporting back with the method you used.
For posterity, and on your behalf, this thread is marked [SOLVED].
For posterity, and on your behalf, this thread is marked [SOLVED].