Skip to content

Commit

Permalink
ext: Make work on non-rotational
Browse files Browse the repository at this point in the history
  • Loading branch information
cdown committed Dec 30, 2023
1 parent fbab61f commit e84b1cd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/enable-usb-trim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ shopt -s nullglob

device=${1?}

provs=( /sys/block/"$device"/device/scsi_disk/*/provisioning_mode )
provs=( /sys/block/"${device##*/}"/device/scsi_disk/*/provisioning_mode )
num_provs=${#provs[@]}

if (( num_provs != 1 )); then
Expand Down
11 changes: 10 additions & 1 deletion bin/ext
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ if ! (( UID )); then
exit 1
fi

bpl=/dev/disk/by-partlabel/ext

case ${1?} in
mount)
sudo mkdir -p /mnt/scratch{,-baduser}
sudo cryptsetup luksOpen /dev/disk/by-partlabel/ext ext

# This USB enclosure reports non-rotational, and TRIM isn't enabled by
# default, sigh...
part=$(readlink -f "$bpl")
device=${part%[0-9]}
sudo enable-usb-trim "$device"

sudo cryptsetup luksOpen --allow-discards /dev/disk/by-partlabel/ext ext
sudo mount /dev/mapper/ext /mnt/scratch-baduser
sudo bindfs -u "$(id -u)" --create-for-user="$(stat -c %u /mnt/scratch-baduser)" /mnt/scratch-baduser /mnt/scratch
;;
Expand Down
16 changes: 11 additions & 5 deletions bin/make-extdrive
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash -ex

update_parts() {
local device
device=${1?}
cat > /sys/block/"${1##*/}"/uevent <<< change
sleep 5 # hold for reprobe
}

device=${1?}
label=${2?}
cryptdev=ext
Expand All @@ -12,16 +19,15 @@ if [[ $device == *[0-9] ]]; then
fi

enable-usb-trim "$device"
blkdiscard "$device"
blkdiscard -f "$device"

update_parts "$device"

wipefs -a "$device"
sgdisk -Z "$device"
sgdisk -n 0:0:0 -c 1:"$label" "$device"

cat > /sys/block/"${device##*/}"/uevent <<< change

sleep 5 # hold for reprobe

update_parts "$device"

part="$device"1
unset device # safety measure to make sure we don't introduce some bug that
Expand Down

0 comments on commit e84b1cd

Please sign in to comment.