2

I have a Debian 8 notebook which had a hardware failure (power board) which is a time consuming and error-prone repair. So I purchased a 2.5" HD USB enclosure and placed the HD from the notebook in it and connected to my XUbuntu so I can recover some important files. The now USB drive does mount but mounts to what I assume is the boot partition. I need to get access to the data (/) partition which I think is a logical partition on /dev/sdb5 (see below).

Could someone help me with the proper mknod mount commands to mount the / logical volume?

Below is an image from an fdisk -l command (showing the USB drive) and the related device files.

Thanks! John

fdisk -l and device file of Debian USB drive

  • 2
    Please don't put images of texts. Copy and paste the text into the question and format the text as "code". – user68186 Aug 11 '18 at 23:42

2 Answers2

1

Script to mount drive - mount-menu.sh

The mount-menu.sh script allows you to select unmounted drives/partitions for mounting. To call the script use: sudo mount-menu.sh. This screen appears tailored to your unique machine environment:

mount-menu 1.png

  • Use arrow keys to select the partition and press Enter

The menu clears and leaves this information in your terminal:

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

Now you can use: cd /mnt/mount-menu.FPRAW to access your external drive's partition.

Then you can use cd home/YOUR_NAME being mindful not to put a / in front of home. Should you use cd /home it would take you to your boot drive and out of the external drive.

mount-menu.sh script contents

To create the script open the terminal and type:

sudo -H gedit /usr/local/bin/mount-menu.sh

Then copy the code below and paste it into gedit. Save the file and exit gedit.

Now mark the file as executable using:

sudo chmod a+x /usr/local/bin/mount-menu.sh

Here's the script to copy:

#!/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 &quot;Use arrow, page, home &amp; end keys. Tab toggle option&quot; \
    --backtitle &quot;Mount Partition&quot; \
    --ok-button &quot;Select unmounted partition&quot; \
    --cancel-button &quot;Exit&quot; \
    --notags \
    --default-item &quot;$DefaultItem&quot; \
    --menu &quot;$MenuText&quot; 24 80 16 \
    &quot;${AllPartsArr[@]}&quot; \
    2&gt;&amp;1 &gt;/dev/tty)

clear                                   # Clear screen.
if [[ $Choice == &quot;&quot; ]]; then            # Escape or dialog &quot;Exit&quot;.
    CleanUp
    exit 1;
 fi

DefaultItem=$Choice                     # whiptail start option.
ArrNdx=$(( $Choice * 2 + 1))            # Calculate array offset.
Line=&quot;${AllPartsArr[$ArrNdx]}&quot;          # Array entry into $Line.

# Validation - Don't wipe out Windows or Ubuntu 16.04:
# - Partition must be ext4 and cannot be mounted.

if [[ &quot;${Line:MOUNTPOINT_col:4}&quot; != &quot;    &quot; ]] ; then
    echo &quot;Partition is already mounted.&quot;
    read -p &quot;Press &lt;Enter&gt; to continue&quot;
    continue
fi

# Build &quot;/dev/Xxxxx&quot; FS name from &quot;├─Xxxxx&quot; menu line
MountDev=&quot;${Line%% *}&quot;
MountDev=/dev/&quot;${MountDev:2:999}&quot;

# Build File System Type
MountType=&quot;${Line:FSTYPE_col:999}&quot;
MountType=&quot;${MountType%% *}&quot;

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 to Unmount Drives/Partitions

Repeat the file creation / execute bit marking process for the script umount-menu.sh. This script only unmounts drives / partitions that were mounted by mount-menu.sh. It has the same selection menu and completes with the message:

=====================================================================

/dev/nvme0n1p10 mounted on /mnt/mount-menu.FPRAW unmounted.

To call the script use: sudo umount-menu.sh

umount-menu.sh bash script:

!/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=&quot;$Line$SPACES&quot;                     # Pad extra white space.
Line=${Line:0:74}                       # Truncate to 74 chars for menu.

AllPartsArr+=($i &quot;$Line&quot;)               # 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 &quot;Use arrow, page, home &amp; end keys. Tab toggle option&quot; \
    --backtitle &quot;Mount Partition&quot; \
    --ok-button &quot;Select unmounted partition&quot; \
    --cancel-button &quot;Exit&quot; \
    --notags \
    --default-item &quot;$DefaultItem&quot; \
    --menu &quot;$MenuText&quot; 24 80 16 \
    &quot;${AllPartsArr[@]}&quot; \
    2&gt;&amp;1 &gt;/dev/tty)

clear                                   # Clear screen.

if [[ $Choice == &quot;&quot; ]]; then            # Escape or dialog &quot;Exit&quot;.
    CleanUp
    exit 1;
 fi

DefaultItem=$Choice                     # whiptail start option.
ArrNdx=$(( $Choice * 2 + 1))            # Calculate array offset.
Line=&quot;${AllPartsArr[$ArrNdx]}&quot;          # Array entry into $Line.

if [[ &quot;${Line:MOUNTPOINT_col:15}&quot; != &quot;/mnt/mount-menu&quot; ]] ; then
    echo &quot;Only Partitions mounted by mount-menu.sh can be unounted.&quot;
    read -p &quot;Press &lt;Enter&gt; to continue&quot;
    continue
fi

# Build &quot;/dev/Xxxxx&quot; FS name from &quot;├─Xxxxx&quot; menu line
MountDev=&quot;${Line%% *}&quot;
MountDev=/dev/&quot;${MountDev:2:999}&quot;

# Build Mount Name
MountName=&quot;${Line:MOUNTPOINT_col:999}&quot;
MountName=&quot;${MountName%% *}&quot;

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

  • However I am having problems getting it to work. The script runs fine and I do get the list of partitions on the drive and I select the partition sdb5:

    There are logical volumes on this partition. Any ideas? │ └─sdb5 LVM2_member 232.7G │

    However this is what I get when I select the sdb5 partition:

    mount: /mnt/mount-menu.Mj4Rz: unknown filesystem type 'LVM2_member'. Mount Device: /dev/sdb5 Mount Name: /mnt/mount-menu.Mj4Rz File System: LVM2_member Partition appears empty

    – bassdeal Sep 01 '18 at 19:29
  • 1
    @bassdeal A few extra steps are required when mounting an LVM partition: https://unix.stackexchange.com/questions/339011/how-do-i-mount-an-lvm-partition – WinEunuuchs2Unix Sep 01 '18 at 19:40
  • It turned out all I needed to do was install lvm2. When I did that and plugged in the USB hard drive both the boot partition and the '/' partition of the LVM were both mounted. I did not have to do any of the other steps. – bassdeal Sep 05 '18 at 16:54
0

I can not reverse all the steps I took but when I installed lvm2 and plugged the USB hard drive in, both the boot partition and the '/' partition of the LVM were mounted automatically. I did not run the mount-menu.sh script.

So somebody in the original situation should try installing lvm2 and it may just mount everything you need.

XUbuntu 18.04 64-bit.