我有一台 Debian 8 笔记本电脑,它出现了硬件故障(电源板),维修起来既费时又容易出错。因此,我购买了一个 2.5 英寸 HD USB 外壳,将笔记本电脑的 HD 放入其中,然后连接到我的 XUbuntu,这样我就可以恢复一些重要文件。现在 USB 驱动器确实挂载了,但挂载到我认为是启动分区的位置。我需要访问数据 (/) 分区,我认为它是 /dev/sdb5 上的逻辑分区(见下文)。
有人可以帮助我使用正确的 mknod mount 命令来挂载 / 逻辑卷吗?
下面是来自 fdisk -l 命令(显示 USB 驱动器)和相关设备文件的图像。
谢谢!约翰
答案1
安装驱动器的脚本 -mount-menu.sh
该mount-menu.sh
脚本允许您选择未安装的驱动器/分区进行安装。要调用该脚本,请使用:sudo mount-menu.sh
。此屏幕根据您的独特机器环境定制:
- 使用箭头键选择分区并按Enter
菜单将清除并将此信息保留在您的终端中:
=====================================================================
Mount Device: /dev/nvme0n1p10
Mount Name: /mnt/mount-menu.FPRAW
File System: ext4
ID: Ubuntu
RELEASE: 18.04
CODENAME: bionic
DESCRIPTION: Ubuntu 18.04.1 LTS
Size Used Avail Use%
27G 7.9G 18G 32%
现在您可以使用:cd /mnt/mount-menu.FPRAW
访问外部驱动器的分区。
然后,您可以使用,cd home/YOUR_NAME
但要小心不要/
在 前面放home
。如果您使用 ,cd /home
它会带您进入启动驱动器并退出外部驱动器。
mount-menu.sh
脚本内容
要创建脚本,请打开终端并输入:
sudo -H gedit /usr/local/bin/mount-menu.sh
然后复制下面的代码并粘贴到gedit
。保存文件并退出gedit
。
现在使用以下命令将文件标记为可执行文件:
sudo chmod a+x /usr/local/bin/mount-menu.sh
这是要复制的脚本:
#!/bin/bash
# NAME: mount-menu.sh
# PATH: /usr/local/bin
# DESC: Select unmounted partition for mounting
# DATE: May 9, 2018. Modified May 11, 2018.
# $TERM variable may be missing when called via desktop shortcut
CurrentTERM=$(env | grep TERM)
if [[ $CurrentTERM == "" ]] ; then
notify-send --urgency=critical \
"$0 cannot be run from GUI without TERM environment variable."
exit 1
fi
# Must run as root
if [[ $(id -u) -ne 0 ]] ; then echo "Usage: sudo $0" ; exit 1 ; fi
#
# Create unqique temporary file names
#
tmpMenu=$(mktemp /tmp/mount-menu.XXXXX) # Menu list
tmpInfo=$(mktemp /tmp/mount-menu.XXXXX) # Mount Parition Info
tmpWork=$(mktemp /tmp/mount-menu.XXXXX) # Work file
MountName=$(mktemp -d /mnt/mount-menu.XXXXX) # Mount directory name
#
# Function Cleanup () Removes temporary files
#
CleanUp () {
[[ -f $tmpMenu ]] && rm -f $tmpMenu # If temporary files created
[[ -f $tmpInfo ]] && rm -f $tmpInfo # at various program stages
[[ -f $tmpWork ]] && rm -f $tmpWork # remove them before exiting.
}
#
# Mainline
#
lsblk -o NAME,FSTYPE,LABEL,SIZE,MOUNTPOINT > $tmpMenu
i=0
SPACES=' '
DoHeading=true
AllPartsArr=() # All partitions.
# Build whiptail menu tags ($i) and text ($Line) into array
while read -r Line; do
if [[ $DoHeading == true ]] ; then
DoHeading=false # First line is the heading.
MenuText="$Line" # Heading for whiptail.
FSTYPE_col="${Line%%FSTYPE*}"
FSTYPE_col="${#FSTYPE_col}" # FS Type, ie `ext4`, `ntfs`, etc.
MOUNTPOINT_col="${Line%%MOUNTPOINT*}"
MOUNTPOINT_col="${#MOUNTPOINT_col}" # Required to ensure not mounted.
continue
fi
Line="$Line$SPACES" # Pad extra white space.
Line=${Line:0:74} # Truncate to 74 chars for menu.
AllPartsArr+=($i "$Line") # Menu array entry = Tag# + Text.
(( i++ ))
done < $tmpMenu # Read next "lsblk" line.
#
# Display whiptail menu in while loop until no errors, or escape,
# or valid partion selection .
#
DefaultItem=0
while true ; do
# Call whiptail in loop to paint menu and get user selection
Choice=$(whiptail \
--title "Use arrow, page, home & end keys. Tab toggle option" \
--backtitle "Mount Partition" \
--ok-button "Select unmounted partition" \
--cancel-button "Exit" \
--notags \
--default-item "$DefaultItem" \
--menu "$MenuText" 24 80 16 \
"${AllPartsArr[@]}" \
2>&1 >/dev/tty)
clear # Clear screen.
if [[ $Choice == "" ]]; then # Escape or dialog "Exit".
CleanUp
exit 1;
fi
DefaultItem=$Choice # whiptail start option.
ArrNdx=$(( $Choice * 2 + 1)) # Calculate array offset.
Line="${AllPartsArr[$ArrNdx]}" # Array entry into $Line.
# Validation - Don't wipe out Windows or Ubuntu 16.04:
# - Partition must be ext4 and cannot be mounted.
if [[ "${Line:MOUNTPOINT_col:4}" != " " ]] ; then
echo "Partition is already mounted."
read -p "Press <Enter> to continue"
continue
fi
# Build "/dev/Xxxxx" FS name from "├─Xxxxx" menu line
MountDev="${Line%% *}"
MountDev=/dev/"${MountDev:2:999}"
# Build File System Type
MountType="${Line:FSTYPE_col:999}"
MountType="${MountType%% *}"
break # Validated: Break menu loop.
done # Loop while errors.
#
# Mount partition
#
echo ""
echo "====================================================================="
mount -t auto $MountDev $MountName
# Display partition information.
echo "Mount Device=$MountDev" > $tmpInfo
echo "Mount Name=$MountName" >> $tmpInfo
echo "File System=$MountType" >> $tmpInfo
# Build Mount information (the partition selected for cloning to)
LineCnt=$(ls $MountName | wc -l)
if (( LineCnt > 2 )) ; then
# More than /Lost+Found exist so it's not an empty partition.
if [[ -f $MountName/etc/lsb-release ]] ; then
cat $MountName/etc/lsb-release >> $tmpInfo
else
echo "No LSB-Release file on Partition." >> $tmpInfo
fi
else
echo "Partition appears empty" >> $tmpInfo
echo "/Lost+Found normal in empty partition" >> $tmpInfo
echo "First two files/directories below:" >> $tmpInfo
ls $MountName | head -n2 >> $tmpInfo
fi
sed -i 's/DISTRIB_//g' $tmpInfo # Remove DISTRIB_ prefix.
sed -i 's/=/:=/g' $tmpInfo # Change "=" to ":="
sed -i 's/"//g' $tmpInfo # Remove " around "Ubuntu 16.04...".
# Align columns from "Xxxx:=Yyyy" to "Xxxx: Yyyy"
cat $tmpInfo | column -t -s '=' > $tmpWork
cat $tmpWork > $tmpInfo
# Mount device free bytes
df -h --output=size,used,avail,pcent "$MountDev" >> $tmpInfo
# Display partition information.
cat $tmpInfo
CleanUp # Remove temporary files
exit 0
umount-menu.sh
卸载驱动器/分区
重复脚本的文件创建/执行位标记过程umount-menu.sh
。此脚本仅卸载由安装的驱动器/分区mount-menu.sh
。它具有相同的选择菜单并完成并显示以下消息:
=====================================================================
/dev/nvme0n1p10 mounted on /mnt/mount-menu.FPRAW unmounted.
要调用脚本,请使用:sudo umount-menu.sh
umount-menu.sh
bash 脚本:
!/bin/bash
# NAME: umount-menu.sh
# PATH: /usr/local/bin
# DESC: Select mounted partition for unmounting
# DATE: May 10, 2018. Modified May 11, 2018.
# $TERM variable may be missing when called via desktop shortcut
CurrentTERM=$(env | grep TERM)
if [[ $CurrentTERM == "" ]] ; then
notify-send --urgency=critical \
"$0 cannot be run from GUI without TERM environment variable."
exit 1
fi
# Must run as root
if [[ $(id -u) -ne 0 ]] ; then echo "Usage: sudo $0" ; exit 1 ; fi
#
# Create unqique temporary file names
#
tmpMenu=$(mktemp /mnt/mount-menu.XXXXX) # Menu list
#
# Function Cleanup () Removes temporary files
#
CleanUp () {
[[ -f "$tmpMenu" ]] && rm -f "$tmpMenu" # at various program stages
}
#
# Mainline
#
lsblk -o NAME,FSTYPE,LABEL,SIZE,MOUNTPOINT > "$tmpMenu"
i=0
SPACES=' '
DoHeading=true
AllPartsArr=() # All partitions.
# Build whiptail menu tags ($i) and text ($Line) into array
while read -r Line; do
if [[ $DoHeading == true ]] ; then
DoHeading=false # First line is the heading.
MenuText="$Line" # Heading for whiptail.
MOUNTPOINT_col="${Line%%MOUNTPOINT*}"
MOUNTPOINT_col="${#MOUNTPOINT_col}" # Required to ensure mounted.
continue
fi
Line="$Line$SPACES" # Pad extra white space.
Line=${Line:0:74} # Truncate to 74 chars for menu.
AllPartsArr+=($i "$Line") # Menu array entry = Tag# + Text.
(( i++ ))
done < "$tmpMenu" # Read next "lsblk" line.
#
# Display whiptail menu in while loop until no errors, or escape,
# or valid partion selection .
#
DefaultItem=0
while true ; do
# Call whiptail in loop to paint menu and get user selection
Choice=$(whiptail \
--title "Use arrow, page, home & end keys. Tab toggle option" \
--backtitle "Mount Partition" \
--ok-button "Select unmounted partition" \
--cancel-button "Exit" \
--notags \
--default-item "$DefaultItem" \
--menu "$MenuText" 24 80 16 \
"${AllPartsArr[@]}" \
2>&1 >/dev/tty)
clear # Clear screen.
if [[ $Choice == "" ]]; then # Escape or dialog "Exit".
CleanUp
exit 1;
fi
DefaultItem=$Choice # whiptail start option.
ArrNdx=$(( $Choice * 2 + 1)) # Calculate array offset.
Line="${AllPartsArr[$ArrNdx]}" # Array entry into $Line.
if [[ "${Line:MOUNTPOINT_col:15}" != "/mnt/mount-menu" ]] ; then
echo "Only Partitions mounted by mount-menu.sh can be unounted."
read -p "Press <Enter> to continue"
continue
fi
# Build "/dev/Xxxxx" FS name from "├─Xxxxx" menu line
MountDev="${Line%% *}"
MountDev=/dev/"${MountDev:2:999}"
# Build Mount Name
MountName="${Line:MOUNTPOINT_col:999}"
MountName="${MountName%% *}"
break # Validated: Break menu loop.
done # Loop while errors.
#
# Unmount partition
#
echo ""
echo "====================================================================="
umount "$MountName" -l # Unmount the clone
rm -d "$MountName" # Remove clone directory
echo $(tput bold) # Set to bold text
echo $MountDev mounted on $MountName unmounted.
echo $(tput sgr0) # Reset to normal text
CleanUp # Remove temporary files
exit 0
答案2
我无法撤消我执行的所有步骤,但是当我安装 lvm2 并插入 USB 硬盘时,启动分区和 LVM 的“/”分区都自动挂载了。我没有运行 mount-menu.sh 脚本。
因此,原始情况下的人应该尝试安装 lvm2,它可能会安装您需要的所有内容。
XUbuntu 18.04 64 位。