Skip to content

Instantly share code, notes, and snippets.

@alexklibisz
Created December 26, 2014 07:50
Show Gist options
  • Save alexklibisz/97694dc363785446b610 to your computer and use it in GitHub Desktop.
Save alexklibisz/97694dc363785446b610 to your computer and use it in GitHub Desktop.
Linux shell script that determines whether or not a Linux partition in a Windows/Linux dual-boot is being booted directly or through VirtualBox and mounts the data directories accordingly
#!/bin/bash
DIR="/media/alex/Data"
# init
# delete all of the directories that should be symlinked in the home directory
rm -rf /home/alex/Desktop
rm -rf /home/alex/Documents
rm -rf /home/alex/Pictures
rm -rf /home/alex/Videos
# delete and recreate the /media/alex/Data directory, try to mount the data partition there
rm -rf $DIR
mkdir $DIR
mount /dev/sda3 $DIR
df -h
# check if the directory is empty after mounting the data partiton
if [ "$(ls -A $DIR)" ]; then
# the directory is not empty, so we are booted directly into linux, symlink directories from the data partition
ln -s /media/alex/Data/Users/Alex/Desktop /home/alex/Desktop
ln -s /media/alex/Data/Users/Alex/Documents /home/alex/Documents
ln -s /media/alex/Data/Users/Alex/Pictures /home/alex/Pictures
ln -s /media/alex/Data/Users/Alex/Videos /home/alex/Videos
else
# the directory is empty, so we are in virtualbox, symlink directories mounted from virtualbox
ln -s /media/sf_Desktop/ /home/alex/Desktop
ln -s /media/sf_Documents/ /home/alex/Documents
ln -s /media/sf_Pictures/ /home/alex/Pictures
ln -s /media/sf_Videos/ /home/alex/Videos
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment