Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to mount multiple partitions, or even all partitions, of a disk with a single command in Linux? Is there, perhaps, an option that the mount command accepts that would facilitate this? I'm running Fedora 18; if I try mount /dev/sda* /media/sda* the operation fails.

Alternatively, can you suggest a script that I could put together for all my future uses?

I've come across some potentially useful posts that mention writing udev-rules; I'm not sure if that would be useful, though, since (as far as I know) the partitions on my main HDD already have those set up - which is evident by looking at the sidebar-list of accessible drives/partitions within my file manager.

To clarify, I'm simply trying to do something like '/dev/{sda1,sda2,...}', where each one of those would be mounted to their own directory with the same name.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

First of all, a partition can be mounted to multiple locations.

And for your own purpose, I doubt mount itself supports so. But you could definitely use your own script,

#!/bin/bash

for x in $*; do
    echo mount "$x" "/media/${x##*/}"
done

And launch it with (Remove the echo before running it)

./XX.sh /dev/sda* /dev/sdb*

P.S: you should consider udisks, which would mount the partition to /media/label_of_drive

share|improve this answer
    
thank you warlock, and thanks to cinelli as well, I will look into udisks...it sounds like that's what I'm looking for! :D –  ILMostro_7 Mar 18 '13 at 2:38
add comment

The mount command will only map one device at a time, so whatever method you choose will have to call mount for each partition.

/proc/partitions will give you a list of what's detected:

# cat /proc/partitions
major minor  #blocks  name

   8        0 1465138584 sda
   8        1 1465134488 sda1
   8       32 1465138584 sdc
   8       33 1465134488 sdc1
   8       16 1465138584 sdb
   8       17 1465134488 sdb1
   8       48 1465138584 sdd
   8       49 1465134488 sdd1
   8       64  156290904 sde
   8       65      96358 sde1
   8       66    4000185 sde2
   8       67          1 sde3
   8       69    2000061 sde5
   8       70   14996646 sde6
   8       71  135197527 sde7

This is where fdisk -l gets its information. You could use this to do something like:

awk '$4 ~ /^sda[0-9]+/{print $4}' /proc/partitions | while read dev; do
    if findmnt /dev/$dev >/dev/null; then
        echo "/dev/$dev is already mounted.  Skipping."
        continue
    elif findmnt /media/$dev >/dev/null; then
        echo "/media/$dev is already a mount point.  Skipping /dev/$dev."
        continue
    fi
    mount /dev/$dev /media/$dev
done
share|improve this answer
add comment

If you're going to be booting the partitions at boot then you could add them to /etc/fstab. man fstab to see what all the different options are for the rows inside the configuration file. The columns should be organized as follows.

<file system>   <dir>   <fs-type>   <mount-options>   <dump> <pass>

If you are not going to be mounting them then look into using udisks or udiskie. You cannot mount two partitions to the same directory. You can mount one inside a sub-directory of an already mounted device though.

share|improve this answer
    
I'm not trying to mount them into a single directory, more like their own sub-directories within the /media/ folder: /dev/sda* /media/sda* ; also, I'm trying to chroot into them while mounted...but it's more of a general question, I suppose, about mounting multiple partitions without having to do a separate command for each partition; kinda like mount /dev/{sda1,sda2,...} or something like that. –  ILMostro_7 Mar 18 '13 at 2:28
    
You either have them auto mount at boot in fstab or systemd.units (man systemd.mount, or you have the auto mounted upon being plugged in wish udisks`. Or you have them auto mount upon access with x-systemd.automount. Other than that you're stuck to typing commands. Also, you should be mounting any additional partitions from inside the chroot. Only the partitions that you need in order to chroot should be mounted outside the chroot. –  cinelli Mar 18 '13 at 5:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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