如何将 /media 安装的 USB 加密狗变成 /mnt 安装的 USB 加密狗?

如何将 /media 安装的 USB 加密狗变成 /mnt 安装的 USB 加密狗?

我正在尝试使 /dev/sda 成为 /dev/mmcblk 设备,我发现唯一的方法是通过将其安装在 /mnt/ 来无限期安装 /media/ 安装的 USB 加密狗。

但是...对于未无限期安装的 USB 加密狗,我应该如何使用 /mnt/ 处的挂载点,以便我可以更新 /dev/ 来处理 /dev/mmcblk?

答案1

好吧,这里什么也没发生,如果这不起作用,请告诉我。

以特权运行script.sh

#!/bin/bash

## Test in a directory first
#export BASE_PATH='.'
export BASE_PATH='/dev'

## Device names
export KNAME_DRIVE='sda'
export KNAME_MMC='mmcblk0'

## Character between disk kname and partition number
export PREFIX_DRIVE_PART=''
export PREFIX_MMC_PART='p'

## Symlink for device
ln -s "${BASE_PATH}/${KNAME_DRIVE}" "${BASE_PATH}/${KNAME_MMC}"

## Symlinks for partitions
# Get only two specified columns.
# Filter for desired drive.
# Prints the partition kname.
# xargs -i iterating over lines, {} being the iterator's value
# $'' increasing readability.
# ${VAR1##${VAR2}} being value of first instance of string VAR2 being substracted from string VAR1
lsblk --raw --noheadings -o NAME,KNAME \
| grep "${KNAME_DRIVE}" \
| awk -v kname_drive="${KNAME_DRIVE}" '{
    if ($1 != kname_drive) {
        print $2
    }
}' \
| xargs -i bash -c $'KNAME_DRIVE_PART="{}";
PATH_DESTINATION="${BASE_PATH}/${KNAME_DRIVE_PART}";
PATH_SYMLINK_FILE="${BASE_PATH}/${KNAME_MMC}${PREFIX_MMC_PART}${KNAME_DRIVE_PART##${KNAME_DRIVE}${PREFIX_DRIVE_PART}}";
ln -s ${PATH_DESTINATION} ${PATH_SYMLINK_FILE};
'

相关内容