Skip to content

Instantly share code, notes, and snippets.

@av1d
Created January 7, 2022 22:10
Show Gist options
  • Save av1d/f920ffe55e82cc9981e4f63f3ab8bfaf to your computer and use it in GitHub Desktop.
Save av1d/f920ffe55e82cc9981e4f63f3ab8bfaf to your computer and use it in GitHub Desktop.
Convert IMA floppy disk image to IMG disk image
#!/bin/bash
# Use at your own risk.
# chmod +x IMA2IMG.sh before using.
echo -e "IMA2IMG by av1d"
echo -e "Convert IMA floppy disk image to IMG disk image\n"
echo -e "Also mounts the IMA file in /mnt/floppyIMAdisk for usage"
echo -e "https://gist.github.com/av1d/e27e72795507e1bd29d92172d76e56f5"
if [[ "$1" == "unmount" ]]
then
echo "Unmounting /mnt/floppyIMAdisk"
sudo umount /mnt/floppyIMAdisk
echo "Done."
echo "Attempting to detach loop device /dev/loop234789"
losetup -d /dev/loop234789
losetup -a
echo "Done."
exit
elif [[ "$1" == "--help" || "$1" == "-h" ]]
then
echo "IMA2IMG - run as root."
echo "Usage example: ./IMA2IMG.sh OriginalDisk.IMA ConvertedDisk.IMG unmount"
echo "unmount command is optional. You can unmount and detach loop device afterwards by typing:"
echo "./IMA2IMG unmount"
exit
elif [[ -z "$1" ]]
then
echo "Please specify the IMA file. Type ./IMA2IMG.sh --help for help."
exit
fi
if [[ -z "$2" ]]
then
echo "Please specify the destination IMG file. Type ./IMA2IMG.sh --help for help."
exit
fi
echo "Creating folder in /mnt/floppyIMAdisk ..."
sudo mkdir /mnt/floppyIMAdisk
echo "associating loop device /dev/loop234789 with file \$1"
sudo losetup /dev/loop234789 ./$1
echo "mounting /dev/loop234789 as a vfat partition at /mnt/floppyIMAdisk"
sudo mount -t vfat /dev/loop234789 /mnt/floppyIMAdisk
echo "Creating IMG file"
sudo dd bs=512 count=2880 if=/dev/loop234789 of=$2
echo -e "Done."
if [[ "$3" == "unmount" ]]
then
echo "Unmounting /mnt/floppyIMAdisk"
sudo umount /mnt/floppyIMAdisk
echo "Done."
echo "Attempting to detach loop device /dev/loop234789"
losetup -d /dev/loop234789
losetup -a
echo "Done."
exit
fi
echo -e "Type ./IMA2IMG.sh unmount to unmount /mnt/floppyIMAdisk and detach loop device"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment