Tag: mount

  • Linux – Mount Bind

    An example of mounting with bind.
    mount --bind Folder NewFolder

  • Create a filesystem in a file

    Some times you need a new filesystem, for testing purposes or for whatever and you dont have access to a physical device. You can create a filesystem within  a file as follows:

    dd if=/dev/zero of=myfsys bs=512M count=1 # creating a 512M zeros file
    mke2fs myfilesys # creating a file system out of the file

    mount myfilesys /mnt -o loop=/dev/loop0 # mounting it as a loop device

    mkdir /mnt/point1 # creating a mount point
    mount /dev/loop0 /mnt/point1 # mounting

    df /mnt/point1/ # its alive!

    # results with:
    # Filesystem 1K-blocks Used Available Use% Mounted on
    # /dev/loop0 516040 400 489428 1% /mnt/point1

  • Mount Share Network Event Triggered Bash Script

    What this script does is, check the gateway mac address to find out if you are within your lan or in a different place. If at home, mount a share as normal. If away, mount that share as a ssh file system.

    #!/bin/bash
    gateway=$(ip route show 0.0.0.0/0 | awk '{print $3}')
    mactest=$(arp -n -a $gateway | awk '{print $4}')
    targetmac="XX:XX:XX:XX:XX:XX"
    homeup="mount -t cifs -o username=USER,password=PASSWORD //SERVER/SHARE /mnt/remote"
    awayup="sshfs my.dyndns.tld:/path/to/share /mnt/remote"
    down="umount -l /mnt/remote"
    if [ $mactest==$targetmac ]
    then
    case "$2" in
    up)
    $homeup
    ;;
    down)
    $down
    ;;
    esac
    else
    case "$2" in
    up)
    $awayup
    ;;
    down)
    $down
    ;;
    esac
    fi

    exit $?