Sunday, April 03, 2016

VirtualBox access to SD card through Windows Host

The problem is how to set the wireless details for a headless Raspberry Pi, and so the challenge is how to change a file on an SD card formatted as Ext4 for Linux when Windows doesn't recognise it.

As I'm already running a Centos 7 image of Linux in VirtualBox, one solution is to access the whole, raw SD card direct from that VM.


And this post details exactly how to do this, whilst the VirtualBox man pages can be found here.



1. Get the DeviceID for your SD card reader

As administrator, open a command prompt and type:

wmic diskdrive list brief



2. Create an image representing the SD card

As administrator, navigate create a link file to the SD card on the desktop:

cd c:\Program Files\Oracle\VirtualBox

VBoxManage.exe internalcommands createrawvmdk -filename "%USERPROFILE%/Documents/sdcard.vmdk" -rawdisk "\\.\PHYSICALDRIVE1"


3. Connect the VM to the SD card using the link

Open VirtualBox as administrator, and open the Settings for the VM. Go to Storage -> Controller: SATA -> (right click) Add Hard Disk -> Choose Existing Disk and open the file that was created in Documents (note VM must be powered off).
.

4. Access...

Start the VM and mount the card using the GUI. The card should now be accessible in native Ext4 format...

Thursday, March 24, 2016

Setting up an SSH Git server on Windows...


I have a set of Raspberry Pis and I need to back up the stuff I do on them, and ideally add some version control as that is always good.
So the idea is to set up a git server on my Windows machine, giving me the ability to both version control the stuff I am doing, and back it up through the pre-existing Windows backup. And the assumption is that anything not in git can be recreated easily enough.
This and the follow up here are the best tutorials I've come across describing this, but full details here:

Install SSH

I'm using the new Microsoft supported OpenSSH.
  • unzip the package at C:\Program Files\OpenSSH-Win64 and follow the installation instructions.
  • Check the installation by connecting to the Windows machine through SSH.
Note that there OpenSSH isn't yet mature enough for this to work correctly. Worth instead using Bitvise SH Server which is free for limited use.

Install Git

  • Download git for Windows and install. Suggest install either git bash, or git bash + cmd option.
  • Update PATH to add C:\Program Files\Git\mingw64\libexec\git-core and C:\Program Files\Git\bin
  • Create a new file in C:\Program Files\Git\bin named gup.sh. his removes additional single quotes that are added by ssh from Linux to windows:
"C:/Program Files/Git/mingw64/libexec/git-core/git-upload-pack.exe" $*
  • Create a second new file named grp.sh:
"C:/Program Files/Git/mingw64/libexec/git-core/git-receive-pack.exe" $*

    How to use:

    To clone:
    git clone -u 'sh gup.sh' user@laptop:C:/Temp/new-project.git
    To push:
    git push --exec 'sh grp.sh' user@laptop:C:/Temp/new-project.git master
    To pull:

    git pull --upload-pack 'sh gup.sh' user@laptop:C:/Temp/new-project.git

    Alternatively, update ~/.gitconfig using (see here):
    git config --global remote.origin.uploadpack 'sh gup.sh'
    git config --global remote.origin.receivepack 'sh grp.sh'

    To create an empty project:

    On remote server:
    mkdir new-project.git
    cd new-project.git
    git init --bare

    On local machine:
    cd new-project
    git init
    git add *
    git commit -m "Initial commit"
    git remote add origin user@laptop:C:/Temp/new-project.git
    git push origin master

    To set up Public Key Authentication

    On remote server (linux):
    ssh-keygen –t rsa
    or (Windows):
    ssh-keygen.exe -t rsa -f id_rsa

    (For OpenSSH) Copy the contents of ~/.ssh/rsa_id.pub and add to %systemdrive%\users\user\\.ssh\authorized_keys on host.


    Alternatively...

    Use Bitvise SSH Server as it is better...