Page 1 of 1
Making bochs disk image with partitions
Posted: Tue Mar 14, 2023 11:09 am
by Matt1223
Do you know any easy to use tool that can create partitions on bochs raw disk images?
Re: Making bochs disk image with partitions
Posted: Tue Mar 14, 2023 11:54 am
by Octocontrabass
Raw disk images are not specific to Bochs. Any tool that can handle raw disk images will work.
For example,
Parted.
Re: Making bochs disk image with partitions
Posted: Tue Mar 14, 2023 1:43 pm
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.
Re: Making bochs disk image with partitions
Posted: Wed Mar 15, 2023 11:35 am
by Matt1223
Thanks MichaelPetch! It was very useful.
Re: Making bochs disk image with partitions
Posted: Sun Mar 26, 2023 5:55 am
by Matt1223
Is there a way to format partition as bare bones FAT32 and not vFAT on linux?
Re: Making bochs disk image with partitions
Posted: Sun Mar 26, 2023 9:44 am
by iansjack
What do you mean by “barebones FAT32”?
Re: Making bochs disk image with partitions
Posted: Sun Mar 26, 2023 2:09 pm
by Matt1223
iansjack wrote:What do you mean by “barebones FAT32”?
I mean a FAT32 system that does not use long file names extension.
Re: Making bochs disk image with partitions
Posted: Sun Mar 26, 2023 2:24 pm
by iansjack
That’s a function of the file system driver that writes/reads the disk, not the way it is formatted.
Re: Making bochs disk image with partitions
Posted: Sun Mar 26, 2023 10:54 pm
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.