Mount usb linux command line

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

# 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
    ## Web server settings (note: host is the FQDN, do not include http://)
    port: 81
    https: false


  <<: *base
    enabled: true
    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:
external_url ''


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

# 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

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)

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



# Reconfigure freezes at ruby_block[supervise_redis_sleep] action run

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.

$ 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
$ 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

Setup linux Motion Camera Raspberry pi

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

$ 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

$ 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: to view your web cam.
You can remotely control the web cam settings by going to

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

# test connection
telnet 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
$ sudo modprobe bcm2835-v4l2
# to make it enable on boot
$ sudo nano /etc/modules

# camera with v4l2 driver

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

# horizontal flip mirror image and video
$ sudo v4l2-ctl --set-ctrl horizontal_flip=1


multiple cameras:

Connect to wifi in the command line

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

If WEP (less secure)


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


# 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

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

$ ip addr show
$ ip route show

wireless interface, network, raspberry pi

Create a router/Access Point for wifi

followed these instructions

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
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
31 unzip
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

additional help

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

Browse Anonymously with a DIY Raspberry Pi VPN/TOR Router

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

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

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”

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  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





VNC in browser using tightvncserver and noVNC

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

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