LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-01-2013, 03:59 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
Create a virtual harddisk using dd ?


Hi,

Usually I created my harddisk using the qemu-img.
Code:
qemu-img create virtdisc.img 1G
In the past, I did simply use :
dd
cfdisk
and mkfs.vfat.

However I absolutely cannot find using google on the web.
I really think that I made it but how...
Impossible to find back


Would you know how to create a virtual image of free
formated harddisk of 1gb as the above alternative technique?

Thank you in advance
 
Old 12-01-2013, 05:15 AM   #2
mjolnir
Member
 
Registered: Apr 2003
Posts: 815

Rep: Reputation: 99
http://www.adayinthelifeof.nl/2011/1...l-disk-images/

This guy uses fdisk and "dd".

"There are multiple ways to do this, but one of the easiest methods is to use either “dd” or “bximage”. The latter one is a tool from the Bochs Emulator that can create disks."

"Another way is to use the “dd” utility that comes on most unix/linux systems:

dd if=/dev/zero of=hdd.img bs=1024 count=10240"

"Partition the image through fdisk
Now that we have a completely blank file (or virtual disk), we need to partition it just like any other disk. The “fdisk” utility it the way to go here, and there is nothing different between creating partitions on a virtual disk than it is on a physical one.

fdisk hdd.img
I’ve added a bunch of partitions (again: I’m testing my OS here, so it needs to be able to handle stuff like extended partitions etc). Just make sure you set the correct settings for your cylinders, heads and sectors-per-track in the fdisk menu. They are located in the “Expert menu” through “x”. I’ve added a big 5MB partition for Linux, a small 2MB partition for dos/fat16, another 1.5MB for linux, and a-little-bit-less-than-1MB partition for Linux, but I’ve put the last one inside an extended partition:

# fdisk -l -u hdd.img -C 20 -H 16 -S 63

Disk hdd1.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 20 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x839d4362

Device Boot Start End Blocks Id System
hdd.img1 63 10079 5008+ 83 Linux
hdd.img2 10080 15119 2520 6 FAT16
hdd.img3 15120 18143 1512 83 Linux
hdd.img4 18144 20159 1008 5 Extended
hdd.img5 18207 20159 976+ 83 Linux"

"Format the partitions
At this point you are able to format the partitions. Again, just like any physical partition.

# mkfs.ext2 /dev/loop1
# mkdosfs /dev/loop2
# mkfs.ext2 /dev/loop3
# mkfs.ext2 /dev/loop5"

He's making loop-back devices but you can adapt it too your needs.

Last edited by mjolnir; 12-01-2013 at 05:16 AM.
 
Old 12-02-2013, 07:05 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
Some of the pen drive pages offer ways but I think above has covered the basics.


Qemu-img can also create format specific virtual hard drives, a qcow2 or soon to be qcow3 has some advantages. An unfilled qcow2 is about 2 seconds of time where the dd has to fill the entire area bit by bit.
 
Old 12-03-2013, 06:47 PM   #4
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Quote:
Originally Posted by jefro View Post
Some of the pen drive pages offer ways but I think above has covered the basics.


Qemu-img can also create format specific virtual hard drives, a qcow2 or soon to be qcow3 has some advantages. An unfilled qcow2 is about 2 seconds of time where the dd has to fill the entire area bit by bit.
Qemu-img, bximage, ... but still, with dd is must be possible. I have written down somewhere how (maybe).
 
Old 12-04-2013, 07:23 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
I think this is correctly reported by mjolnir,


dd if=/dev/zero of=hdd.img bs=1024 count=10240"


If not see this too. http://lnx.cx/docs/vdg/output/Virtua...pts-Running-dd
 
Old 12-05-2013, 07:30 AM   #6
mjolnir
Member
 
Registered: Apr 2003
Posts: 815

Rep: Reputation: 99
@jefro Nice link.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to create second virtual IP? sam_nyc Linux - Newbie 3 04-20-2012 12:24 PM
Is it possible to create a virtual LAN on my machine using virtual box or MS virtula nhammoud Linux - Networking 1 01-27-2011 03:49 PM
how to create virtual terminals anubhuti_k AIX 1 02-08-2006 12:03 AM
How to create dual boot in two harddisk tkt Linux - Newbie 5 05-16-2005 01:46 AM
Vmware and its virtual harddisk! Stealth870 Linux - General 1 03-12-2005 09:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration