Reduce EC2 Root Volume Size

0. Tested to work on Ubuntu 14.04
1. Stop source instance
2. Snapshot source instance root volume
3. Create a clone volumn from the snapshot from #2, name it INSTANCEKEY-origin
4. Launch a new instance with a volumn of the desired smaller size (don’t delete volumn on instance termination)
5. Terminate the new instance (all we need is the volume)
6. Name the volume from the new instance INSTANCEKEY-target
7. Attach INSTANCEKEY-origin volume to the source instance, as /dev/sdg
8. Attach INSTANCEKEY-target volume to the source instance, as /dev/sdf
9. Start source instance again
10. Run following:

mkfs -t ext4 /dev/xvdf1
mkdir /mnt/origin
mkdir /mnt/target
mount /dev/xvdg /mnt/origin
mount /dev/xvdf1 /mnt/target
rsync -aHAXxSP /mnt/origin/ /mnt/target

11. Check LABEL (all 3 should be the same) via

blkid

12. From the result of blkid, remember UUID of /dev/sda1 and /dev/sdf, replace UUID from /dev/sda1’s to /dev/sdf’s

vim /mnt/target/boot/grub/grub.cfg
:%s/FROM/TO/g

13. Poweroff the source instance
14. Detach all volumes
15. Attach the target volume to the source instance, with Device set to /dev/sda1
16. Start the source instance again, should be working with the new volume
17. Delete the snapeshot created from #2
18. Delete the original volume of the source instance, and the volume created from step 3 (i.e. the origin volume)
19. Update your snapshot backup script with the new volume id

Reference:

http://cloudacademy.com/blog/amazon-ebs-shink-volume/
http://serverfault.com/questions/673048/how-to-reduce-aws-ebs-root-volume-size

Cronjob at startup under OSX

#run: crontab -e
@reboot sudo /path/to/your-command

Additional you also need to edit sudo file by adding:

#run: sudo visudo
your-user-name ALL = NOPASSWD: /path/to/your-command

Config your own DNS server

This article assume you have a default Ubuntu 14.04 Server installed.

Config the DNS Server

Note:
10.0.0.200 should be your Ubuntu server’s IP
Assuming you want to use Google’s DNS (i.e. 8.8.8.8 and 8.8.4.4)
Added are two wildcard domains: *.app and *.dev and they will all point to localhost
You can also add more in /etc/dnsmasq.conf in this format “address=/DOMAIN/IP”

apt-get install dnsmasq
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.org

cat > /etc/dnsmasq.conf << EOL
domain-needed
bogus-priv
no-resolv
no-poll
server=/localnet/10.0.0.200
server=8.8.8.8
server=8.8.4.4
local=/localnet/
address=/double-click.net/127.0.0.1
no-hosts
expand-hosts
EOL

cat > /etc/dnsmasq.d/app-tld << EOL
local=/app/
address=/app/192.168.10.10
EOL

cat > /etc/dnsmasq.d/dev-tld << EOL
local=/dev/
address=/dev/127.0.0.1
EOL

service dnsmasq restart

Optional: Update your router to use your own custom DNS Server

If you do this the custom domains on your DNS will be applied to all computers using your router. And if you do this you don’t have to add your own DNS server IP to your NIC’s DNS Server list anymore.

OSX Terminal Slow Start Fix

Run:

sudo rm -rf /private/var/log/asl/*.asl

Then:

vim /etc/profile

Modify:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

To:

if [ -x /usr/libexec/path_helper ]; then
    PATH=""
    eval `/usr/libexec/path_helper -s`
fi

Screen Capture x1 Image Size Under Retina Macs

1. Open “Automator”
2. Select “Service” for “Choose a type for your document”
3. Change “Service receives no input in any application” on top right section of the Automator
4. Drag action “Run Shell Script” from the left pane into the workflow on the right pane
5. Make sure Shell setting is to “/bin/bash”
6. Add the following script to the script section (change the 2nd line setting for SS_PATH to your desktop absolute path) and save:

# the path where screenshots to save
SS_PATH="/Users/vincent/Desktop"
TMP_PATH="/tmp"

# a variable of unix timestamp for screenshot file name
NOW=$(date +%s)

# image format to create, default is png (other options include pdf, jpg, tiff and other formats)
SS_TYPE=png

# name of screenshot
SS_NAME=screenshot$NOW

# full path of screenshot file
SS_1X=$SS_PATH/$SS_NAME.$SS_TYPE
SS_2X=$TMP_PATH/$SS_NAME@2X.$SS_TYPE

# execute screen capture command and save to $SS_2X
screencapture -i -r -t $SS_TYPE $SS_2X

# check if screenshot is existing
if [ -f $SS_2X ]; then

    # get the 50% width of screenshot by sips
    WIDTH=$(($(sips -g pixelWidth $SS_2X | cut -s -d ':' -f 2 | cut -c 2-)/2))

    # scale down by sips
    sips --resampleWidth $WIDTH $SS_2X --out $SS_1X
    
    # copy small one to clipboard by applescript
    # if you hold control key when do capture, causes screen shot 2X to go to clipboard
    osascript -e 'set the clipboard to POSIX file "'$SS_1X'"'
fi

7. Open “System Preferences” > “Keyboard” > “Shortcuts”, find the service you just created and assign hotkey (e.g. Cmd+Shift+5).

OSX Slow Samba Client Fix

This may or may not fully fix the very screwed up implementation of SMB on OSX.

Fix 1 – nsmb.conf

echo "[default]" >> ~/Library/Preferences/nsmb.conf; echo "smb_neg=smb1_only" >> ~/Library/Preferences/nsmb.conf; echo "notify_off=yes" >> ~/Library/Preferences/nsmb.conf;

Fix 2 – net.inet.tcp.delayed_ack
Use Lingon to create a “User Daemon” that runs when loaded by the system to run this (Name doesn’t matter):

sudo sysctl -w net.inet.tcp.delayed_ack=0

After Fix 1 and Fix 2 reboot.