How to find the format of a not mounted drive? (Solved)

Using applications, configuring, problems
Post Reply
Message
Author
der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

How to find the format of a not mounted drive? (Solved)

#1 Post by der-schutzhund »

Hi,

i want to mount all drives automatically to mount them in a script.
Do you now how a script can test the format?

With this script i can mount all drives but the ntfs drives are then read only!

Code: Select all

!/bin/bash -a
# Sort out swap and mounted partitions
blkid  | egrep '(hd|sd)' | egrep -v "/dev/loop*" | egrep -v "swap" | cut -f 1 -d ':' | sed 's/\/dev\///'>/tmp/list_of_drives
for drive in  `cat /tmp/list_of_drives` ; do
   mkdir -p /mnt/$drive
   mount /dev/$drive /mnt/$drive
   echo $drive
done 
exit 0
With this i can mount a ntfs but I do not know if it's a ntfs drive or not!

Code: Select all

   mount -t ntfs /dev/$drive /mnt/$drive
The solution: --------------------------------------

Code: Select all

blkid  | egrep '(hd|sd)' | egrep -v "/dev/loop*" | egrep -v "swap" | cut -f 1 -d ':' | sed 's/\/dev\///'>/tmp/list_of_drives
for drive in  `cat /tmp/list_of_drives` ; do
   mkdir -p /mnt/$drive
   if [ "`blkid /dev/$drive | grep -o "TYPE=.*" | cut -f2 -d '"'`" = "ntfs" ]; then
     mount -t ntfs /dev/$drive /mnt/$drive
   else
     mount /dev/$drive /mnt/$drive
   fi
   echo $drive
done  
Special thangs to SFR !

Greetings

Wolfgang
Last edited by der-schutzhund on Mon 04 Mar 2013, 15:27, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

I don't know the reason, and I'm no great specialist, but I believe you need an utility or a group of utilties called "ntfs-3g" to deal with ntfs disk format from a Linux distro.

Best regards.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#3 Post by musher0 »

Incidentally, here's what I did to/with it!

I use it to mount everything. Thanks, guys.

musher0

~~~~~~~~~~~~~~~

Code: Select all

#!/bin/bash -a 
# $MBINS/mount-all-drives.sh
# Sort out swap and mounted partitions
# Auteurs : der-schutzhund, avec l'aide de SFR (D-S/SFR)
# Source : http://murga-linux.com/puppy/viewtopic.php?t=84759, 2013-03-04, 10 h 47.
####
blkid  | egrep '(hd|sd)' | egrep -v "/dev/loop*" | egrep -v "swap" | cut -f 1 -d ':' | sed 's/\/dev\///'>/tmp/list_of_drives 
 for drive in  `cat /tmp/list_of_drives` ; do 
    mkdir -p /mnt/$drive 
    if [ "`blkid /dev/$drive | grep -o "TYPE=.*" | cut -f2 -d '"'`" = "ntfs" ]; then 
      mount -t ntfs /dev/$drive /mnt/$drive >/dev/null 2>&1
    else 
      mount /dev/$drive /mnt/$drive >/dev/null 2>&1
    fi 
    echo $drive 
 done  
Attachments
mount-all-drives.sh.zip
Goes in ~/my-applications/bin
(635 Bytes) Downloaded 211 times
Last edited by musher0 on Wed 10 Jul 2013, 05:04, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

Code: Select all

if [ "`blkid /dev/$drive | grep -o "TYPE=.*" | cut -f2 -d '"'`" = "ntfs" ]; then
can give errors in case of a pre -non-actual format formatted partition .
In such a case blkid might say something like this :

Code: Select all

 /dev/sdb1: UUID="4CC6405D47D90582" SEC_TYPE="vfat" TYPE="ntfs"
Therefore it is needed that there is a space before TYPE in the grep string :

Code: Select all

if [ "`blkid /dev/$drive | grep -o " TYPE=.*" | cut -f2 -d '"'`" = "ntfs" ]; then

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

Thanks, Karl.

I'll keep your edit in mind if something goes wrong. (It hasn't yet, and I use this script at every launch.)

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#6 Post by musher0 »

Hello, all.

Here is an edit to
  • o - include utf-8 reading vfat drives.
    o - Also removed the display of the list of drives, which clogged xerrs.log.
    o - Finally did away with the sed call: another "cut" was sufficient.
Credits are mentioned within the script.

BFN.

musher0

Code: Select all

#!/bin/sh 
# $MBINS/mount-all-drives2.sh
# Modif. par / by musher0, 21 juillet 2013
# de / of 
# $MBINS/mount-all-drives.sh
# Sort out swap and mounted partitions
# Par / by  : der-schutzhund, avec l'aide de SFR (D-S/SFR)
# Source : http://murga-linux.com/puppy/viewtopic.php?t=84759, 2013-03-04, 10 h 47.
####
blkid  | egrep '(hd|sd)' | egrep -v "/dev/loop*" | egrep -v "swap" | cut -f 1 -d ':' | cut -d '/' -f 3 > /tmp/list_of_drives 
# orig. : sed 's/\/dev\///'>/tmp/list_of_drives # modif. par musher0
 for drive in  `cat /tmp/list_of_drives` ; do 
    mkdir -p /mnt/$drive 
# modification par musher0
	A="`blkid /dev/$drive | grep -o "TYPE=.*" | cut -f2 -d '"'`"
    case $A in 
	ntfs) mount -t ntfs /dev/$drive /mnt/$drive >/dev/null 2>&1 ;;
	vfat) mount -t vfat -o iocharset=utf8,codepage=850,shortname=mixed,quiet /dev/$drive /mnt/$drive >/dev/null 2>&1 ;;
# Merci à / Thanks to Médor, http://murga-linux.com/puppy/viewtopic.php?p=712828&sort=lastpost#712828
	*) mount /dev/$drive /mnt/$drive >/dev/null 2>&1 ;;
    esac
#    echo $drive # Pas besoin, encombre xerrs.log. / Not needed, clogs xerrs.log.
 done  
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
ASRI éducation
Posts: 3197
Joined: Sat 09 May 2009, 12:10
Location: France
Contact:

Re: How to find the format of a not mounted drive? (Solved)

#7 Post by ASRI éducation »

der-schutzhund wrote:i want to mount all drives automatically to mount them in a script.
Hello,
Pmsd (Puppy mount storage devices) could be a solution.
http://murga-linux.com/puppy/viewtopic.php?t=87434
Cordialement,

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

#8 Post by RetroTechGuy »

musher0 wrote:I don't know the reason, and I'm no great specialist, but I believe you need an utility or a group of utilties called "ntfs-3g" to deal with ntfs disk format from a Linux distro.

Best regards.

musher0
The other "type" may mount it, but it might mount read-only.
[url=http://murga-linux.com/puppy/viewtopic.php?t=58615]Add swapfile[/url]
[url=http://wellminded.net63.net/]WellMinded Search[/url]
[url=http://puppylinux.us/psearch.html]PuppyLinux.US Search[/url]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#9 Post by musher0 »

Hello, all.

I'd like to share a discovery I made this week-end:
with help from awk, we mount all ext* partitions in 198 bytes!

BFN.

musher0
Attachments
MonterPartitions.zip
Unzip in ~/my-applications/bin, make executable and run.
(507 Bytes) Downloaded 184 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#10 Post by musher0 »

Hello again, puppyists!

This one is even more compact, thanks to awk.

TWYL.

musher0
Attachments
MonterPartitions.zip
(453 Bytes) Downloaded 137 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply