Mount an ISO image on a Solaris filesystem with lofiadm

Many software packages can be downloaded in the form of an ISO image. Rather than burning the image to a CD-ROM to access its contents, it is easy to mount the image directly into the filesystem using the lofiadm and mount commands.


Given an ISO image in /export/temp/software.iso, a loopback file device (/dev/lofi/1) is created with the following command:

lofiadm -a /export/temp/software.iso /dev/lofi/1

The lofi device creates a block device version of a file. This block device can be mounted to /mnt with the following command:

mount -F hsfs -o ro /dev/lofi/1 /mnt

These commands can be combined into a single command:

mount -F hsfs -o ro `lofiadm -a /export/temp/software.iso` /mnt

The Conversation

Follow the reactions below and share your own thoughts.

6 Responses to “Mount an ISO image on a Solaris filesystem with lofiadm”

  1. October 16, 2009 at 7:52 pm, FMan said:

    How about how to place this in /etc/vfstab

    Reply

  2. December 04, 2010 at 5:51 am, Michael said:

    thank you

    Reply

  3. June 01, 2011 at 12:51 pm, Lucien Hercaud said:

    mkdir -p /etc/fs/isofile
    cd /etc/fs/isofile
    # Create the files “mount” and umount with contents below
    # mount
    #!/bin/bashif [[ X"$1" = X ]]then        echo isofile usage: mount -F isofile file.iso directory        exit 32else        _iso=$1        shiftfiif [[ X"$1" = X ]]then        echo isofile usage: mount -F isofile file.iso directory        exit 32else        _dir=$1        shiftfi
    [[ ! -r "$_iso" ]] &[[ ! -d "$_dir" ]] &exec /usr/sbin/mount -F hsfs $(/usr/sbin/lofiadm -a $_iso) $_dir# umount
    #!/bin/bashif [[ X"$1" = X ]]then        echo isofile usage: umount ‘{special | mount-point | isofile}’        exit 32fi
    if [[ -d $1 ]]then        _lofi=$(/usr/sbin/mount | nawk -v _d=$1 ‘{ if ($1==_d) print $3}’)        /etc/fs/isofile/_umount $1 && /usr/sbin/lofiadm -d $_lofi        exit $?elif [[ -L $1 ]]then        case $1 in        /dev/lofi/*)                _lofi=$1                _dir=$(/usr/sbin/mount | nawk -v _l=$1 ‘{ if ($3==_l) print $1}’)                /etc/fs/isofile/_umount $_dir && /usr/sbin/lofiadm -d $1                ;;        *)                /etc/fs/isofile/_umount $1        esacelif [[ -f $1 ]] && [[ -s $1 ]]then        _lofi=$(/usr/sbin/lofiadm $1 2>/dev/null)        [[ X"$_lofi" = X ]] &        _dir=$(/usr/sbin/mount | nawk -v _l=$_lofi ‘{ if ($3==_l) print $1}’)        /etc/fs/isofile/_umount $_dir && /usr/sbin/lofiadm -d $1else        echo isofile ERROR: No such file, mount-point or lofi device $1        exit 33fi# compile the file below as: ”gcc -m32 -o _umount _umount.c”
    #include #include main(int ac, char *av[]){        int r;        r=umount(av[1]);        if (-1 ==r) {                perror(“umount”);                exit(33);        }        exit(0);}
    # Then use it as :
    # mount -F isofile /jumpstart/isos/sol-10-u9-ga-x86-dvd.iso /mnt
    # /etc/fs/isofile/umount /jumpstart/isos/sol-10-u9-ga-x86-dvd.iso

    Reply

    • June 01, 2011 at 12:54 pm, Lucien Hercaud said:

      Hmmm … the lines did not wrap up

      Here it is again :

      mkdir -p /etc/fs/isofilecd /etc/fs/isofile# Create the files “mount” and “umount” with the contents below### mount:#!/bin/bashif [[ X"$1" = X ]]thenecho isofile usage: mount -F isofile file.iso directoryexit 32else_iso=$1shiftfiif [[ X"$1" = X ]]thenecho isofile usage: mount -F isofile file.iso directoryexit 32else_dir=$1shiftfi[[ ! -r "$_iso" ]] &[[ ! -d "$_dir" ]] &exec /usr/sbin/mount -F hsfs $(/usr/sbin/lofiadm -a $_iso) $_dir### umount:#!/bin/bashif [[ X"$1" = X ]]thenecho isofile usage: umount ‘{special | mount-point | isofile}’exit 32fiif [[ -d $1 ]]then_lofi=$(/usr/sbin/mount | nawk -v _d=$1 ‘{ if ($1==_d) print $3}’)/etc/fs/isofile/_umount $1 && /usr/sbin/lofiadm -d $_lofiexit $?elif [[ -L $1 ]]thencase $1 in/dev/lofi/*)_lofi=$1_dir=$(/usr/sbin/mount | nawk -v _l=$1 ‘{ if ($3==_l) print $1}’)/etc/fs/isofile/_umount $_dir && /usr/sbin/lofiadm -d $1;;*)/etc/fs/isofile/_umount $1esacelif [[ -f $1 ]] && [[ -s $1 ]]then_lofi=$(/usr/sbin/lofiadm $1 2>/dev/null)[[ X"$_lofi" = X ]] &_dir=$(/usr/sbin/mount | nawk -v _l=$_lofi ‘{ if ($3==_l) print $1}’)/etc/fs/isofile/_umount $_dir && /usr/sbin/lofiadm -d $1elseecho isofile ERROR: No such file, mount-point or lofi device $1exit 33fi### compile the file below as: “gcc -m32 -o _umount _umount.c”### _umount.c:#include #include main(int ac, char *av[]){int r;r=umount(av[1]);if (-1 ==r) {perror(“umount”);exit(33);}exit(0);}### Then use it as :# mount -F isofile /jumpstart/isos/sol-10-u9-ga-x86-dvd.iso /mnt# /etc/fs/isofile/umount /jumpstart/isos/sol-10-u9-ga-x86-dvd.iso### Can also be added to /etc/vfstab as :/jumpstart/isos/sol-10-u8-ga-x86-dvd.iso – /mnt isofile – yes -### To totally unmount and free the lofi device, please always care to use the “/etc/fs/isofile/umount” command

      Reply

  4. March 20, 2012 at 8:11 am, ashrayer said:

    Thanks, it is really helpful;)

    Reply

  5. October 24, 2012 at 7:44 pm, Prince said:

    aic12898:root lofiadm -a /var/tmp/sol-10-u10-ga-sparc-dvd.iso /mnt/iso
    lofiadm: size of /var/tmp/sol-10-u10-ga-sparc-dvd.iso is not a multiple of 512

    Reply

Leave a Reply