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
  •  


Intel Core i7-7700T 2.9GHz 8MB Socket LGA1151 Quad Core Processor SR339 picture

Intel Core i7-7700T 2.9GHz 8MB Socket LGA1151 Quad Core Processor SR339

$39.99



AMD Ryzen 7 5800X Desktop Processor (4.7GHz, 8 Cores, Socket AM4) picture

AMD Ryzen 7 5800X Desktop Processor (4.7GHz, 8 Cores, Socket AM4)

$169.99



Corsair RM750e 750W Fully Modular 80 Plus Gold ATX 3.1 PSU Certified Refurbished picture

Corsair RM750e 750W Fully Modular 80 Plus Gold ATX 3.1 PSU Certified Refurbished

$52.99



Intel Core i7-9700 3.0 GHz 8 Core Processor picture

Intel Core i7-9700 3.0 GHz 8 Core Processor

$85.00



Intel i7-8700 Coffee Lake 3.2GHz 6-Core Max Turbo 4.6GHz Processor picture

Intel i7-8700 Coffee Lake 3.2GHz 6-Core Max Turbo 4.6GHz Processor

$69.99



Intel 4th Gen Core i7-4790 SR1QF 3.60GHz (Turbo 4.00GHz) 8M 4-Core LGA-1150 CPU picture

Intel 4th Gen Core i7-4790 SR1QF 3.60GHz (Turbo 4.00GHz) 8M 4-Core LGA-1150 CPU

$39.99



Intel i7-3770 Quad Core 3.40 Ghz Ivy Bridge Desktop Processor  LGA 1155 picture

Intel i7-3770 Quad Core 3.40 Ghz Ivy Bridge Desktop Processor LGA 1155

$24.99



Intel 7th Gen Core i7-7700 3.6GHz 4 Core 8 Thread LGA1151 CPU SR338 picture

Intel 7th Gen Core i7-7700 3.6GHz 4 Core 8 Thread LGA1151 CPU SR338

$42.99



HP ProDesk 405 G8 Desktop AMD Ryzen 5 PRO 5650GE 16GB RAM 512GB SSD W11P picture

HP ProDesk 405 G8 Desktop AMD Ryzen 5 PRO 5650GE 16GB RAM 512GB SSD W11P

$260.49



Intel 6th Gen Core i7-6700K 4.0GHz (Turbo 4.2GHz) 4-Core LGA1151 CPU SR2L0 picture

Intel 6th Gen Core i7-6700K 4.0GHz (Turbo 4.2GHz) 4-Core LGA1151 CPU SR2L0

$38.00