Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lshw (on Linux) with blockdev #6

Merged
merged 3 commits into from
Oct 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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.
```

Expand Down
17 changes: 9 additions & 8 deletions format-udf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -168,8 +168,9 @@ fi
###############################################################################

echo "[+] Gathering drive information..."
if [[ $TOOL_DRIVE_LISTING = $TOOL_LSHW ]]; then
sudo lshw -short -quiet | grep /dev/$DEVICE
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
else
Expand Down