Tuesday, 4 July 2017

Setting up Dakboard to run on a Rasperry Pi

To set up DAKBoard to run on a Raspberry Pi, these notes have been taken from http://dakboard.com/blog/diy-wall-display/

  • Download Raspbian - Download the full version with the GUI, not the lite version
  • Use a program like Etcher to put the Raspbian img image file onto an SD card. If you're on Windows use Win32DiskImager.
  • Boot the Pi 
  • It should boot into the graphical user interface
    • Set the locale and timezone under preferences
    • Enable SSH server under preferences
    • Connect to WiFi by waiting for the task bar network symbol to detect local SiFi SSIDs
  • If the device is not booting into the GUI, run raspi-config to configure the device
Start a terminal window.

I often have to set the display properties to avoid blank displays on reboot. I think is because I am using older monitors.

sudo nano /boot/config.txt
Then uncomment the following lines:
hdmi_force_hotplug=1 config_hdmi_boost=4
It might be worth a reboot at this point to make sure the display works. As a precaution you can check your IP address so that you can SSH into the Pi if the screen doesn't come back
sudo ip addr sudo reboot

Install the unclutter app which hides the mouse pointer after inactivity

sudo apt-get install unclutter
Then make boot configuration changes
sudo nano /boot/config.txt
Add the following lines
# Display orientation. Landscape = 0, Portrait = 1 display_rotate=1 # Use 24 bit colors framebuffer_depth=24
Finally, to make the Pi auto run DAKBoard in a chromium browser kiosk view. Edit the autostart file:
sudo nano ~/.config/lxsession/LXDE-pi/autostart
Add the following lines to it
@xset s off @xset -dpms @xset s noblank @chromium-browser --noerrdialogs --incognito --kiosk http://dakboard.com/app/?p=YOUR_PRIVATE_URL
Now you can reboot the Pi and it should boot up to run DAKboard
sudo reboot

Remote Desktop Setup

In order to set up Remote Desktop, the easiest way for me is to use Microsoft's Remote Desktop Viewer, as i use it for other tasks, which uses RDP, Remote Desktop Protocol.
I had to remove xrdp, vnc4server, tightvncserver, which were all installed in the wrong order.

I had to install tightvncserver, then install xrdp.

Please see:

https://bugs.launchpad.net/ubuntu/+s...dp/+bug/375755
https://bugs.launchpad.net/ubuntu/+s...dp/+bug/220005

It's important to do tightvnc before xrdp.

Doing things in this manner will cause xrdp to use tightvncserver instead of vnc4server, which will not work.
sudo apt-get remove xrdp
sudo apt-get remove vnc4server
sudo apt-get remove tightvncserver

sudo apt-get install tightvncserver
sudo apt-get install xrdp

Setting the time to update on reboot

The pi will not remember the time between reboots. It does not have a real time clock. We need to modify the ntp settings

To back up the configuration file before making any changes to it type the following:

‘sudo cp /etc/ntp.conf /etc/ntp_backup.conf’

I live in the UK so these will be set to ones within the UK.

Type ‘sudo nano /etc/ntp.conf’ you will see on the page something like this:

server 0.pool.ntp.org iburst server 1.pool.ntp.org iburst server 2.pool.ntp.org iburst server 3.pool.ntp.org iburst

Change this to your local time servers. Navigate to http://www.pool.ntp.org/en/use.html to find yours. Example if your in the UK you should change the entry in your ntp.conf file so it looks like this. 

server 0.uk.pool.ntp.org iburst server 1.uk.pool.ntp.org iburst server 2.uk.pool.ntp.org iburst server 3.uk.pool.ntp.org iburst

Finally further down the file you will see the following:

restrict 127.0.0.1 restrict ::1

comment these out by inserting a ‘#’ (without quotes) at the beginning of these lines press crtl + x then ‘Y’ will save your changes.

To update the time. you can reboot or: type ‘sudo service ntp restart’ followed by ‘date’

Setting the monitor to turn off overnight

You can set up a cron job to turn the monitor off overnight. Copy the code in the following script
#!/bin/sh

# Enable and disable HDMI output on the Raspberry Pi

is_off ()
{
 tvservice -s | grep "TV is off" >/dev/null
}

case $1 in
 off)
  tvservice -o
 ;;
 on)
  if is_off
  then
   tvservice -p
   curr_vt=`fgconsole`
   if [ "$curr_vt" = "1" ]
   then
    chvt 2
    chvt 1
   else
    chvt 1
    chvt "$curr_vt"
   fi
  fi
 ;;
 status)
  if is_off
  then
   echo off
  else
   echo on
  fi
 ;;
 *)
  echo "Usage: $0 on|off|status" >&2
  exit 2
 ;;
esac

exit 0
Then create a new file and paste the code into it.
sudo nano /home/pi/rpi-hdmi.sh
Then update the permissions on the file to make it executable
sudo chmod +x /home/pi/rpi-hdmi.sh
And finally edit the cron table to schedule the script
sudo crontab -e
Add the following lines at the bottom
# Turn HDMI Off (22:00/10:00pm)
45 00 * * * /home/pi/rpi-hdmi.sh off

# Turn HDMI On (7:00/7:00am)
45 6 * * * /home/pi/rpi-hdmi.sh on

Creating an SD Card Image

It's wise to create a backup image of the SD card when you have it all setup. The Pi is a fickle beast and at some point, after power cuts or problems, it'll be corrupted. Being able to reflash an image will save time in getting it back up and running again.

On a Mac

dd if=/dev/rdiskx of=/path/to/image bs=1m
Where
/dev/rdiskx
is your SD card.

(using rdisk is preferable as its the raw device - quicker)

To find out which disk your device is type
diskutil list
at a command prompt - also, you may need to be root; to do this type
sudo -s
and enter your password when prompted.

On Linux, you can use the standard dd tool:
dd if=/dev/sdx of=/path/to/image bs=1M
Where
/dev/sdx
is your SD card.

SSH Remote Identification Change

If when SSHing into the Pi you get an identification changed warning after you have reflashed the image
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
You can refresh the key using
ssh-keygen -R 
For example,
ssh-keygen -R 192.168.2.10

Friday, 31 March 2017

Recovering Ubuntu boot disk after failure to boot

Ubuntu system fails to boot

After a series of power cuts my Ubuntu server was unable to complete the boot process and displayed the following messages:

Begin: Will now check root file system ... fsck from util-linux 2.27.1
[     5.4120241] usb 4-1: device not accepting address 4, error -71
[/sbin/fsck.ext4 (1) -- /dev/mapper/ubuntu--vg-root] fsck.ext4 -a -C0 /dev/mapper/ubuntu--vg-root
/dev/mapper/ubuntu--vg-root contains a file system with errors, check forced.
[     5.524020] usb 4-1: new full-speed usb device number 5 using uhci_hcd
Inodes that were part of a corrupted orphan linked list found.

/dev/mapper/ubuntu--vg-root: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
        (i.e. without -a or -p options)
fsck exited with status code 4
done.
Failure. File system check of the root filesystem failed
the root filesystem on /dev/mapper/ubuntu--vg-root requires a manual fsck
[     5.940027] usb 4-1: device not accepting addres 5, error -71
[     5.940061] usb usb4-port1: unable to enumberate USB device

LVM Root Installation

I was confused as to how to run fsck on the boot drive. This was because the Ubuntu installation I had done was using LVM2 logical volume management. This meant that the boot drive is not listed as /dev/sdx, instead it is /dev/mapper/ubuntu--vg-root.

Rescue USB boot drive

I created a SystemRescueCD USB boot drive and was then able to repair the drive using:

fsck /dev/mapper/ubuntu--vg-root

The article below helped me to finally pin this down:

http://askubuntu.com/questions/781315/ubuntu16-04-boots-into-initramfs


Saturday, 14 January 2017

Backup Routine

File Locations

The primary drive location is /unas which has subfolders

  • unas/photo
  • unas/video

To see how much space left on the drives

df -h

To see how much space is left on the ZFS pools only

sudo zfs list

The main backup location os a 4TB external drive called

/media/4tb

Photo Backup


cd /media/4tb/unasbackup/photos

screen -S backup

./rsyncUnasPhotos.sh



Wednesday, 21 September 2016

Updating Minecraft Spigot build

Download the buildtools


wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar

git config --global --unset core.autocrlf

java -jar BuildTools.jar

copy the created spigot-1-x-xx.jar file to the main spigot directory and update the start.sh batch file to use the new version of the jar file.


Friday, 16 September 2016

Ubuntu new external Hard Drive setup partitioning, formatting and tuning

# Checking the location of the new drive. It is /dev/sdb.
sudo lshw -C disk

# Creating the GUID Partition Table (GPT)
sudo parted /dev/sdx mklabel gpt

# Checking that the GPT has been created
sudo parted /dev/sdx print

# see 6001175MB size
sudo parted /dev/sdb print unit MB print free

# Creating partition label
sudo parted --align optimal /dev/sdx mkpart primary ext4 0% 100%

# Creating the partition
# -b sets the block size (do not use for standard drive, set to 64k (65536) if mostly video and images large files

sudo mkfs.ext4 -b size=65536 /dev/sdx1

# Check the drive surface for bad blocks
# -n is non destructive test, it takes longer but does not destroy data on the disk
# -w is destructive (and faster) and will write over any data on the drive
# -s shows progress indicator
# -b specifies the blocksize which is optional but will speed up the scan
# -f force checking even if the volume seems clean
# -c the size of the block written for each test, speeding up the test but using more memory

sudo badblocks -nsvf -b 4096 -c 65536 /dev/sdx
sudo badblocks -wsvf -b 4096 -c 65536 /dev/sdx

sudo badblocks -nsvf -b 65536 -c 1024 /dev/sdx
sudo badblocks -wsvf -b 65536 -c 1024 /dev/sdx

# NOTE - Smartmontools smartctl tests will be a better faster test than badblocks
The SMART surface test is almost certainly a single, and certainly non-destructive, read pass. As has been pointed out it is also internal to the drive; with the possible exception of minor control data, no data is being passed to or from the host during the test.

On the other hand, badblocks -w makes four passes over the drive, each with one write and one read. That alone accounts for an 8× difference in time taken for the test, plus rotational latency. Since it's software running on the host, all that data needs to be shuffled through the disk interface to RAM and handled by the software (badblocks, in our case).

# -t type of test
# -C run the test in the foreground

sudo smartctl -t long -C /dev/sdx

# Show the test results

sudo smartctl -a /dev/sdx


# mount the drive on a folder
sudo mount /dev/sdx1 /media/usb

# Remove reserved blocks (i.e. set to 0%), since this drive is just for user data
sudo tune2fs -m 0 /dev/sdx1

Friday, 5 August 2016

Discovering and Mounting USB Drives/Flash Drives using the command line on Ubuntu Server

Discovering which drives are connected

There are many ways to see which drives are connected to the ubuntu system:

To show full detailed information about all drives connected to the system.

sudo fdisk -l

This will list, in detail, all of the drives connected.

Here is an example of the drive we are interested in. A 500mb external HDD:

Disk /dev/sdi: 465.8 GiB, 500107706368 bytes, 976772864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe38f367e

Other options:

blkid
lsblk -f
lsusb
sudo lshw
df -h -T

To see if the drive is FAT16 or FAT32

sudo file -s /dev/sdi1


This will show is the following details for the drive


/dev/sdi1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "BSD  4.4", sectors/cluster 64, Media descriptor 0xf8, sectors/track 32, heads 255, hidden sectors 2, sectors 976772862 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 119206, serial number 0xfd44150c, label: "500-FREECOM"

Mount the drive

USB drives are usually mounted under the /media directory. Create a directory to mount the drive on.

cd /media
mkdir external

sudo mount -t vfat /dev/sdb1 /media/external
If no -t option is given, or if the auto type is specified, mount will try to guess the desired type.