41

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

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

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

mount这个过程与使用命令挂载有很大不同。尤其:

  • 你不需要是root(或者你不需要修改/etc/fstab来允许普通用户挂载设备)
  • /media/LABEL 目录是自动创建的
  • 目录的名称根据卷标而改变。

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

4

9 回答 9

44

您正在寻找的是gio mount(它最近被替换gvfs-mount,它被替换gnome-mount)。

这里有一个手册页,或者您可以输入gio help mount详细信息

基本用法是:

gio mount --list --detail获取已安装和可安装卷的列表

gio mount [-u] <volume>[un] 挂载它,例如gio mount smb://server/shareor gio mount WINDOWS

可悲的是,似乎有一个错误导致“错误安装位置:卷未实现安装”消息尝试按卷名安装,但gvfs-mount -d /dev/<devicename>可能有效。

于 2011-05-12T11:04:14.567 回答
24

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

udisks --mount /dev/sdXN

答案更新:

udisksctl命令被用作该命令的替代品udisks。这可以使用相同的方式,-b只是被附加来定义块设备。

udisksctl mount -b /dev/sdXN
于 2013-01-26T11:01:58.337 回答
10

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

于 2009-01-27T13:56:58.277 回答
1

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

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

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

于 2009-01-29T19:21:31.940 回答
0

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

于 2009-01-27T14:01:56.007 回答
0

您还可以使用 gnome-mount 从命令行挂载/卸载。

于 2009-01-29T19:26:13.987 回答
0

我插入我的 USB 设备,输入“gnome-volume-manager”,这似乎符合您的要求。

于 2009-01-29T19:50:30.740 回答
0

那将是“ devkit-disks --mount /dev/sdxx”,xx要挂载的分区的字母和编号在哪里...

于 2009-12-26T12:18:31.907 回答
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
#====================================================================
于 2013-11-02T01:46:44.113 回答