Making bochs disk image with partitions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Matt1223
Member
Member
Posts: 45
Joined: Mon Jul 30, 2018 2:58 am

Making bochs disk image with partitions

Post by Matt1223 »

Do you know any easy to use tool that can create partitions on bochs raw disk images?
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Making bochs disk image with partitions

Post by Octocontrabass »

Raw disk images are not specific to Bochs. Any tool that can handle raw disk images will work.

For example, Parted.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making bochs disk image with partitions

Post by MichaelPetch »

As Octo suggests `parted` is a good tool. You can specify a file name of an image to partition as well as a device. If you are using Linux you could create a disk image (example 100MiB) with `dd if=/dev/zero of=disk.img bs=1M count=100` . Once you have the disk image you can use parted (or fdisk, or if you want to make partition creation scriptable - sfdisk) specifying the file. Something like: `parted disk.img` . Once it is partitioned you can map the partitions with a loop back device with kpartx. kpartx will look at a specified image and create mapper entries in /dev/mapper for each partition. `sudo kpartx -av disk.img` will do the device mappings. It will print out the partition names and the mapped loop device it is on. In my case it says loop0p1 and loop0p2. You can find the device names in /dev/mapper if it worked as expected.

With partitions now mapped into /dev/mapper you can use those like you'd specify hard drive and floppy device.

If you partitioned and set the type of partition to ext2/Linux (ie partition 1) then you can format it with `sudo mkfs.ext4 /dev/mapper/loop0p1`. You can mount that formatted partition and copy files into it. Make a mount point with `mkdir mnt` (mount point will be a director called `mnt` in current directory) and then mount it the partition to the mount point with `sudo mount /dev/mapper/loop0p1 mnt'. You can then copy files into the mnt directory and they will be wriitten to the disk image. When you have finished copying/adding/deleting/etc files in the mnt directory you have to unmount it with `sudo umount mnt`. Once you are finished with the mapped partitions you can remove the device mappings on a loop device with `sudo kpartx -d /dev/loopX` where X is the loop number used for mapping. You can then disconnect the /dev/loopX device from the image with `sudo losetup -d /dev/loopX` (again X is the device mapped that was used to map to.
Matt1223
Member
Member
Posts: 45
Joined: Mon Jul 30, 2018 2:58 am

Re: Making bochs disk image with partitions

Post by Matt1223 »

Thanks MichaelPetch! It was very useful.
Matt1223
Member
Member
Posts: 45
Joined: Mon Jul 30, 2018 2:58 am

Re: Making bochs disk image with partitions

Post by Matt1223 »

Is there a way to format partition as bare bones FAT32 and not vFAT on linux?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Making bochs disk image with partitions

Post by iansjack »

What do you mean by “barebones FAT32”?
Matt1223
Member
Member
Posts: 45
Joined: Mon Jul 30, 2018 2:58 am

Re: Making bochs disk image with partitions

Post by Matt1223 »

iansjack wrote:What do you mean by “barebones FAT32”?
I mean a FAT32 system that does not use long file names extension.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Making bochs disk image with partitions

Post by iansjack »

That’s a function of the file system driver that writes/reads the disk, not the way it is formatted.
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: Making bochs disk image with partitions

Post by sounds »

Matt1223 wrote:Is there a way to format partition as bare bones FAT32 and not vFAT on linux?
Matt1223, I agree with your use of the terminology.

That is to say, FAT32 is a variant of the FAT filesystems that uses a 32 bit cluster - reference: https://en.wikipedia.org/wiki/File_Allo ... able#FAT32

And vFAT is a means of storing longer filenames in a FAT directory - reference: https://en.wikipedia.org/wiki/File_Allo ... Table#VFAT

However, to attempt to answer your question is tricky because while I get what you're asking, the VFAT extension works on FAT16 and FAT32 filesystems, and is invisible to an OS that is not aware of it. VFAT was introduced with Windows 95 in 1995, and FAT32 was introduced in Windows 95 OSR2 in 1996. Hence it isn't exactly a supported use of FAT32 if what you want is FAT32 which prohibits somehow the use of VFAT filenames.

I actually think you're simply asking how to set up a FAT32 filesystem that doesn't use VFAT at all. That's quite simple: stick to only 8.3 filenames and uppercase characters. VFAT does nothing to filenames if they stick to the restrictions of the original FAT directory entry.
Post Reply