We help IT Professionals succeed at work.

Script to mount drives on boot or via a script file

Emanuel asked
Last Modified: 2013-12-26
Hi I am running Ubuntu Lucid Lynx and would like to know how I can get it to automatically mount additional partitions of my primary drive.
I have five partitions on my drive and would ideally like to mount them via a script file.  In addition I would like to mount the 5th partition on boot and have an icon on the desktop appear for the drive.

Additionally how can I install a desktop shortcut for the Computer function, enabling me to browse the drives?

My partitions are;
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdf81dcc2

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        7012    56217600    7  HPFS/NTFS
/dev/sda3            7012       10837    30720000    7  HPFS/NTFS
/dev/sda4           10837       60802   401344512    f  W95 Ext'd (LBA)
/dev/sda5           10837       60802   401343488    7  HPFS/NTFS

Many thanks,

Watch Question

Put the entries in /etc/fstab to mount partitions automatically @ boot

1) Create directories where you want to mount partitions:
e.g.: mkdir /mnt/win_C /mnt/win_d /mnt/win_E

2) edit your /etc/fstab and add these lines:
/dev/sda1    /mnt/win_C     auto    defaults   0 0
/dev/sda2    /mnt/win_D     auto    defaults   0 0
/dev/sda3    /mnt/win_E     auto    defaults   0 0
/dev/sda4    /mnt/win_F     auto    defaults   0 0
and so on ..

You may need to install NTFS support (if not already installed).

Also, I believe there is now a GUI in latest Ubuntu to do this http://www.psychocats.net/ubuntu/mountwindows


Is it possible to create a script file to do this for mounting drives across a network too?
Not sure what you want to achieve, once its in fstab, it will always be mounted.

If you need it to be in a script, you could put mount commands on any of the system startup scripts
/etc/rc.local OR /etc/rc.sysinit

Add these commands at the end of file:
mount /dev/sda1 /mnt/win_c
mount /dev/sda2 /mnt/win_e
and so on ...


OK thank you.
I am not sure either really.  I understand how to create VBscripts in windows and they simply create a map to other network drives when you double click them.  I am trying to understand how you would do that in Linux I guess.

On a Windows machine you would open a cmd prompt and type 'net use x: \\\data' or '\\server\data'

This would then create a drive X:\data

How would I achieve the same in Ubuntu?
Say I have a shared folder called data on server

Cheers you have been enlightening already.
This one is on us!
(Get your first solution completely free - no credit card required)


Nevvamind, thank you have been very helpful.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.