How do I grep to find /dev/first-drive-shown-on-the-desktop-probably-an-ntfs-volume and auto-mout it rw to /somemountpoint, no matter if it's an ntfs or fatxx filesystem?
Printable View
How do I grep to find /dev/first-drive-shown-on-the-desktop-probably-an-ntfs-volume and auto-mout it rw to /somemountpoint, no matter if it's an ntfs or fatxx filesystem?
Quote:
Originally Posted by unclecameron
All file systems and hard drive partitions can be mounted automatically by knoppix just by clicking on them from the default kde desktop.
The drives will be shown in partition order so first partition will be hda1 or sda1 depending on if your HD is IDE or SATA.
With knoppx 5.1.1 and higher open a terminal and type:
sudo fdisk -l
(this will list all partitions on all hard drives).
I'm attempting to make a script I'm running on boot do it, so I know knoppix finds the most likely candidate and lists it on the desktop, I need to grep that, then I can mount it in the script hopefully, or possibly having something automount it.
Ok, I misread your question.Quote:
Originally Posted by unclecameron
In Kde autostart programs run from ~/.kde/Autostart
this is where you can start your script:
For starters someting like:
#!/bin/sh
cd /home/knoppix/Desktop
ls | grep sd > drivelist
# above line creates a list of drive from icons on desktop grep sd is for sata use hd for ide
cat drivelist | while read line;
do
mount /dev/${line} -t ntfs /mnt/sda1
# above line reads each entry in drivelist and mounts it, will need some work as it will fail if more than 1 drive detected
done
You'll need to modify this as it will fail if multiple drives detected, however if its always one partition like a C: drive it will alsmost always
be the first partition so you may get away with simplifying the script.
Im not much of a bash programmer so you may need to ask on a bash forum
Hope that helps
ok great, thanks, I'll hack together something based on what you posted :)
I also found that knoppix puts the drives found on the end of fstab, so a typical setup detecting one ntfs, one ext3 and one swap (this my test box, no one would ever be doing this to an ext3/swap, but possibly a FAT16/32)
so I have to figure out how to write a loop to grep for "# Added by KNOPPIX", then cut the 1st 9 characters off the next line and mount that, then repeat. I'm guessing I can just use mount $somevariable /mountlocation and knoppix will detect the fs type, that would make it a bit simpler. I know there are a number of ways to do this type of a loop, not sure what would be the simplest...Code:/proc /proc proc rw,nosuid,nodev,noexec 0 0
/sys /sys sysfs rw,nosuid,nodev,noexec 0 0
/dev/shm /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0
/dev/pts /dev/pts devpts mode=0622 0 0
/dev/fd0 /media/fd0 auto user,noauto,exec,umask=000 0 0
/dev/cdrom /media/cdrom auto user,noauto,exec,ro 0 0
/dev/hdc /media/hdc auto users,noauto,exec,ro 0 0
# Added by KNOPPIX
/dev/sda1 /media/sda1 ntfs noauto,users,exec,umask=000,uid=knoppix,gid=knoppix 0 0
# Added by KNOPPIX
/dev/sda2 /media/sda2 ext3 noauto,users,exec 0 0
# Added by KNOPPIX
/dev/sda3 none swap defaults 0 0
ok, I have done this, and it ALMOST works :)
the problem is knoppix needs a filesystem type, so now I have to get it to search the same file/line for the characters between the 2nd and 3rd blank space on the same line...Code:#!/bin/bash
#find the "# Added by KNOPPIX" line
grep -A 1 "KNOPPIX" /etc/fstab | grep dev | cut -c1-9 > drivelist
# read a line at a time
cat drivelist | while read line;
do
# increment a variable for sequential mount points
let "a += 1"
# make mountpoint
mkdir -p "/scanmount/drive"$a
# now mount that drive
mount ${line} /scanmount/drive$a
done
I wonder if there's simpler way to just get Knoppix to automount them, rather than listing noauto in fstab?
Quote:
Originally Posted by unclecameron
There probably is, this may work, automount every first and second partition, I've only shown sata drives but you'll get the idea.
#!/bin/bash
mkdir /mnt/winxp
mkdir /mnt/winxp2
mount -rw /dev/sda1 /mnt/winxp -t ntfs 2 > /dev/null
mount -rw /dev/sda2 /mnt/winxp -t ntfs 2 > /dev/null
You would have to install ntfs-3g to have read write permissions and extend the script
If the partition does not exist standard error is just redirected to /dev/null
You could even add it as a startup script to your run level and include it in
/etc/rc5.d/ or whatever runlevel youre starting at.
Ok, I got it to work :)
though my nested while loops could probably be improved :) Thanks for all the help!Code:#!/bin/bash
# find the "# Added by KNOPPIX" line
# and pipe the output to a loop
sed -n '/^\s*#/{N;s/^#.*\n//p}' /etc/fstab \
| while read device mountpoint filesystem options junk
# now we have a list of our mount information
do
while [ "$filesystem" = "ntfs" ]
do
# increment drive mount variable
let "a += 1"
# make the sequential mount location
mkdir -p "/scanmount/drive"$a
# now mount that drive at the dir we just made
mount $device -t $filesystem "/scanmount/drive"$a
# reset filesystem variable
filesystem="1"
done
while [ "$filesystem" = "fat32" ]
do
# increment drive mount variable
let "a += 1"
# make the sequential mount location
mkdir -p "/scanmount/drive"$a
# now mount that drive at the dir we just made
mount $device -t $filesystem "/scanmount/drive"$a
# reset filesystem variable
filesystem="1"
done
while [ "$filesystem" = "fat16" ]
do
# increment drive mount variable
let "a += 1"
# make the sequential mount location
mkdir -p "/scanmount/drive"$a
# now mount that drive at the dir we just made
mount $device -t $filesystem "/scanmount/drive"$a
# reset filesystem variable
filesystem="1"
done
done