Mount usb linux command line

# ways to find flash drive
dmesg | tail
sudo fdisk -l
lsusb
ls /dev/sd*
df -h
gnome-disks

# make a directory to mount the usb
sudo mkdir /media/usb

# mount usb
# to grant permission to all when mounting add umask flag. For only root omit flag.
sudo mount -o umask=000 /dev/sda1 /media/usb

# if error mount: unknown filesystem type 'exfat'
sudo apt-get install exfat-fuse exfat-utils

# mount on every boot
# determine the partition/filesystem type for proc column
sudo blkid /dev/sda*

# edit file
sudo nano /etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1       /media/usb      exfat   defaults
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

# unmount
sudo umount /dev/sda1

# resources
How to Mount USB Drive on the Raspberry Pi

# tags
ntfs fat32 ext4

Installing Gitlab

Raspberry Pi

# login as root
$ sudo su

# follow gitlab installation for specified operating system
$ apt-get install gitlab-ce

# install web server
$ apt-get install nginx

# check log for errors. Port conflicts will be notified
$ cat /var/log/nginx/error.log

# change port if desired
$ nano /etc/nginx/sites-enabled/default

server {
        listen 81 default_server;
        listen [::]:81 default_server;

        # SSL configuration

# reconfigure gitlab
$ gitlab-ctl reconfigure

# change gitlab port to match nginx port
$ nano /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.example.com
    port: 81
    https: false

.......

test:
  <<: *base
  gravatar:
    enabled: true
  gitlab:
    host: localhost
    port: 81

# change gitlab port to match nginx port
$ nano /etc/gitlab/gitlab.rb

## Url on which GitLab will be reachable.
## For more details on configuring external_url see:
## https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#configuring-the-external-url-for-gitlab
external_url 'http://gitlab.com.local:81/'

........

## Advanced settings
# unicorn['listen'] = '127.0.0.1'
# unicorn['port'] = 8081
# unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
# unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid'

# reconfigure gitlab
$ gitlab-ctl reconfigure

# restart gitlab
$ sudo gitlab-ctl restart

# restart server
$ sudo reboot

# restart nginx
$ /etc/init.d/nginx restart

# check if listen to port
$ nmap -sS 192.168.0.14

PORT     STATE SERVICE
81/tcp   open  hosts2-ns
85/tcp   open  mit-ml-dev
443/tcp  open  https
3128/tcp open  squid-http
3389/tcp open  ms-wbt-server
9418/tcp open  git

# navigate to page. Be careful with browser cache (especially firefox)
http://192.168.0.14:81/

# gitlab repositories location
$ sudo su
$ cd /var/opt/gitlab/git-data/repositories/

sources

http://www.thecfguy.com/blog/how-to-change-default-port-for-gitlab/

troubleshooting

# Reconfigure freezes at ruby_block[supervise_redis_sleep] action run
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/430#note_1308607
http://stackoverflow.com/questions/22328923/impossible-to-install-gitlab-on-ubuntu-12-04#answer-25785708

when accessing the file tab there was an ajax request that was loading a 500 error page.
Looked into the log by running
$ sudo gitlab-ctl tail
and found this error message

Errno::ENOMEM (Cannot allocate memory - /opt/gitlab/embedded/bin/git):
.......

Found out that not enough memory was being allocate. May be because its a raspberry pi and it has limited memory.
The solution was to reduce unicorn worker processes thus reducing the memory consumption.
$ nano /etc/gitlab/gitlab.rb

##################
# GitLab Unicorn #
##################
## Tweak unicorn settings.

# unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 1

# Deleting branches and committing changes (edit file) using GitLab hangs it
error: proxyRoundTripper: POST " failed with: "EOF"

The corresponding unicorn worker waits for the git hook to complete and can not serve other requests during this time. The hook uses the GitLab web API to check if the user is allowed to execute the requested git operation. Because I had unicorn running with only one worker, no other worker was available to serve the API request, thus resulting in a deadlock.
https://gitlab.com/gitlab-org/gitlab-ce/issues/13947

$ nano /etc/gitlab/gitlab.rb

unicorn['worker_processes'] = 2

# remove GitLab
$ apt-get purge gitlab-ce

# remove nginx
$ apt-get purge nginx nginx-common nginx-full

Use apache server instead of nginx

followed these these steps

# Additional
Before running 'gitlab-ctl reconfigure', first run 'gitlab-ctl start postgresql', else there will be an error that postgresql is not running.

# enable apache modules
# http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#comment-65475363
# http://askubuntu.com/questions/64454/how-do-i-enable-the-mod-rewrite-apache-module-for-ubuntu-11-04#answer-64460
$ sudo a2enmod rewrite
$ sudo a2enmod proxy_http

If you get permission errors like "You don't have permission to access /assets/logo-white-0b53cd4ea06811d79b3acd486384e047.png on this server." then you need "Require all granted" in the <Location> in your apache vhost configuration file

# sources
http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#answer-25809733

Setup linux Motion Camera Raspberry pi

After you have a working raspberry pi with internet working. I used a raspberry pi 2.

Setup:
$ sudo apt-get update
$ sudo apt-get install motion

$ sudo nano /etc/motion/motion.conf

daemon on
logfile /tmp/motion.log
stream_localhost off
stream_auth_method 2
stream_authentication username:password
webcontrol_localhost off
webcontrol_authentication username:password

$ sudo nano /etc/default/motion
start_motion_daemon=yes

$ sudo chmod -R 777 /var/lib/motion
$ sudo chown -R pi:pi /var/lib/motion

# start motion
$ sudo motion start

You can now open up a browser from another computer on the same network and go to: http://192.168.0.85:8081 to view your web cam.
You can remotely control the web cam settings by going to http://192.168.0.85:8080.

trouble shooting:
# View if ports are listening
$ netstat -tapen | grep "LISTEN"
$ sudo nmap -sS 192.168.0.85

# test connection
telnet 127.0.0.1 8080

# view if there is any errors. Make sure log is enabled in motion.conf
# At one point the ports were not staying open after motion started was due to permission issues on /var/lib/motion. Error was found in the log.
$ cat /tmp/motion.log

# view if motion is running
$ ps aux | grep motion

# for raspberry pi camera module to be work/detected
# https://raspberrypi.stackexchange.com/questions/10480/raspi-camera-board-and-motion#answer-26386
$ sudo modprobe bcm2835-v4l2
# to make it enable on boot
# http://www.richardmudhar.com/blog/2015/02/raspberry-pi-camera-and-motion-out-of-the-box-sparrowcam/
$ sudo nano /etc/modules

# camera with v4l2 driver
bcm2835-v4l2

# other commands
$ sudo service motion start
or
$ sudo /etc/init.d/motion start

# horizontal flip mirror image and video
# https://raspberrypi.stackexchange.com/questions/47507/mirror-image-output-from-v2-pi-camera-in-motion#answer-48156
$ sudo v4l2-ctl --set-ctrl horizontal_flip=1

resources:
http://www.instructables.com/id/Raspberry-Pi-Completely-Wireless-IP-Camera-Solar/
http://www.instructables.com/id/Raspberry-Pi-as-low-cost-HD-surveillance-camera/?ALLSTEPS

multiple cameras:
http://ubuntuforums.org/showthread.php?t=1897786

Connect to wifi in the command line

The wifi access point security will determine the way you connect to it.

If WEP (less secure)
http://askubuntu.com/questions/294257/connect-to-wifi-network-through-ubuntu-terminal#answer-294320

If WPA
http://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line#answer-138476

Configuring WPA
# view enabled connections
$ ifconfig

# view enabled and disabled connections
$ ifconfig -a

# To find out the name of your wireless card device. Look at the row that has some information in it, not ‘no wireless extensions’. In this example its wlan0.
$ iwconfig

# find wireless/wifi access points
$ sudo iwlist scan
$ nmcli dev wifi list # source
# an alternative can be “wavemon” if installed on your machine

# Add wifi network ssid and password
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
# add to the bottom of file

network={
 ssid="your_wireless_ssid"
 psk="your_wireless_password"
}

# wpa_supplicant.conf is being included in /etc/network/interfaces. Another option would be to edit interfaces file directly. Example Below.

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet dhcp
	wpa-ssid "your_wireless_ssid"
	wpa-psk "your_wireless_password"

# restart connection. This is an alternative to restarting the computer
$ sudo ifdown wlan0
$ sudo ifup wlan0

# you should now see an ip address under “inet addr:”
$ ifconfig wlan0

# test internet connection
sudo ping google.com

# useful commands
# 10 Useful “IP” Commands to Configure Network Interfaces

$ ip addr show
$ ip route show

tag:
wireless interface, network, raspberry pi

Create a router/Access Point for wifi

followed these instructions
https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software

Ran these commands
1 sudo apt-get update
2 sudo apt-get install hostapd isc-dhcp-server
3 sudo nano /etc/dhcp/dhcpd.conf
4 sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.orig
5 sudo nano /etc/dhcp/dhcpd.conf
6 sudo nano /etc/default/isc-dhcp-server
7 sudo ifdown wlan0
8 sudo cp /etc/network/interfaces /etc/network/interfaces.orig
9 sudo nano /etc/network/interfaces
10 ifconfig
11 sudo ifconfig wlan0 192.168.42.1
12 ifconfig
13 sudo nano /etc/hostapd/hostapd.conf
14 sudo cp /etc/default/hostapd /etc/default/hostapd.orig
15 sudo nano /etc/default/hostapd
16 sudo cp /etc/sysctl.conf /etc/sysctl.conf.orig
17 sudo nano /etc/sysctl.conf
18 sudo sh -c “echo 1 > /proc/sys/net/ipv4/ip_forward”
19 sudo nano /etc/sysctl.conf
20 sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
21 sudo iptables -A FORWARD -i eth0 -o wlan0 -m state –state RELATED,ESTABLISHED -j ACCEPT
22 sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
23 sudo iptables -t nat -S
24 sudo iptables -S
25 sudo iptables -L
28 sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”
29 sudo nano /etc/network/interfaces
30 wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
31 unzip adafruit_hostapd_14128.zip
32 sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
33 sudo mv hostapd /usr/sbin
34 sudo chmod 755 /usr/sbin/hostapd
35 sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
40 sudo raspi-config
41 sudo reboot
43 sudo service hostapd status
44 sudo service hostapd start
45 sudo service isc-dhcp-server start
46 sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
47 sudo service hostapd status
48 sudo update-rc.d hostapd enable
49 sudo update-rc.d isc-dhcp-server enable
50 sudo mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~/

created an image backup called
2016-01-13-rpi_access_point_router_raspbian-jessie.img

additional help

Turn Your Raspberry Pi Into a WiFi Hotspot with Edimax Nano USB EW-7811Un (RTL8188CUS chipset)


https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=75060
https://seravo.fi/2014/create-wireless-access-point-hostapd

Browse Anonymously with a DIY Raspberry Pi VPN/TOR Router

https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/

Raspberry Pi troubleshooting

Error: ‘No space left on device’
# check memory size.

$ df -h

# None should have 100% but if so here is how to fix it

$ sudo raspi-config

# select ‘Expand Filesystem’ then restart computer when prompted
https://steve0hh.wordpress.com/2013/02/10/raspberry-pis-no-space-left-on-device-error-message/

Changing keyboard layout

$ sudo raspi-config

# select Internatinalisation Options->Change Keyboard Layout->Generic 105-key (Intl) PC->Other->English (US)->English (US)->Right Alt (AltGr)->No compose key->…
# alternative http://baligena.com/changing-keyboard-layout/

Fix Raspberry pi zero wifi disconnect/sleeps after a certain period of time. source, and here

$ sudo nano /etc/modprobe.d/8192cu.conf

Add these lines
# Disable power management
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

After a while the monitor will wont work and you will not be able to see the command line once you plug in the HDMI. It goes black and you cannot see the screen. In order to keep the terminal alive here what is need to be done. source, source2

$ sudo nano /etc/rc.local

ABOVE the “exit 0” line insert:
setterm -blank 0 -powerdown 0 -powersave off

$ sudo reboot

# As of 2016-07-03 you cannot update raspberry pi packages thus some programs cannot be updated such as git.
# to have the latest git version you will need to install it by source
How To Install Git from Source

Remote Access Raspberry Pi desktop using VNC

Super Easy using windows “Remote Desktop Connection” and “xrdp”
http://www.raspberrypiblog.com/2012/10/how-to-setup-remote-desktop-from.html

So first we need to install some software on the Raspberry Pi, but don’t worry it is very easy!
  1. Start up your Pi to the terminal prompt.
  2. Type the following command “sudo apt-get install xrdp”
  3. If promoted enter your password (the default is “raspberry”)
  4. Type “Y” and press enter.
  5. This is now installing xrdp onto your Pi which is the software we are going to use for the remote desktop connection.  Wait for it to complete.
  6. Restart your Pi.  We are going to check that xrdp is going to start up automatically.
  7. When your Pi has booted to the command prompt look for [ ok ] Starting Remote Desktop Protocol server : xrdp sesman.  This shows you that xrdp is installed and automatically starting up on start up of your Pi
  8. The last step is to make a note of the IP address of your Pi which should also be displayed on the start up screen.  In my case below it is 192.168.1.9.  This is the address of your Pi on your network and what we will use to connect to your Pi from the second machine.
  9. Port forwarding 3389

 

 

OR

 

VNC in browser using tightvncserver and noVNC
https://www.raspberrypi.org/forums/viewtopic.php?f=99&t=81165

Changing Keyboard Layout

Just booted up raspberry pi but had an issue with the keyboard layout not being as I’m used to here in America, I believe the default is UK. So here is how I was able to change it and what I changed it to. (works with linux too)

$ sudo dpkg-reconfigure keyboard-configuration

settings:
generic 105 – (intl) PC
English (US)
English (US)
the default of the keyboardlayout
no compose key
configuration keyboard-configuration — no (x server termination)

resources
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=91&t=18906