Managing iso files in Linux

This is a small workaround I came up with to mount/unmount iso image files in #!. Iso files are great to work with be it the os installer or back up of your dvd/cd data. By default you would read them with the archive manager, but that makes it cumbersome since you have to extract each file before you can work with it.

A better approach is to mount the iso file to some location and work with its content there. A simple cli command will help you do it. And to make things more convenient, i created basic shell scripts which help me manage the iso files that i have to work with.

The idea is to mount the iso at a known location after doing some basic checks like whether the file argument provided is an iso, is the mount point location available for use etc.

Here’s the script for mounting an iso file.


#! /bin/sh
clear
if [ $# -eq 0 ]
then
echo "No iso file provided"
echo "Usage ::"
echo "isomount <file-name.iso>"
exit 0
fi
if [ $1 = '--help' ]
then
echo "Usage ::"
echo "isomount <file-name.iso>"
exit 0
fi
if [ ! -f $1 ]
then
echo "File $1 does not exist"
exit 0
fi
fileNameLength=`expr length $1`
start=`expr $fileNameLength - 2`
fileExt=`expr substr $1 $start $fileNameLength`
if [ $fileExt != "iso" -a $fileExt != "ISO" ]
then
echo "File not a valid iso"
exit 0
fi
if [ ! -d ~/iso-mount ]
then
echo "Mount directory is missing. Creating one..."
mkdir ~/iso-mount
fi
echo "Mounting file "$1"..."
sudo mount -o loop $1 ~/iso-mount/
thunar ~/iso-mount/ &

If the checks are valid then the iso file gets mounted at /home/<user>/iso-mount/. And the file manager opens the mount location for immediate use.

To unmount the iso, the script simply issues a umount command like so –

#! /bin/sh
echo "Attempting unmounting ~/iso-mount"
fileCount=`ls ~/iso-mount/ | wc -l`
if [ $fileCount -eq 0 ]
then
echo "Mount point seems already unmounted"
echo "Nothing needs to be done"
exit 0
fi
sudo umount ~/iso-mount/
echo Done

I have saved these scripts at location /usr/bin with executable rights and root previledge.

koolksp@crunchbang:~$ ls -l /usr/bin/iso*
-rwxr-xr-x 1 root root 606 Apr 30 08:44 /usr/bin/isomount
-rwxr-xr-x 1 root root 241 Dec 24 22:52 /usr/bin/isounmount

See them in action –

koolksp@crunchbang:~$ isomount openSUSE-13.1-GNOME-Live-i686.iso
Mounting file openSUSE-13.1-GNOME-Live-i686.iso...

And the files open up in Thunar the file manager for #!

For unmounting simply execute the isounmount script.

koolksp@crunchbang:~$ isounmount
Attempting unmounting iso-mount
Done

My Linux Arsenal

Think of it as a must have tool kit. Tools and softwares and live cds, each one to deal with specific things when you have to upgrade/reinstall/recover your Linux installation.

Quick Checklist

  1. Live cd of your favorite distro ( Yep thats #! for now )
  2. Min 2Gb pen drive to make a usb bootable distro ( Why make dvd coasters!!?? )
  3. Gparted Live cd – for any partition related work
  4. CloneZilla Live cd – for backing up existing partitions
  5. Puppy Linux – My favorite recovery disk. Although any live cd works as well

Scenario 1 – Distro hopping.
So you got bored of whatever was installed earlier and want to move to the latest and greatest distro out yet! Installing the distro over the entire disk space is definitely a bad idea. But if you must do so, try and create separate partitions for root (/) and home (/home). That way you leave all the data in /home and install the system files at root (/). Next time you plan to install another distro, just select install partition as root (/). The data in /home would be intact. This also makes it easy to back up only the system partition and not the entire disk using clonezilla. When the new system is installed create users with same name as before and their respective files under /home/ will be available for use. Creating a bootable USB is better than burning dvds which probably aren’t of much use after the system is installed.

Scenario 2 – Managing partitions
Although any linux installation will allow you to partition the disk before continuing, sometimes it makes sense to start with a clean slate. Delete everything thats there on the disk and start the installation process afresh. In this case Gparted live cd will help to manage/delete/resize partition. For installtion over windows, better to delete all partitions and then create appropriate partitions during installation.

Scenario 3 – Backup – Better safe than sorry
You are the best judge of your data. Whether or not to backup is really up to the individual. But imagine the pain to start from scratch, if your full fledged distro installation with several tweaks, fonts, themes, icons and software were to be doomed. Backing up partition ( if not the entire disk ) with clonezilla is a wise move. If something goes wrong, like a software installation goes rogue or an upgrade tanks, you can fall back to previous working state by restoring partition image with Clonezilla. A monthly back up frequency would be a good idea with backups for upto 3 months. Anything older than that would be too outdated to restore back.

Scenario 4 – Oops something bad happened
Believe it or not, with bad luck on your side, you may see your system unable to boot. Reasons could be many, but the damage is already done. For salvaging data off your disk, you could use any live cd to boot into the machine, connect an external HDD and start copying off data. Puppy Linux is my favorite here. Its nifty and does the job pretty fast.

That sums it up. A quick list of things I’d like to keep handy in case I am messing up with my current installation.