Daniel Ngu

Raspberry Pi 3

Backup

Backup SD Card Image
1
2
$ sudo dd bs=4M if=/dev/sde of=raspbian.img    # backup
$ sudo dd bs=4M if=raspbian.img of=/dev/sde    # restore

or

Backup SD Card Image With Compression
1
2
$ sudo dd bs=4M if=/dev/sde | gzip > rasbian.img.gz             # backup
$ gunzip --stdout rasbian.img.gz | sudo dd bs=4M of=/dev/sde    # restore

Reference: Backups

Media

ISO available via Arch download page.

Installation

Installation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ fdisk /dev/sde
$ o                      # Clear out any partitions on the drive
$ p                      # List partitions
$ n                      # New partition
$ p                      # Primary
$ 1                      # First partition on drive
$ Enter                  # Accept default first sector
$ +100M                  # 100MB for boot partition
$ t                      # Partition type
$ c                      # Set partition type to W95 FAT32 (LBA)
$ n                      # New partition
$ p                      # Primary
$ 2                      # Second partition on drive
$ Enter                  # Accept default first sector
$ Enter                  # Accept default last sector
$ mkfs.vfat /dev/sde1    # Create and mount the FAT filesystem
$ mkdir boot
$ mount /dev/sde1 boot
$ mkfs.ext4 /dev/sde2    # Create and mount the ext4 filesystem
$ mkdir root
$ mount /dev/sde2 root
Download and extract the root filesystem (as root, not via sudo)
1
2
3
4
5
$ wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
$ bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root
$ sync
$ mv root/boot/* boot    # Move boot files to the first partition
$ umount boot root       # Unmount the two partitions

Default:
user: alarm
password: alarm

user: root
password: root

Reference: ARMv7 Installation

Wireless

Setup Wireless Network
1
2
3
4
$ pacman -S dialog wpa_supplicant
$ wifi-menu
$ ls /etc/netctl/               # Find the wifi profile
$ netctl enable profile-name    # Substitute profile-name as obtained above

Create New User

Create New User
1
2
3
$ useradd -m -G wheel -s /bin/bash daniel
$ passwd daniel
$ usermod -a -G audio,network,power,scanner,storage,systemd-journal,video daniel

The above creates a new user with home directory, change password and add user to additional groups.

Sudo

Install Sudo
1
$ pacman -S sudo

Run visudo, edit it to restrict sudo to specific group or user.

Update

Update
1
2
$ sudo pacman -Syu
$ sudo pacman -Syy              # If above failed

Xfce

Install Xfce
1
2
3
4
$ sudo pacman -S xfce4
$ sudo pacman -S xorg-server xorg-server-utils xorg-xinit
$ sudo pacman -S xf86-video-fbdev
$ startxfce4                    # NOTE: To manually start Xfce

Additional Install

Additional Install
1
2
3
$ sudo pacman -S openssh
$ sudo pacman -S vim
$ sudo pacman -S tigervnc

dotfiles

Apply the dotfiles

VNC Setup

VNC Setup
1
2
$ vncserver                     # Create configs
$ vncserver -kill :1            # NOTE: To shutdown vncserver
~/.vnc/xstartup
1
2
3
#!/bin/sh

exec /bin/sh /etc/xdg/xfce4/xinitrc
/etc/systemd/system/vncserver@:1.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=daniel
PAMName=login
PIDFile=/home/daniel/.vnc/%H:%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -geometry 1280x720 -alwaysshared -fg %i
ExecStop=/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target
Enable vncserver@:1.service
1
$ sudo systemctl enable vncserver@:1.service

VNC Client

Use TightVNC
Port: 5901

Mount USB Drive

Mount USB Drive
1
$ sudo mount /dev/sda1 /mnt/usb -o uid=1000,gid=1000,utf8,dmask=027,fmask=137

sshfs

Install sshfs
1
2
$ brew cask install osxfuse
$ brew install sshfs

Plex

Plex Media Server

prelink from AUR.
plex-media-server from AUR.

Configuration

Edit plexmediaserver.service
1
$ sudo vim /usr/lib/systemd/system/plexmediaserver.service

Set a maximum amount of memory by inserting a new line entry of MemoryLimit=2G

Edit iptables
1
2
3
$ iptables -A INPUT -p tcp -m multiport --dports 32400,32469 -j ACCEPT
$ iptables -A INPUT -p udp -m multiport --dports \
> 1900,32410,32412,32413,32414 -j ACCEPT
Enable plexmediaserver.service
1
$ sudo systemctl enable plexmediaserver.service

Storage

Directory Structure
1
$ sudo mkdir /shares
Drive Details
1
2
$ df -h
$ sudo blkid /dev/sdb1
/etc/fstab
1
2
# UUID=1f22599a-6b0f-4b90-81b0-4c471f761f47
/dev/sdb1    /shares    ext4    rw,relatime,data=ordered    0 3

Reboot

Directory Structure
1
2
3
4
5
$ cd /shares
$ mkdir plex
$ sudo chgrp plex plex
$ sudo chmod g+w,o-rx plex
$ sudo usermod -a -G plex daniel

Reference: Plex

I3

Packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo pacman -S i3
$ sudo pacman -S dmenu
$ sudo pacman -S feh                     # for wallpaper
$ sudo pacman -S scrot                   # for screenshot
$ sudo pacman -S mplayer
$ sudo pacman -S archey3
$ sudo pacman -S cmus
$ sudo pacman -S gpicview
$ sudo pacman -S firefox                 # optional
$ sudo pacman -S dnsutils
$ sudo pacman -S whois
$ sudo pacman -S imagemagick
$ sudo pacman -S easytag
$ sudo pacman -S rdesktop freerdp        # optional
~/.config/i3/config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Pulse Audio controls
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% #increase sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% #decrease sound volume
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle #mute sound

# pause / play / next / previous
bindsym XF86AudioPlay exec cmus-remote -C "player-pause"
bindsym XF86AudioNext exec cmus-remote -n
bindsym XF86AudioPrev exec cmus-remote -r

# Sreen brightness controls
bindsym XF86MonBrightnessUp exec xbacklight -inc 20 #increase screen brightness
bindsym XF86MonBrightnessDown exec xbacklight -dec 20 #decrease screen brightness

exec --no-startup-id feh --recursive --randomize --bg-center ~/Pictures/wallpaper

Optional: JRE

Run /usr/lib/jvm/java-7-jre/jre/bin/ControlPanel to configure.

Octopress

General maintenance related tasks:

Upgrades
1
2
3
4
5
6
7
8
9
10
11
$ rvm get stable                 # RVM
$ rvm install 2.2.3              # Ruby
$ rvm --default use 2.2.3        # Set default version
$ rvm rubygems latest            # RubyGems
$ gem install bundler            # Dependencies
$ bundle install                 # Run within blog directory
$ rvm -v                         # Check versions
$ ruby -v
$ which ruby
$ gem -v
$ which gem

Arch uses Python version 3, whereas Octopress requires verions 2. Edit the first line of mentos.py to the following instead:

~/.rvm/gems/ruby-2.2.3/gems/pygments.rb-0.3.4/lib/pygments/mentos.py
1
#!/usr/bin/env python2

Migrating to another computer:

Install RVM
1
curl -L https://get.rvm.io | bash -s stable --ruby

Then do the upgrades as listed above.

Clone blog
1
2
3
$ git clone -b source git@github.com:username/username.github.io.git
$ cd username.github.io.git
$ git clone git@github.com:username/username.github.io.git _deploy

Install the dependencies as listed above.

To maintain the blog on multiple computers:

Push on one:

Push
1
2
3
4
5
$ rake generate
$ rake deploy
$ git add .
$ git commit -a
$ git push origin source

Pull on the other:

Pull
1
2
3
$ git pull origin source
$ cd ./_deploy
$ git pull origin master

Wayland

Disable Wayland if it’s not supported to avoid GDM startup problems.

Edit /etc/gdm/custom.conf file and uncomment the following line:

/etc/gdm/custom.conf
1
#WaylandEnable=false

Reference: Use Xorg backend.

Backup and Restore

I’m currently using Partclone for backing up and restoring Arch. That’s essentially done by booting up Clonezilla ISO available via download page.

Follow through the wizard to mount external drive and then use the Partclone commands off Arch wiki page with sudo.

Alternatively, a better option is to clone the entire drive (save disk image) for backup. Then restore it with “restore disk image”.

OS X Installation

Media

Obtainable from Applications prior to installation when downloaded from App Store.

To create bootable USB flash drive:
Open Disk Utility, select the drive.
Choose Partition tab, select 1 Partition from Partition Layout.
Click Options, choose GUID Partition Table, then OK and Apply.

Media
1
2
3
$ sudo Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia \
--volume /Volumes/untitled --applicationpath Install\ OS\ X\ Mavericks.app \
--nointeraction

Installation

Reboot while holding down the option key.
Select the USB flash drive.
For clean install, select Disk Utility. Erase the / partition.
After that, select Reinstall OS X.

External Monitor

Resolution

Workaround for undetected resolutions:

xorg.conf
1
2
$ nvidia-xconfig                # Create xorg.conf based on detected hardware
$ sudo vim /etc/X11/xorg.conf

Amend Monitor section of xorg.conf with the correct specifications. In my case, the HorizSync and VertRefresh values were incorrect.

Reboot, then check display for native resolution.

If it’s not listed, run the following to get its modeline details.

Modeline
1
2
3
4
$ cvt 1680 1050
# 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
Modeline "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089
-hsync +vsync

Add the modeline values to xorg.conf

/etc/X11/xorg.conf
1
2
3
4
5
6
7
8
9
10
Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Samsung"
    ModelName      "SyncMaster 2253BW"
    HorizSync       30.0 - 81.0
    VertRefresh     56.0 - 75.0
    Option         "DPMS"
    Modeline       "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053
                    1059 1089 -hsync +vsync
EndSection

Reboot, the native resolution should now be listed.

DLNA

PS3 Media Server

Install PS3 Media Server
1
2
3
4
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:happy-neko/ps3mediaserver
$ sudo apt-get update
$ sudo apt-get install ps3mediaserver

Directory Structure

Directory Structure
1
2
3
4
5
6
$ sudo mkdir -p /shares/stream        # stream directory
$ cd /shares
$ sudo groupadd stream
$ sudo chgrp stream stream
$ sudo chmod g+w,o-rx stream
$ sudo usermod -a -G stream daniel

ps3

Create ps3 Account
1
2
$ sudo useradd -m -G stream -s /bin/bash ps3
$ sudo passwd ps3

Daemon

/etc/default/ps3mediaserver
1
2
3
PMS_START="yes"
PMS_USER="ps3"
PMS_PROFILE="/home/$PMS_USER/.config/ps3mediaserver"

Config

/etc/samba/smb.conf
1
2
3
4
5
6
[Stream]
comment = Stream
path = /shares/stream
browseable = yes
read only = no
valid users = daniel
/home/ps3/.config/ps3mediaserver/PMS.conf
1
2
3
usecache = false
hide_empty_folders = true
folders = /shares/stream

Remove /home/ps3/.config/ps3mediaserver/WEB.conf

Reboot

Tip

Needed sometimes if media not playing, especially newly added.

Restart Daemon
1
$ sudo service ps3mediaserver restart

Samba Setup

Directory Structure

Directory Structure
1
2
3
4
5
6
$ sudo mkdir -p /shares/data          # data directory
$ cd /shares/data
$ sudo mkdir daniel                   # home directory
$ sudo groupadd data
$ sudo chown daniel:data daniel
$ chmod o-rx daniel

sysadmin

Create sysadmin Account
1
2
$ sudo useradd -m -G data -s /bin/bash sysadmin
$ sudo passwd sysadmin

Config

/etc/samba/smb.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
workgroup = <workgroup-name>
wins support = yes
name resolve order = lmhosts host wins bcast
security = user

[Data]
comment = Data
path = /shares/data
browseable = yes
read only = yes
valid users = sysadmin

[Daniel]
comment = Daniel
path = /shares/data/daniel
browseable = yes
read only = no
valid users = daniel

Sets Samba password. I think smbpasswd ties in with passwd but needed in this case since password was set prior to Samba installation.

Set Samba Password
1
$ smbpasswd -a daniel