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

发布于 2024-07-12 23:28:24 字数 1552 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

纵性 2024-07-19 23:28:24

您正在寻找的是gio mount(它最近取代了gvfs-mount,后者又取代了gnome-mount)。

这里有一个 手册页 或者您只需输入 gio help mount 了解详细信息

基本用法是:

gio mount --list --detail 获取已挂载和可挂载卷的列表

gio mount [-u] < ;volume> 来[卸载]它,例如 gio mount smb://server/sharegio mount WINDOWS

遗憾的是,似乎存在一个错误,导致尝试按卷名称挂载时出现“安装位置错误:卷未实现挂载”消息,但 gvfs-mount -d /dev/可能有效。

What you are looking for is gio mount (it recently replaced gvfs-mount, which replaced gnome-mount).

There is a man page here or you can just type gio help mount for the details

The basic usage is:

gio mount --list --detail to get a list of mounted and mountable volumes

gio mount [-u] <volume> to [un]mount it, e.g. gio mount smb://server/share or gio mount WINDOWS.

Sadly, there seems to be a bug that results in a "Error mounting location: volume doesn't implement mount" message trying to mount by volume name, but gvfs-mount -d /dev/<devicename> might work.

神仙妹妹 2024-07-19 23:28:24

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

udisks --mount /dev/sdXN

回答更新:

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

udisksctl mount -b /dev/sdXN

In modern distributions, HAL is no longer used. The pmount still exists, but it is deprecated. Use:

udisks --mount /dev/sdXN

Answer Update:

The udisksctl command is being used as an alternative to the udisks command. This can be used the same way, -b is just to be appended to define the block device.

udisksctl mount -b /dev/sdXN
雨夜星沙 2024-07-19 23:28:24

请参阅 pmount 命令使用信息

See the pmount command for usage information

心奴独伤 2024-07-19 23:28:24

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

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

以便它也可以管理电源设置。

Yes there is. It's called ivman and handles all HAL events. I start it when running ion3. I simply start ivman as a daemon process, but has added the program to my sudoers file:

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

so that it can manage power settings as well.

伴我老 2024-07-19 23:28:24

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

I don't believe Gnome itself handles the mounting—it's HAL. So if HAL is running, you should be able to automount. I assume that pmount talks to HAL somehow, and that would be the way to handle unmounting. I hope this gets you started, at least.

千纸鹤 2024-07-19 23:28:24

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

You can also use gnome-mount for mounting / unmounting from the command line.

維他命╮ 2024-07-19 23:28:24

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

I plug in my USB device, type "gnome-volume-manager" and this seems to do what you require.

画骨成沙 2024-07-19 23:28:24

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

That would be "devkit-disks --mount /dev/sdxx" where xx is the letter and number of the partition to mount...

ゞ花落谁相伴 2024-07-19 23:28:24

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

#!/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 [email protected]
#====================================================================

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
#====================================================================

I have a script to do what you want.

#!/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 [email protected]
#====================================================================

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
#====================================================================
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文