Results 1 to 8 of 8

Thread: auto-mount /dev/xda1 at /somemountpoint on boot

  1. #1

    auto-mount /dev/xda1 at /somemountpoint on boot

    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?

  2. #2
    Senior Member registered user
    Join Date
    Jan 2005
    Location
    UK
    Posts
    282

    Re: auto-mount /dev/xda1 at /somemountpoint on boot

    Quote Originally Posted by unclecameron
    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?

    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).

  3. #3
    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.

  4. #4
    Senior Member registered user
    Join Date
    Jan 2005
    Location
    UK
    Posts
    282
    Quote Originally Posted by unclecameron
    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.

    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

  5. #5
    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)
    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
    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...

  6. #6
    ok, I have done this, and it ALMOST works

    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
    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...

    I wonder if there's simpler way to just get Knoppix to automount them, rather than listing noauto in fstab?

  7. #7
    Senior Member registered user
    Join Date
    Jan 2005
    Location
    UK
    Posts
    282
    Quote Originally Posted by unclecameron
    ok, I have done this, and it ALMOST works

    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
    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...

    I wonder if there's simpler way to just get Knoppix to automount them, rather than listing noauto in fstab?

    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.

  8. #8
    Ok, I got it to work
    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
    though my nested while loops could probably be improved Thanks for all the help!

Similar Threads

  1. Auto mount persistant image on boot
    By luka in forum Hardware & Booting
    Replies: 2
    Last Post: 07-23-2008, 03:48 PM
  2. basic auto mount question
    By A. Jorge Garcia in forum General Support
    Replies: 10
    Last Post: 02-28-2006, 11:13 PM
  3. Auto Mount?
    By cfish in forum Hdd Install / Debian / Apt
    Replies: 6
    Last Post: 03-26-2005, 02:04 AM
  4. Auto Mount after booting from CD
    By mahdi in forum General Support
    Replies: 3
    Last Post: 04-18-2004, 07:50 PM
  5. How do I auto mount HD partitions durring Knoppix boot?
    By audioaficionado in forum Customising & Remastering
    Replies: 0
    Last Post: 03-29-2003, 06:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Seagate ST6000NM0115 6TB 256MB 7200RPM 3.5

Seagate ST6000NM0115 6TB 256MB 7200RPM 3.5" SATA 6.0Gb/s Enterprise Hard Drive

$159.99



Seagate Exos X14 10TB 7200RPM 3.5

Seagate Exos X14 10TB 7200RPM 3.5" SAS 12Gb/s Hard Drive HDD ST10000NM0528

$165.00



Seagate 14TB Exos X14 7200RPM SATA 6Gb/s 256MB 3.5

Seagate 14TB Exos X14 7200RPM SATA 6Gb/s 256MB 3.5" Enterprise HDD ST14000NM0408

$354.99



Seagate ST8000NM0075 Enterprise Capacity 3.5 HDD 8TB SAS Hard Drive 8TB EXOS picture

Seagate ST8000NM0075 Enterprise Capacity 3.5 HDD 8TB SAS Hard Drive 8TB EXOS

$184.99



HGST 4TB 7200RPM 3.5

HGST 4TB 7200RPM 3.5" SATA 6Gb/s Internal HDD | HDN724040ALE640 0F22408

$75.00



HGST - 6TB - 7200RPM 3.5

HGST - 6TB - 7200RPM 3.5" SATA 6Gb/s Enterprise Hard Drive | HUS726060ALA640

$84.99



HGST HUS724040ALA640 4TB 7200 RPM SATA 3.5

HGST HUS724040ALA640 4TB 7200 RPM SATA 3.5" Internal Desktop Drive 100% Health

$78.00



Seagate ST500DM009 BarraCuda 500 GB 3.5

Seagate ST500DM009 BarraCuda 500 GB 3.5" SATA III Desktop Hard Drive

$14.99



HDD 3.5

HDD 3.5" SATA Hard Drive with Windows 10/Win 11 64x Installed Legacy

$35.00



Western Digital WD30EFRX 3TB SATA 5400RPM 3.5

Western Digital WD30EFRX 3TB SATA 5400RPM 3.5" Internal NASware HDD Hard Drive

$84.69