Clean and create Disk with DiskPart

Start DiskPart

C:\>Diskpart

List all the drives

DISKPART> List Disk

Select the target drive

DISKPART> SELECT DISK 1

Zap the drive an all data using

DISKPART> CLEAN

Create a primary partion

DISKPART> CREATE PARTITION PRIMARY

Select the new partition

DISKPART> SELECT PART 1

Format and label the selected partiion

DISKPART> FORMAT FS=NTFS LABEL=DATA QUICK

Mount the drive at a given drive letter (e.g. N)

DISKPART>ASSIGN LETTER N

 

Recovering Data Off Netgear ReadyNAS

So I have a 4 bay Netgear ReadyNAS NVX that has stopped working.

The unit has TWO drives configured as a RAID 1 mirror (this will only work with units with two or less drives fitted).

I suspect that the power supply has failed (a common problem).

I’m going to recover the data off drive to a QNAP NAS (HS-251+ in this case).

Steps..

  1. Remove one drive from the ReadyNAS caddy
  2. Connect the drive SATA and power cables to a standard PC (remove/disconnect all other drives to avoid confusion).
  3. Boot the PC from a System Rescue CD – this can be downloaded here: https://www.system-rescue-cd.org/SystemRescueCd_Homepage
  4. Once at the command prompt you can list the drives with:
  5. fdisk -l
  6. root@sysresccd /root % fdisk -l
    Disk /dev/loop0: 353.1 MiB, 370208768 bytes, 723064 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
    
    
    Disk /dev/sda: 1.4 TiB, 1500301910016 bytes, 2930277168 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: gpt
    Disk identifier: 30AC9B24-F06D-4CE1-BBB5-ED9443790F5F
    
    Device Start End Sectors Size Type
    /dev/sda1 4 8388611 8388608 4G Linux RAID
    /dev/sda2 8388612 9437187 1048576 512M Linux RAID
    /dev/sda5 9437189 2930272064 2920834876 1.4T Linux RAID
    
    
    Disk /dev/sdb: 58.6 GiB, 62932647936 bytes, 122915328 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: 0x455dc590
    
    Device Boot Start End Sectors Size Id Type
    /dev/sdb1 * 2048 122915327 122913280 58.6G c W95 FAT32 (LBA)
    
    
    Disk /dev/md0: 4 GiB, 4294955008 bytes, 8388584 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
    
    
    Disk /dev/md1: 512 MiB, 536858624 bytes, 1048552 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
    
    
    Disk /dev/md2: 1.4 TiB, 1495467311104 bytes, 2920834592 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 16384 bytes / 16384 bytes
    
    
    Disk /dev/mapper/c-c: 1.4 TiB, 1490085216256 bytes, 2910322688 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 16384 bytes / 16384 bytes

The drive is 1.5TB and the device we are interested in is /dev/mapper/c-c

Mount this drive with:

root@sysresccd /mnt % mkdir /mnt/readynas
root@sysresccd /mnt % mount /dev/mapper/c-c /mnt/readynas

We can now look at the files on the ReadyNAS drive:

root@sysresccd /mnt % ls /mnt/readynas
aquota.group aquota.user backup home lost+found media squeezeboxserver

Next I’m going to mount the QNAP drive so that I can copy data from the ReadyNAS drive to the QNAP NAS. I need the IP address of the QNAP from the QNAP Finder application (in my case this is 172.31.1.69 – more typically 192.168.1.x).

Mount the Public folder on the  QNAP drive using:

root@sysresccd /mnt % mkdir /mnt/qnap
root@sysresccd /mnt % mount -t cifs -ousername=admin,password=YourQnapPassword //172.31.1.69/Public /mnt/qnap

I can now copy the data from the ReadyNAs drive (/mnt/readynas) to the QNAP (/mnt/qnap) e.g.:

rsync -av /mnt/readynas/media /mnt/qnap/media

 

Raspberry Pi Audio with AudioQuest DragonFly

 

AudioQuest Dragonfly Red

After booting Raspbian for the first time on my latest Raspberry Pi 3 (Jessie) I started to play with audio.

I have an Audioquest Dragonfly Red connected to one of the USB ports.

 

 

pi+dragonfly-red

First list the available device names using aplay -L

pi@raspberrypi:~ $ aplay -L
null
 Discard all samples (playback) or generate zero samples (capture)
pulse
 PulseAudio Sound Server
sysdefault:CARD=ALSA
 bcm2835 ALSA, bcm2835 ALSA
 Default Audio Device
dmix:CARD=ALSA,DEV=0
 bcm2835 ALSA, bcm2835 ALSA
 Direct sample mixing device
dmix:CARD=ALSA,DEV=1
 bcm2835 ALSA, bcm2835 IEC958/HDMI
 Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
 bcm2835 ALSA, bcm2835 ALSA
 Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
 bcm2835 ALSA, bcm2835 IEC958/HDMI
 Direct sample snooping device
hw:CARD=ALSA,DEV=0
 bcm2835 ALSA, bcm2835 ALSA
 Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
 bcm2835 ALSA, bcm2835 IEC958/HDMI
 Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
 bcm2835 ALSA, bcm2835 ALSA
 Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
 bcm2835 ALSA, bcm2835 IEC958/HDMI
 Hardware device with all software conversions
sysdefault:CARD=v10
 AudioQuest DragonFly Red v1.0, USB Audio
 Default Audio Device
front:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 Front speakers
surround21:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 4.0 Surround output to Front and Rear speakers
surround41:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 Direct sample mixing device
dsnoop:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 Direct sample snooping device
hw:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 Direct hardware device without any conversions
plughw:CARD=v10,DEV=0
 AudioQuest DragonFly Red v1.0, USB Audio
 Hardware device with all software conversions

As you can see the Raspberry Pi has the inbuilt sound chip (bcm2835) capable of audio output on the HDMI and the 3.5mm jack. I also have an AudioQuest Dragonfly Red attached to the USB port.

The list of devices is shown using the command aplay -l

pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
 Subdevices: 8/8
 Subdevice #0: subdevice #0
 Subdevice #1: subdevice #1
 Subdevice #2: subdevice #2
 Subdevice #3: subdevice #3
 Subdevice #4: subdevice #4
 Subdevice #5: subdevice #5
 Subdevice #6: subdevice #6
 Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 1: v10 [AudioQuest DragonFly Red v1.0], device 0: USB Audio [USB Audio]
 Subdevices: 1/1
 Subdevice #0: subdevice #0

Initially I was getting no audio out of the Dragonfly.

I tried using alsamixer command. The device shows up, the volume control works. But no audio played.

Back to the command line using aplay

I copied a sample wav file (44.1kHz 16bit)

aplay ~/sample.wav

resulted in an error:

aplay sample.wav
Playing WAVE 'sample.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
aplay: set_params:1233: Sample format non available
Available formats:
- S24_3LE

The Device needs to be specified (plughw:CARD:v10) as follows:

pi@raspberrypi:~/Music $ aplay sample.wav -v -Dplughw:CARD=v10
Playing WAVE 'sample.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Plug PCM: Linear conversion PCM (S24_3LE)
Its setup is:
 stream : PLAYBACK
 access : RW_INTERLEAVED
 format : S16_LE
 subformat : STD
 channels : 2
 rate : 44100
 exact rate : 44100 (44100/1)
 msbits : 16
 buffer_size : 22050
 period_size : 5513
 period_time : 125011
 tstamp_mode : NONE
 period_step : 1
 avail_min : 5513
 period_event : 0
 start_threshold : 22050
 stop_threshold : 22050
 silence_threshold: 0
 silence_size : 0
 boundary : 1445068800
Slave: Hardware PCM card 1 'AudioQuest DragonFly Red v1.0' device 0 subdevice 0
Its setup is:
 stream : PLAYBACK
 access : MMAP_INTERLEAVED
 format : S24_3LE
 subformat : STD
 channels : 2
 rate : 44100
 exact rate : 44100 (44100/1)
 msbits : 24
 buffer_size : 22050
 period_size : 5513
 period_time : 125011
 tstamp_mode : NONE
 period_step : 1
 avail_min : 5513
 period_event : 0
 start_threshold : 22050
 stop_threshold : 22050
 silence_threshold: 0
 silence_size : 0
 boundary : 1445068800
 appl_ptr : 0
 hw_ptr : 0

Sweet Music from my AudioQuest Dragonfly Red!

To make the AudioQuest Dragonfly USB the default sound device can be achieved by disabling the on board sound (snd_bcm2835):

$ sudo nano /boot/config.txt

Comment out the section that loads the snd_bcm2835 by adding the # symbol as shown – then reboot for the changes to take effect:

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on

Next set the required device to use for the audio by editing ~/.asoundrc

nano ~/.asoundrc

This should be as follows:

pcm.!default {

type plug

slave {

pcm "hw:0,0"

}

}

ctl.!default {

type hw

card 0

}

 

Remote Desktop Connection for Raspberry Pi

For remote GUI access to the Raspberry PI we need RDP.

Start by connecting via SSH (ssh -l pi raspberrypi) or directly in a Terminal window and install as follows:

sudo apt-get install xrdp

Start the service

sudo service xrdp start

You may now easily access the Raspberry Pi from a Windows PC using “Remote Desktop Connection” (mstsc.exe). You may use the hostname (raspberrypi by default) or the IP address (found using ifconfig)

 

mstc2
remote Desktop Connection to Raspberry Pi

 

mstsc3
Initial RDP Login to the Raspberry Pi. Username pi, password raspberry
mstsc4
Established Remote Desktop session to Raspberry Pi from Windows 10

 

This works on Raspbian (July 2016):

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux

pi@raspberrypi:~ $ cat /proc/version
Linux version 4.4.13-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #894 SMP Mon Jun 13 13:13:27 BST 2016

Using System Rescue CD to Share a Mounted Folder

System Rescue CD is an essential tool for system and data recovery. I typically use it for recovering files off fail(ing) or damaged hard drives from multiple types of systems: Windows, QNAP and OSX etc.

System Rescue CD

Download System Rescue CD here.

Find the partition to mount with:

fdisk -l

or use the graphical application gparted from the GUI (use the command startx to switch to the GUI from the command line).

The following assumes we have a NFTS partition on /dev/sdc1

First mount the partition and make it fully accessible:

mkdir /mnt/sdc1

mount /dev/sdc1 /mnt/sdc1

chmod 777 /mnt/sdc1

At this point we should be able to access the files on the Windows drive e.g

ls /dev/sdc1

Now I want share this entire drive so I can access it from any machine on the local area network.

Create the file /etc/samba/smb.conf.default

** Check this maybe filename is just /etc/samba/smb.conf

nano /etc/samba/smb.conf.default

Add the following and save (CTRL+X):

[public]
path = /mnt/sdc1
public = yes
writable = yes
printable = no
browsable = yes

Next we need to give the root user a password using:

pdbedit -a -u root

Start the Samba server with:

service samba start

Find the IP address of the machine using:

ifconfig

Now you should be able to access the share from any client computer on the same network.

Assuming the computer running System Rescue CD is at ip address 192.168.1.100 then drive should be available at the following UNC path:

\\192.168.1.100\public

or using “Connect to Server” option in Finder on the Mac:

smb://192.168.1.100/public

 

Using Windows Powershell to find Files

Microsoft Windows Powershell

OK so I have a bunch of files on a Windows machine ( they happen to be music files).

I want to list all the files that are below a specified size. e.g. 2k

The Windows Powershell has the Get-ChildItem command (alias as ls so that it is easier on the eye for Unix/Linux types) that can do the trick. The full command is:

ls -path d:\dbp\ -R *.m4a | where-object {$_.length  -lt 2048 } | % {Write-Host `"$($_.Fullname)`" }

So lets split that up:

ls -path d:\dbp -R *.m4a

This gets me all the files with the m4a extension in all sub-folders in/below the specified root folder d:\dbp

| where-object {$_.length  -lt 2048 }

This sets my filter condition – where the files size is Less Than 2048 bytes

| % {Write-Host `"$($_.Fullname)`"}

This formats the output to give me a list containing the full path of all matching files. Note the ` character escapes the ” character so we get the full path output within quotes.

Example output:

"D:\dbp\25564-2\Various Artists\The Greatest Songs Ever; France\01 - Douce France (Charles Trénet).m4a"
"D:\dbp\25564-2\Various Artists\The Greatest Songs Ever; France\04 - Emmenez-Moi (Charles Aznavour).m4a"
"D:\dbp\25564-2\Various Artists\The Ultimate Gershwin Disc 2\09 - S'wonderful-Funny Face.m4a"
"D:\dbp\25564-2\Various Artists\The Ultimate Line Dancing Album\10 - Cotton Eye Joe (Rednex).m4a"

Now if I want to do something useful with the files… like delete them I can use the Remove-Item command. No undo – proceed with caution:

ls -path d:\dbp\ -R *.m4a | where-object {$_.length  -lt 2048 } | % { Remote-Item -literalpath $($_.Fullname) }

 

Using Apache as a Proxy for Node JS Applications on Debian

I have a NodeJS application running on port (for example) 7070 e.g. http://localhost:7070

I also have Apache2 installed.

I want to get all requests to http://localhost to be handled by the NodeJS appliaction running on 7070 (express.io app.listen(7070); ).

Install Apache2 if not already installed….

sudo apt-get install apache2

Enable proxy module

sudo a2enmod proxy

Enable proxy_http module

sudo a2enmod proxy_http

Create file /etc/apache2/conf-available/node.conf

sudo nano /etc/apache2/conf-available/node.conf

Add the following:

ProxyPass / http://localhost:7070/

Tell Apache about the proxy configuration with:

sudo a2enconf node

Restart Apache for the changes to be effective:

sudo service apache2 reload

Browse to http://localhost should now direct requests to http://localhost:7070

 

Installing Ubiquiti Unifi Controller on Debian Linux

The Ubiquiti UniFi controller is pre-packaged for installation on Debian and Ubuntu.

ubiquiti-unifi-review

Download the latest version from https://www.ubnt.com/download/unifi/

At the time of writing this is “UniFi v4.8.15 Controller for Debian/Ubuntu Linux”

Using the command prompt:

cd ~/Downloads

Install the downloaded file:

sudo dpkg -i unify_sysvinit_all.deb

This will fail due to missing dependancies, fix with

sudo apt-get -f install

Then re-install with

sudo dpkg -i unify_sysvinit_all.deb

Check the Unify service is running:

sudo service unify status

Screen Shot 2016-04-30 at 07.13.10

You should now be able to access the controller from a web browser on the local machine (ignore security warnings due to self-signed certificate):

https://localhost:8443

After completing the initial setup wizard you will be able to log in to the controller web interface as usual:

Screen Shot 2016-04-30 at 07.14.11

 

Installing Google Chrome on Debian Linux with Remote Desktop

Login as a normal user (who  as sudo rights).

Open the default Debian Iceweasle web browser and navigate to the Chrome Download site:

vm1

Click Download

Select 64bit .deb (For Debian/Ubuntu)

vm2

Click Accept and Install

This will actually download the installation file

google-chrome-stable_current_amd64.deb

Choose to save the file.

Open Terminal

cd ~/Downloads

sudo dpkg -i google-chrome-stable_current_amd64.deb

This will fail.. so next get the missing dependancies with:

sudo apt-get -f install

Now repeat:

sudo dpkg -i google-chrome-stable_current_amd64.deb

Chrome will now be installed (note that cannot use the browser when logged in as root??)

vm3

Install Chrome Remote Desktop on Debian

Open the Chrome browser and sign in to the account.

Add the “Chrome Remote Desktop” app into Chrome if not already installed.

Download the Chrome Remote Desktop from:

http://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb

Open Terminal

cd ~/Downloads

sudo dpkg -i ~/Downloads/chrome-remote-desktop_current_amd64.deb

This will probably fail due to missing dependancies, fix with:

sudo apt-get -f install
sudo dpkg -i ~/Downloads/chrome-remote-desktop_current_amd64.deb

Next we need to create a file that defines the graphical environment. I’m using LXDE.

Create a file called .chrome-remote-desktop-session in your home directory.

cd ~
nano .chrome-remote-desktop-session

Add the following:

exec /usr/bin/startlxde

See https://support.google.com/chrome/answer/1649523?hl=en-GB for details of getting other desktop environment settings.

Reboot the computer.

Open the Chrome Browser a remote Desktop

Click the “My Computers” -> “Access your own computers from anywhere” -> “Get started”

Scroll down to the bottom of the page and you should see “Enable remote connections”

vm4

Click and enter the remote access PIN number.

You will now be able to access the machine from any other Chrome Remote Desktop app when signed into your Google Chrome account.

 

Installing Debian in a VirtualBox Virtual Machine

These are the basic steps need to install Debian Virtual Machine running in Virtualbox. May 2016.

Note: This VM will be used for hosting the Ubiquiti Networks Unifi Controller software – so the VM hard drive is bigger than generally required.

Install Debian

Create the Virtual Machine with a virtual drive of 64GB (required by the Mongo DB used by Unifi – see another post about this).

Download the latest Debian ISO – in this case debian-8.2.0-amd64-netinst.iso

Mount the Debian ISO as a CD withing the storage manager of the VM.

Set the LAN adapter to be BRIDGED

Boot the machine and proceed with the install with the following settings:

Hostname: unifyNode

Create user & passwords : root, jon

Partition: Guided – use entire disk

Package manager: United Kingdom /  ftp.uk.debian.org

Software Selection: Debian Desktop environment, LXDE, SSH Server, standard system utilities.

Install the GRUB boot loader on the VBOX drive (/dev/sda (ata-VBOX_HARDDISK_xxxxx)

Boot Debian and Install Update

Login as root

apt-get update

apt-get upgrade

visudoer

Add user to the sudoer list

visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
jon ALL=(ALL:ALL) ALL

Next Up… Installing Chrome with Remote Desktop on Debian Linux,

Installing Ubiquiti Unifi Controller on Debian Linux