-
Notifications
You must be signed in to change notification settings - Fork 13
/
mnt-image
executable file
·59 lines (50 loc) · 1016 Bytes
/
mnt-image
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
#!/bin/bash
set -e
if [[ "$OSTYPE" != linux* ]]; then
echo "Not on a Linux box; aborting."
exit 1
fi
if [[ `id -u` != 0 ]]; then
echo "Not root; aborting."
exit 1
fi
if [[ $# != 1 && $# != 2 ]]; then
echo "Usage: $0 <floppy image> [ <mount point> ]"
exit 1
fi
MNTROOT=/mnt/initrd
mkdir -p $MNTROOT
if ! [ -d $MNTROOT ]; then
echo "Couldn't mkdir -p $MNTROOT" >&2
exit 1
fi
img=$1
imgbase=${1##*/}
mnt=${2:-$MNTROOT/$imgbase}
absmnt="`abs $mnt`"
if mount | egrep -q "$absmnt"; then
echo "Something already mounted on $absmnt! Aborting."
exit 1
fi
[[ -d $mnt ]] || mkdir -p $mnt
fs="`file $img`"
case "$fs" in
*FAT*)
fstype=msdos ;;
*ext2*)
fstype=ext2 ;;
*)
echo -e "Image $img had unknown filesystem!\n$fs"
exit 1 ;;
esac
echo "$img image type: $fstype"
if mount -o loop -t $fstype $img $mnt; then
echo Mounted $img on $mnt
else
echo -n "Retrying read-only ... "
if ! mount -o loop,ro -t $fstype $img $mnt; then
echo failed.
else
echo ok.
fi
fi