From e1113e8ee9b1d552583eca75dd54784f5154d65d Mon Sep 17 00:00:00 2001 From: Jonathan Elchison Date: Mon, 6 Oct 2014 17:14:10 -0400 Subject: [PATCH 1/3] Replacing lshw (on Linux) with blockdev --- README.md | 17 ++++++++++------- format-udf.sh | 15 ++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 683868e..54b4564 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ DOS, FreeDOS, Windows 3.11 or older |Filesystems that have an ISO9660 backward c * false * awk * dd - * *One* of the following: lshw, diskutil + * *One* of the following: blockdev, diskutil * *One* of the following: umount, diskutil * *One* of the following: mkudffs, newfs_udf @@ -90,25 +90,28 @@ Example: # Example usage On Ubuntu: ``` -user@computer:~$ ./format-udf.sh sdi "My External Drive" +user@computer:~$ ./format-udf.sh sdb "My External Drive" [+] Testing dependencies... -[+] Looking for drive listing tool... using /usr/bin/lshw +[+] Looking for drive listing tool... using /sbin/blockdev [+] Looking for unmount tool... using /bin/umount [+] Looking for UDF tool... using /usr/bin/mkudffs [+] Validating arguments... [+] Gathering drive information... +Patriot Memory [sudo] password for user: -/0/b/0.0.0 /dev/sdi disk 4003MB SCSI Disk +RO RA SSZ BSZ StartSec Size Device +rw 256 512 4096 0 4003463168 /dev/sdb The above-listed drive (and partitions, if any) will be completely erased. Type 'yes' if this is what you intend: yes [+] Detecting native sector size... [+] Validating detected sector size... [+] Unmounting drive... +umount: /dev/sdb: not mounted [+] Zeroing out any existing partition table on drive... 4096+0 records in 4096+0 records out -2097152 bytes (2.1 MB) copied, 0.737711 s, 2.8 MB/s -[+] Formatting /dev/sdi ... +2097152 bytes (2.1 MB) copied, 0.924472 s, 2.3 MB/s +[+] Formatting /dev/sdb ... start=0, blocks=64, type=RESERVED start=64, blocks=12, type=VRS start=76, blocks=180, type=USPACE @@ -120,7 +123,7 @@ start=7819007, blocks=1, type=ANCHOR start=7819008, blocks=239, type=USPACE start=7819247, blocks=16, type=RVDS start=7819263, blocks=1, type=ANCHOR -[*] Successfully formatted /dev/sdi: LABEL="My External Drive" TYPE="udf" +[*] Successfully formatted /dev/sdb: LABEL="My External Drive" TYPE="udf" Please disconnect/reconnect your drive now. ``` diff --git a/format-udf.sh b/format-udf.sh index 43c76e5..e6e6d7e 100755 --- a/format-udf.sh +++ b/format-udf.sh @@ -61,17 +61,17 @@ fi # ensure have required drive listing tool echo -n "[+] Looking for drive listing tool..." # `true` is so that a failure here doesn't cause entire script to exit prematurely -TOOL_LSHW=$(which lshw) || true +TOOL_BLOCKDEV=$(which blockdev) || true # `true` is so that a failure here doesn't cause entire script to exit prematurely TOOL_DISKUTIL=$(which diskutil) || true -if [[ ! -x $TOOL_LSHW ]] && [[ ! -x $TOOL_DISKUTIL ]]; then +if [[ ! -x $TOOL_BLOCKDEV ]] && [[ ! -x $TOOL_DISKUTIL ]]; then echo - echo "[-] Dependencies unmet. Please verify that at least one of the following are installed, executable, and in the PATH: lshw, diskutil" >&2 + echo "[-] Dependencies unmet. Please verify that at least one of the following are installed, executable, and in the PATH: blockdev, diskutil" >&2 exit 1 fi # select drive listing tool -if [[ -n "$TOOL_LSHW" ]]; then - TOOL_DRIVE_LISTING=$TOOL_LSHW +if [[ -n "$TOOL_BLOCKDEV" ]]; then + TOOL_DRIVE_LISTING=$TOOL_BLOCKDEV elif [[ -n "$TOOL_DISKUTIL" ]]; then TOOL_DRIVE_LISTING=$TOOL_DISKUTIL else @@ -168,8 +168,9 @@ fi ############################################################################### echo "[+] Gathering drive information..." -if [[ $TOOL_DRIVE_LISTING = $TOOL_LSHW ]]; then - sudo lshw -short -quiet | grep /dev/$DEVICE +cat /sys/block/$DEVICE/device/model +if [[ $TOOL_DRIVE_LISTING = $TOOL_BLOCKDEV ]]; then + sudo blockdev --report | egrep "(Device|$DEVICE)" elif [[ $TOOL_DRIVE_LISTING = $TOOL_DISKUTIL ]]; then diskutil list $DEVICE else From 5e5faae107017c077fcfd2f1aac87ce1b1b45af5 Mon Sep 17 00:00:00 2001 From: Jonathan Elchison Date: Mon, 6 Oct 2014 22:30:24 -0400 Subject: [PATCH 2/3] Moving /sys/ name dump to Linux-only section --- format-udf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format-udf.sh b/format-udf.sh index e6e6d7e..473f1b1 100755 --- a/format-udf.sh +++ b/format-udf.sh @@ -168,8 +168,8 @@ fi ############################################################################### echo "[+] Gathering drive information..." -cat /sys/block/$DEVICE/device/model if [[ $TOOL_DRIVE_LISTING = $TOOL_BLOCKDEV ]]; then + cat /sys/block/$DEVICE/device/model sudo blockdev --report | egrep "(Device|$DEVICE)" elif [[ $TOOL_DRIVE_LISTING = $TOOL_DISKUTIL ]]; then diskutil list $DEVICE From 5b618e440c44baa86696e1e3e87f6ec3a081d605 Mon Sep 17 00:00:00 2001 From: Jonathan Elchison Date: Mon, 6 Oct 2014 22:49:29 -0400 Subject: [PATCH 3/3] Updating internal version to 1.0.2 --- format-udf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format-udf.sh b/format-udf.sh index 473f1b1..1288d39 100755 --- a/format-udf.sh +++ b/format-udf.sh @@ -4,7 +4,7 @@ # # Bash script to format a block drive (hard drive or Flash drive) in UDF. The output is a drive that can be used for reading/writing across multiple operating system families: Windows, OS X, and Linux. This script should be capable of running in OS X or in Linux. # -# Version 1.0.1 +# Version 1.0.2 # # Copyright (C) 2014 Jonathan Elchison #