我有以下硬盘分区设置:
- 256 GB 固态硬盘
/dev/sda1- FAT 32 - 挂载在 /boot/efi
/dev/sda2-挂载在文件系统根目录
/dev/sda3-安装在/usr
- 1 TB 硬盘
/dev/sdb1——Linux 交换
/dev/sdb2-安装在/var
/dev/sdb3-安装在/home
/dev/sdb4-EFI 系统(未安装)
/dev/sdb5-安装在第二个发行版的文件系统根目录(已卸载)
这两个发行版分别是 Lubuntu 和 Elementary。在上面的分类中,Elementary 是未安装的。有人能告诉我如何在这些发行版之间共享文件吗?目前,我无法在 Elementary 中打开或执行任何来自 Lubuntu 的已安装应用程序。我也无法打开几个文件夹,例如 /usr/local/bin
答案1
手动操作
使用这些命令安装第二个发行版
sudo mkdir /mnt/MyOtherDistro
sudo mount -t auto -v /dev/sdb5 /mnt/MyOtherDistro
现在您将能够使用 Nautilus 或任何其他文件管理器导航到目录来/mnt/MyOtherDistro
查看/复制/删除文件等。
您还可以更改到第二个发行版中的目录:
cd /mnt/MyOtherDistro/home/Me/Documents
完成后卸载分区并删除目录:
sudo umount -l /mnt/MyOtherDistro
sudo rm -d /mnt/MyOtherDistro
使用 Bash 脚本
幸运的是,今晚我正在研究两个脚本,通过命令行滚动框来挂载和卸载分区。
挂载分区
要挂载分区,请运行 bash 脚本sudo mount-menu.sh
:
突出显示未挂载的分区并按Enter。它将被挂载,并显示有关该分区的一些基本信息:
=====================================================================
Mount Device: /dev/nvme0n1p8
Mount Name: /mnt/mount-menu.b9yZf
File System: ext4
ID: Ubuntu
RELEASE: 18.04
CODENAME: bionic
DESCRIPTION: Ubuntu 18.04 LTS
Size Used Avail Use%
24G 17G 5.2G 77%
要创建脚本,请将以下内容复制到名为的文件中/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
卸载分区
要卸载分区设置,请mount-menu.sh
运行命令sudo umount-menu.sh
。屏幕上将显示与上面相同的内容,但分区已安装,您可以选择卸载它。首先,您需要创建脚本/usr/local/bin/umount-menu.sh
并复制以下几行:
#!/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 /tmp/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
使它们可执行
创建文件后,两个脚本都必须标记为可执行:
sudo chmod a+x /usr/local/bin/mount-menu.sh
sudo chmod a+x /usr/local/bin/umount-menu.sh