[TAG] Virtual Hard Disks
Thomas Adam
thomas.adam22 at gmail.com
Wed Jan 14 22:41:05 MSK 2009
2009/1/14 Michael SanAngelo <msanangelo at gmail.com>:
> Hi, I was wondering what are the possibilities of creating and using virtual
> disks for. I understand I can use dd to create it then mkfs.ext3 or
> something like it to format the disk. What purpose could they be used for
> besides serving as a foundation for creating a live cd?
>
> I want to do this from the cli so no gui.
The term "virtual disk" is misleading here -- what you're referring to
are essentially loopback files, a la:
```
dd if=/dev/zero of=/somefile bs=1024 count=300000
'''
That will create a 30GiB zero-filled file called "somefile".
Then what you want to do with that is attach a loopback device to the file:
```
losetup /dev/loop0 /somefile
'''
(It may well be that /dev/loop0 is in use -- there are up to 8 loopback devices:
```
/dev/loop{1,2,3,4}
'''
Use whichever is available.)
Then create a filesystem on it:
```
mkfs -t ext3 -m 1 -v /dev/loop0
'''
(Replacing "/dev/loop0 if applicable with the above.)
Then you can mount it somewhere:
```
mount -t ext3 /dev/loop0 /mnt
'''
(Replacing "/dev/loop0 if applicable with the above.)
Do stuff under /mnt as you would with a normal directory then when you're done:
```
umount /mnt
losetup -d /dev/loop0
'''
(Replacing /dev/loop0 if applicable.)
-- Thomas Adam
More information about the TAG
mailing list