如何从命令行像鹦鹉螺一样挂载?

在我的Ubuntu的Linux上,我可以很容易地安装USB连接的驱动器或CDROM点击我可以在桌面上find的设备图标。

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

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

这个过程与使用mount命令的安装有很大的不同。 尤其是:

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

有一个命令行命令的行为像Gnome的GUI安装设施呢?

请参阅pmount命令以获取使用信息

我想你要找的是“gfvs-mount”(它最近取代了大多数人谈论的“gnome-mount”; gnome-mount和pmount都依赖于正在被淘汰的HAL)。

有没有手册页,所以只需输入“gvfs-mount –help”的细节,或阅读这里: 如何从Ubuntu 10.04和10.10的命令行挂载文件系统 ; 基本用法很简单,可能会得到:

“gvfs-mount –list”获取挂载/安装卷的列表;

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

可悲的是,似乎有一个错误,导致“错误安装位置:卷不执行安装”消息尝试挂载卷名,但“gvfs-mount -d / dev /”应该工作。

在我的Ubuntu 10.04上,我可以安装像这样的股份,但不是Windows分区 – 但它可能是我做错了,我需要安装SMB股票,并没有打扰研究ntfs分区的问题。

在现代发行HAL不再使用,pmount仍然存在,但它不赞成使用:

 udisks --mount /dev/sdXN 

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

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

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

我不相信Gnome自己处理安装 – 这是HAL。 所以如果HAL正在运行,你应该能够自动挂载。 我认为,不知何故,HAL将与HAL进行会谈,这将是解决问题的方法。 我希望这至少能让你开始。

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

我插入我的USB设备,输入“gnome-volume-manager”,这似乎是做你所需要的。

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

我有一个脚本来做你想做的事情。

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