Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to partition raw disk image with the following commands

#creating the blank image
$ dd if=/dev/zero of=example.img bs=1M count=50

#write the partition table
$ parted example.img mktable msdos

#creating partition but not the file system
#creating fat32 primary partition 1 to 15 MB
$ parted example.img mkpart p fat32 1 15
#creating ext3 primary partition 16 to end
$ parted example.img mkpart p ext3 16 -0

These command doesn't create file system. How could I do that? I am trying the mkfs command in parted but it is showing no command found. How could I create file system externally?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Use the command kpartx to create a loopback device that can then be formatted.

kpartx -a /path/to/imagefile.img  # Presents partitions from the image file
mkfs.vfat /dev/mapper/loop0p1   # Format partition 1
mkfs.ext3 /dev/mapper/loop0p2   # Format partition 2
kpartx -d /path/to/imagefile.img  # Unmaps the partitions from the image file

Related kpartx examples here

share|improve this answer
    
perfectly worked for me.. thanks –  Shantanu Banerjee Nov 5 '12 at 15:01
add comment

With the usual mkfs commands, such as mkfs.ext4. You will need to use losetup to associate a loopback device with the file though in order to have somewhere to point mkfs to. You also may need to use partprobe to recognize the partitions on the loop device.

share|improve this answer
    
thank you... good explanation ... –  Shantanu Banerjee Nov 5 '12 at 15:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.