Skip to content

Instantly share code, notes, and snippets.

@estysdesu
Last active May 16, 2020 13:39
Show Gist options
  • Save estysdesu/4a05483b553fd2d77ccb69ac9fe436fe to your computer and use it in GitHub Desktop.
Save estysdesu/4a05483b553fd2d77ccb69ac9fe436fe to your computer and use it in GitHub Desktop.
[dd: Write to Disk/Create Swapfile] #dd #pv #status #progress #swapfile #swap
#!/usr/bin/env sh
dd status=progress if=/dev/zero of=/swapfile status=progress bs=1024 count=$[(1024**2)*4] && sync # 4G
chmod 0600 /swapfile
mkswap -L swap /swapfile
swapon /swapfile
#!/usr/bin/env sh
##### MACOS #####
brew install gnutls && brew install pv
dd bs=1024 if=$(ls | grep linux-minimal*.iso) | pv -s <size><K|M|G> | dd bs=1024 of=/dev/disk<number> && sync # or gdd bs=1024 status=progress if=$(ls | grep linux-minimal*.iso) of=/dev/<disk> && sync
##### LINUX #####
dd bs=1024 status=progress if=$(ls | grep linux-minimal*.iso) of=/dev/<disk> && sync
##### DD + PV #####
function ddpv {
# Inputs:
# $1 - file or grep pattern to locate a disk image file
# $2 - file or disk device to write disk image file to
if [ -z $1 ]; then
echo 'Please supply a file or a grep pattern to locate a disk image file'
exit 1
elif [ -z $2 ]; then
echo 'Please supply a file or disk device to write disk image file to'
exit 1
fi
if [ -e $1]; then
FILENAME_IN="$1"
SIZE=$(stat --format=%s $1)
else
FILESTAT="$(/bin/ls -l . | grep $1)"
FILENAME_IN="$(echo $FILESTAT | awk '{print $9}')"
SIZE="$(echo $FILESTAT | awk '{print $5}')"
fi
FILENAME_OUT="$2"
dd if="$FILENAME_IN" | pv -s $SIZE | sudo dd of="FILENAME_OUT"; sync
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment