Last active
June 19, 2022 17:23
-
-
Save Nircek/2101dc89d0898754ca6aa67b8e799b27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function confirm() { | |
# https://stackoverflow.com/a/1885534/6732111 | |
read -p "Is it ok? " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell | |
fi | |
} | |
# sudo dd if=/dev/zero of=/dev/sdb bs=4M count=6 oflag=direct; ls /dev/sdb* | |
[[ $# != 2 ]] && { echo "usage: $0 /dev/sd* img.iso"; exit; }; | |
ls -lah "$2" | |
stat --printf="%s\n" "$2" # src: https://unix.stackexchange.com/a/16644/450009 | |
lsblk -b --output SIZE -n -d "$1" | |
echo | |
echo $ sudo dd "of=$1" "if=$2" | |
confirm || exit | |
sudo dd bs=4M status=progress conv=fsync oflag=direct "of=$1" "if=$2" | |
sleep 2 | |
printf "p\nn\n\n\n\n\np\n" | sudo fdisk --wipe=never -t gpt "$1" | |
confirm || exit | |
printf "p\nn\n\n\n\n\np\nw\nq\n" | sudo fdisk --wipe=never -t gpt "$1" | |
sync | |
sudo partprobe "$1" | |
sleep 2 | |
ls $1* | |
part=$(ls $1* | tail -n1) | |
echo "The last partition is '$part'." | |
confirm || exit | |
sudo mkfs.ext4 "$part" | |
mnt="/tmp/$(uuidgen)" | |
mnt="${mnt,,}" # https://serverfault.com/a/103366/947767 | |
echo "Random temporary dir: $mnt" | |
confirm || exit | |
sudo mkdir "$mnt" | |
sudo mount "$part" "$mnt" | |
echo "inxi -pildfForumxxxv8c0tmc||inxi -pildfForumxxxv 7 -c 0 -tmc" | sudo tee "$mnt/gather.sh" > /dev/null # https://gist.github.com/Nircek/acb62cdebd3b6029e160551dfc636c52 | |
sudo chown -R 1000:1000 "$mnt" | |
ls -lah "$mnt" | |
echo Reinsert your USB stick to tease gvfs/udisks2... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That should be multiplied by 1024 or 1000 to get the capacity of drive in bytes.
https://gist.github.com/Nircek/2101dc89d0898754ca6aa67b8e799b27/db06639bed8e142e6061ca1a7f69d42acb9cf5c1#file-dd-system-sh-L15