如何从命令行挂载像Nautilus一样?

时间:2009-01-27 13:51:24

标签: linux gnome mount

在我的Ubuntu linux盒子上,我可以轻松安装USB连接的驱动器或CDROM点击桌面上的设备图标。

例如,如果我点击USB连接的驱动器图标,则会发生以下情况:

  • 自动创建/ media / LABEL目录(其中LABEL是磁盘的标签,可能因磁盘而异)
  • 设备上的文件系统安装在/ media / LABEL

此过程与使用mount命令的安装有很大不同。特别是:

  • 您不需要是root用户(或者您不需要修改/ etc / fstab以允许普通用户安装设备)
  • 自动创建/ media / LABEL目录
  • 目录名称根据卷标更改。

有一个命令行命令,其行为类似于Gnome GUI安装工具吗?

9 个答案:

答案 0 :(得分:37)

我猜你要找的是“gfvs-mount”(它最近取代了大多数人所说的“gnome-mount”; gnome-mount和pmount都依赖于正逐步淘汰的HAL。)

没有手册页,所以只需输入“gvfs-mount --help”获取详细信息,或者在此处阅读:How to mount filesystems from the command line in Ubuntu 10.04 and 10.10; 基本用法尽可能简单:

“gvfs-mount --list”获取已挂载/可挂载卷的列表;

“gvfs-mount [-u]”以[un]挂载它,例如“gvfs-mount smb:// server / share”或“gvfs-mount WINDOWS”。

遗憾的是,似乎有一个错误导致“错误安装位置:卷没有实现挂载”消息尝试按卷名安装,但“gvfs-mount -d / dev /”应该可以工作。 / p>

在我的ubuntu 10.04上我可以挂载这样的smb共享而不是Windows分区 - 但它可能是我做错了,我需要安装smb共享并且没有费心去研究ntfs分区的问题。

答案 1 :(得分:22)

在现代发行版中,不再使用HAL,pmount仍然存在,但已弃用....使用:

udisks --mount /dev/sdXN

答案 2 :(得分:9)

有关使用信息,请参阅pmount命令

答案 3 :(得分:1)

是的。它被称为ivman并处理所有HAL事件。我在运行ion3时启动它。我只是将ivman作为守护进程启动,但已将程序添加到我的sudoers文件中:

cat /etc/sudoers
[...]
ivman {hostname}=(root) NOPASSWD: /sbin/init, /usr/sbin/hibernate
[...]

这样它也可以管理电源设置。

答案 4 :(得分:0)

我不相信Gnome本身会处理装载它的HAL。因此,如果HAL正在运行,您应该能够自动挂载。我假设pmount以某种方式与HAL对话,这将是处理卸载的方法。我希望这至少让你开始。

答案 5 :(得分:0)

您也可以使用gnome-mount从命令行安装/卸载。

答案 6 :(得分:0)

我插入USB设备,输入“gnome-volume-manager”,这似乎可以满足您的需求。

答案 7 :(得分:0)

那将是“devkit-disks --mount /dev/sdxx”,其中xx是要挂载的分区的字母和数字......

答案 8 :(得分:0)

我有一个脚本可以做你想做的事。

#!/bin/bash
#====================================================================
# udmount.sh - mounts partitons by volume label.
#  usage: udmount.sh <label> [rw|ro|u]
#   rw - mount read-only (default) 
#   rw - mount read-write 
#   u  - unmount
# 
# Mounts on /media/<label>. Tested on Mint 13 and Fedora 19.
# Use and/or modify at your own risk. Your mileage may vary.
# Caveats:
#   * No spaces in volume label. Won't work.
#   * If the mount point (/media/<label>) already exists,
#     (usually from an unclean shutdown), udmount will mount
#     the volume on /media/<label>_  
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You can view the GNU General Public License for this program at
# http://www.gnu.org/licenses/gpl.txt
# Copyright 2013 maxdev137@sbcglobal.net
#====================================================================

BEEP=$'\a'
VLABEL="$1"     # volume label
MPOINT="/media" # default mount point for gnome-mount/udisks
YN=""           # yes/no string

c_red() { echo -n $(tput setaf 1)$1$(tput sgr0) ; }
c_grn() { echo -n $(tput setaf 2)$1$(tput sgr0) ; }
c_yel() { echo -n $(tput setaf 3)$1$(tput sgr0) ; }
c_blu() { echo -n $(tput setaf 4)$1$(tput sgr0) ; }
c_pur() { echo -n $(tput setaf 5)$1$(tput sgr0) ; }
c_aqu() { echo -n $(tput setaf 6)$1$(tput sgr0) ; }
c_wht() { echo -n $(tput setaf 7)$1$(tput sgr0) ; }

Y="YEP " ; Y_c=$(c_grn "$Y")
N="NOPE" ; N_c=$(c_red "$N")
SNAME=`echo "$0" | sed -e 's|.*/\(.*\)$|\1|'`

#--------------------------------------------------
AMV_LABEL=""    # already mounted volume label
MMSG=""         # "is mounted on" msg
AMF=0           # already mounted flag
AMV=""          # already mounted volume (from "mount -l")
AMV_DETAILS=""  # already mounted volume details
AMV_HELPER=""   # "uhelper" subsystem for mount/unmount ("hal" or "udisks")
COPT="$2"       # command line option
MOPT="ro"       # user input for mount option
UOPT="ro"       # udisk mount options

#--------------------------------------------------
_usage ()      { echo "usage: $SNAME LABEL [rw|ro|u]" ; }
_error()       { echo "!!! Error: $1. !!!" >&2 ; echo -n "$BEEP"; _usage ; exit 1 ; }
_error_parm()  { _error "$2 Parameter Missing [$1]" ; }
_error_parm2() { _error "Command is wrong (only \"rw, ro, or u\") is alowed, not \"$1\"" ; }

_unmount () {
  ### unmount ###
  if [ "$COPT" = "u" ] ; then
    MPOINT=`echo "$AMV" | grep "\[$VLABEL\]" |sed -e 's|^.* \(/.*\) type.*$|\1|'`
    #echo "unmount MPOINT = [$MPOINT]"
    if [ -z "$MPOINT" ] ; then
      echo "$N_c - $VLABEL not mounted."
    else
      _MSG=`umount "$MPOINT" 2>&1`
      _STATUS=$?
      if [ "$_STATUS" -eq 0 ] ; then
        echo "$Y_c - \"$MPOINT\" is now unmounted"
      else echo "$N_c - unmount \"$MPOINT\" failed ($_MSG)"
      fi
    fi
  fi
}

#--------------------------------------------------
[ -n "$VLABEL" ]  || _error_parm "$VLABEL" "Volume Label"

### command line option checck
case "$COPT" in
  "ro" ) ;;
  "rw" ) ;;
  "u"  ) ;;
     * ) _error_parm2 "$COPT" ;;
esac

### is VLABEL already mounted?
AMV=$(mount -l | grep "\[$VLABEL\]")
AMF=$?

### VLABEL is mounted somewhere
if  [ $AMF -eq 0 ] ; then
  AMV_LABEL=$(echo "$AMV" | sed 's/^.* \[\(.*\)\]$/\1/')
  AMV_DETAILS=$(echo $AMV | sed 's|^.*on \(.*\) \[.*$|on \"\1\"|')
  AMV_UHELPER=$(echo $AMV | grep uhelper | sed 's/^.*uhelper=\(.*\)).*$/\1/')
  #echo "AMV = [$AMV]"
  #echo "AMV_LABEL = [$AMV_LABEL]"
  #echo "AMV_DETAILS = [$AMV_DETAILS]"
  #echo "AMV_UHELPER = [$AMV_UHELPER]"

  ### unmount ###
  [ "$COPT" = "u" ] && _unmount && exit $?

  ### mounted on MPOINT (usually /media)
  if [ -d "$MPOINT/$VLABEL" ] ; then
    MOPT="ro" ; YN="$N_c"
    [ -w "$MPOINT/$VLABEL" ] && MOPT="rw"
    [ "$MOPT" = "$COPT" ]     && YN="$Y_c"
  ### mounted somewhere else
  else
    MOPT=$(echo "$AMV_DETAILS" | sed 's/^.*(\(.*\)).*$/\1/')
  fi
  echo "$N_c - $VLABEL is already mounted \"$MOPT\" $AMV_DETAILS"

### $VLABEL is not mounted anywhere, decide on "rw" or "ro"
else
  if [ "$COPT" = "u" ] ; then
    echo "$N_c - \"$VLABEL\" is not mounted"
  else
    MOPT="ro"
    [ "$COPT" = "rw" ] && MOPT="rw"
    echo "udisks --mount /dev/disk/by-label/$VLABEL $UOPT"
    udisks --mount /dev/disk/by-label/"$VLABEL" --mount-options "$MOPT"
    _STATUS=$?
    [ $_STATUS -eq 0 ] && echo "$Y_c - $MPOINT/$VLABEL mounted ($MOPT)"
    [ $_STATUS -ne 0 ] && echo "$N_c - \"$VLABEL\""
  fi
fi
#====================================================================