15

Issue
I have a Linux Mint installation. Every time that I boot, I need to manually mount the two partitions on my computer(New volume D and Drive C). If I don't do this, these drives don't show up anywhere. I want to know if there is some way to automate this process.

Goal
Automatically mounting all the partitions on the hard disk each time I boot.

Specs
Linux Mint 14 dual boot with Windows XP SP3

2

5 Answers 5

15

You can do this through the file /etc/fstab. Take a look at this link. This tutorial also has good details.

Example steps

First you need to find out the UUID of the hard drives. You can use the command blkid for this. For example:

% sudo blkid
/dev/sda1: TYPE="ntfs" UUID="A0F0582EF0580CC2"
/dev/sda2: UUID="8c2da865-13f4-47a2-9c92-2f31738469e8" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda3: TYPE="swap" UUID="5641913f-9bcc-4d8a-8bcb-ddfc3159e70f"
/dev/sda5: UUID="FAB008D6B0089AF1" TYPE="ntfs"
/dev/sdb1: UUID="32c61b65-f2f8-4041-a5d5-3d5ef4182723" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdb2: UUID="41c22818-fbad-4da6-8196-c816df0b7aa8" SEC_TYPE="ext2" TYPE="ext3" 

The output from the blkid command above can be used to identify the hard drive when adding entries to /etc/fstab.

Next you need to edit the /etc/fstab file. The lines in this file are organized as follows:

UUID={YOUR-UID}    {/path/to/mount/point}               {file-system-type}    defaults,errors=remount-ro 0       1

Now edit the file:

% sudo vi /etc/fstab

And add a file like this, for example:

UUID=41c22818-fbad-4da6-8196-c816df0b7aa8  /disk2p2      ext3    defaults,errors=remount-ro 0       1

Save the file and then reprocess the file with the mount -a command.

Windows partitions

To mount an ntfs partition you'll need to do something like this in your /etc/fstab file:

/dev/sda2   /mnt/excess ntfs-3g    permissions,locale=en_US.utf8    0   2
3
  • the two partitions /dev/sda5 and dev/sda6 are not listed in fstab file and in the blkid command. why?
    – IcyFlame
    Apr 14, 2013 at 12:42
  • okay. i got it. it is because it is a windows partition that is there in /media
    – IcyFlame
    Apr 14, 2013 at 12:45
  • Windows partitions you'll need to use the dev/sda* to mount them, also you'll need to specify ntfs-3g for the file-system-type I believe.
    – slm
    Apr 14, 2013 at 12:56
15

You can do this by the simplest way. Go to:

  • Menu -> Disks (app)
  • Select the volume you want to mount, and click on its options
  • Select "Edit Mount Options" -> And make sure you select "Mount at Startup" in the drive.
4
  • Sometime gui makes sense or it makes easy to do these things.
    – Ramsharan
    Oct 17, 2013 at 4:11
  • Oh, Holly S***, Nice!!! Aug 9, 2015 at 17:56
  • Wysiwyg solution, better for beginners.
    – Sandburg
    Nov 28, 2018 at 9:10
  • Seriously this is the best answer.. so easy and less error prone
    – supersan
    Dec 2, 2020 at 17:13
2

If you have a lot of partitions to be mounted, maybe you need a script like I did.


# ! python
# mount all partition by neoedmund
from subprocess import Popen
from subprocess import PIPE

def getCol(col, line):
    p1 = line.find(col)
    if p1<0 : return ""
    p2 = p1 + len(col) + 1
    p3 = line.find('"',p2+1)
    return line[p2+1:p3]

data_stream = Popen(["/bin/lsblk", "-P", "-o", "FSTYPE,UUID,MOUNTPOINT,KNAME"], stdout=PIPE)
data=[]
for line in data_stream.stdout:
    fstype = getCol("FSTYPE", line)
    if fstype=="": continue # no fs
    mountpoint = getCol("MOUNTPOINT", line)
    if mountpoint!="":continue  # already mounted   
    uuid = getCol("UUID", line)
    kname = getCol("KNAME", line)
    data.append((kname, uuid))

print("### mount script ###")
for (kname,uuid) in data:
    print("mkdir /media/%s-%s"%(kname, uuid))
    print("mount /dev/%s /media/%s-%s" %(kname, kname, uuid))

print("### umount script ###")
for (kname,uuid) in data:
    print("umount /dev/%s" %(kname))




It is a python script, depends on "/bin/lsblk" , save the output to two shell scripts for mount and umount.

0
for i in $(lsblk -r |awk '{ print $1 }'|grep -v md |grep -v loop |grep .*[[:digit:]]|sort|uniq;); 
do
    if [ -z  "$(grep  $i /proc/mounts)" ]
    then  
        mkdir /mnt/$i;
        mount /dev/$i /mnt/$i
    fi
done
2
  • 2
    It would be helpful if you could explain exactly what your command does.
    – dhag
    Mar 25, 2015 at 19:14
  • Putting a huge sequence of commands and control structures on the same line doesn't really make your code a one-liner. It just makes it unecessarily harder to understand... Mar 25, 2015 at 19:36
0

Backup of current fstab:

#cp -a /etc/fstab /etc/fstab.bk

process the output of lsblk -f using sed and awk and redirect output to fstab:

#lsblk -f|sed 's/\[SWAP]/swap /g'|awk '/(-)/{printf"UUID=%-36s %-23s %-7s defaults 
           0 0\n", $3, ($4==""?mnt"NR:$4), $2}'>/etc/fstab

mount the new mount points by invoking

#mount -a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.