You are not logged in.

#1 2008-11-29 20:16:58

madeye
Member
From: Denmark
Registered: 2006-07-19
Posts: 331
Website

Script to mount partition according to filesystem in use

I am trying to make a script that will mount any vfat or ntfs drive as /mnt/windows/c and so on.
Is there a way I can do this?

It must check all drives present in the computer and create the directories in /mnt if they don't exist.

The first step however is just to make it recognise the filesystem and tell me what it is. If someone can help me with that, then I think I can continue the rest on my own afterwards.

The script can be bash, perl or python. It doesn't really matter. However the fewer dependencies I have to install for it to work will be better, as this in the end will be used on a USB rescue system.

Thanks,


MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage

Offline

#2 2008-11-30 11:00:52

gradgrind
Member
From: Germany
Registered: 2005-10-06
Posts: 921

Re: Script to mount partition according to filesystem in use

Here's a snippet I have been using in larch for generating entries in /etc/fstab, you might be able to modify it for your purposes:

# Get all other partitions
sfdisk -d | grep "^/dev/" | sed "s|\(.*\):.*Id=\(..\).*|\1 \2|" | \
    while read dev id; do
        # Ignore if id is "Extended" or "LVM", these are not usable partitions
        if [ "${id}" = "5" -o "${id}" = "8e" ]; then continue; fi
        # See if swap
        if [ "${id}" = "82" ]; then
            printf "%-12s %-12s %-8s defaults,noatime 0     0\n" \
                ${dev} swap swap >>${DEST}
            continue
        fi
        removable=""
        part=$( basename ${dev} )
        if [ $( cat /sys/block/${part:0:3}/removable 2>/dev/null ) -ne 0 ]; then
            removable="_rmv"
        fi
        mountdir=${part}${removable}
        printf "%-12s %-12s %-8s user,noauto,noatime 0     0\n" \
                ${dev} /mnt/${mountdir} auto >>${tmpfile}
        mkdir -p ${MNT}/${mountdir}
    done

It reads the output from 'sfdisk -d' to get the devices and partition types.
You might also like to have a look at blkid, or parted.

Offline

#3 2008-11-30 15:27:43

madeye
Member
From: Denmark
Registered: 2006-07-19
Posts: 331
Website

Re: Script to mount partition according to filesystem in use

Cool. Thanks a lot. I think this is just what I was looking for.


MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage

Offline

Board footer

Powered by FluxBB