1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
mkdir -p /etc/fs/isofile
cd /etc/fs/isofile
# Create the files "mount" and "umount" with the contents below
### mount:
#!/bin/bash
if [[ X"$1" = X ]]
then
echo isofile usage: mount -F isofile file.iso directory
exit 32
else
_iso=$1
shift
fi
if [[ X"$1" = X ]]
then
echo isofile usage: mount -F isofile file.iso directory
exit 32
else
_dir=$1
shift
fi
[[ ! -r "$_iso" ]] && {
echo isofile ERROR: No such file $_iso
exit 33
}
[[ ! -d "$_dir" ]] && {
echo isofile ERROR: No such directory $_dir
exit 33
}
exec /usr/sbin/mount -F hsfs $(/usr/sbin/lofiadm -a $_iso) $_dir
### umount:
#!/bin/bash
if [[ X"$1" = X ]]
then
echo isofile usage: umount '{special | mount-point | isofile}'
exit 32
fi
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
esac
elif [[ -f $1 ]] && [[ -s $1 ]]
then
_lofi=$(/usr/sbin/lofiadm $1 2>/dev/null)
[[ X"$_lofi" = X ]] && {
echo isofile ERROR: No lofi device for $1
exit 33
}
_dir=$(/usr/sbin/mount | nawk -v _l=$_lofi '{ if ($3==_l) print $1}')
/etc/fs/isofile/_umount $_dir && /usr/sbin/lofiadm -d $1
else
echo isofile ERROR: No such file, mount-point or lofi device $1
exit 33
fi
### compile the file below as: "gcc -m32 -o _umount _umount.c"
### _umount.c:
#include <sys/mount.h>
#include <stdio.h>
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 |
Partager