Skip to content

Instantly share code, notes, and snippets.

View jsafrit's full-sized avatar

John Safrit jsafrit

View GitHub Profile
MOUNTING A HARD DISK IMAGE INCLUDING PARTITIONS USING LINUX
JANUARY 22, 2008 ANDRE 63 COMMENTS
A while ago I thought it would be a good idea to make a backup of my Linux server by just dumping the complete disk to a file. In retrospect, it would have been much easier had I just dumped the individual filesystems.
When I finally got around to using this backup, long after the 10GB disk had perished I realized that to use the loopback device to mount a filesystem it actually needs a filesystem to mount. What I had was a disk image, including partition table and individual partitions. To further complicate matters the data partition was also not the first partition inside this image.
For reference, I created this image using the Unix ‘dd’ tool:
# dd if=/dev/hda of=hda.img
30544113+0 records in
30544113+0 records out
# ls -lh
-rw-r--r-- 1 root root 9.6G 2008-01-22 14:12 hda.img
@jsafrit
jsafrit / checkInternet
Last active July 4, 2017 21:16
bash check for internet connectivity
checkInternet()
{
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1 # query google with a get request
if [ $? -eq 0 ]; then #check if the output is 0, if so no errors have occured and we have connected to google successfully
return 0
else
echo "Error: no active internet connection" >&2 #sent to stderr
return 1
fi
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jsafrit
jsafrit / screenlst.sh
Created July 27, 2015 20:07
interactive screen selection
#!/bin/bash
# filters the screen -ls output to show the sesssions
sessions=`screen -ls | sed -ne 's/[[:space:]]//' -ne 's/\((Attached)\|(Detached)\|(Multi, detached)\|(Multi, attached)\)// p'`
#echo $sessions
#echo $sessions | wc -w
res=`echo "$sessions" | wc -w`
if [[ "$res" != "0" ]]
then
@jsafrit
jsafrit / gitconfig
Created January 16, 2015 04:06
My git setup
[user]
name = John Safrit
email = jsafrit@users.noreply.github.com
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
@jsafrit
jsafrit / bash_aliases
Last active August 29, 2015 14:12
Custom bash alias file
# some more ls aliases
alias ll='ls -alF'
alias more='less'
alias la='ls -A'
alias l='ls -CF'
alias h="history"
alias gno="gnome-open"
alias pu="pushd"
alias po="popd"