Hyper-V til VirtualBox

Har du konverteret din Windows til Hyper-V kan den konverteres til VirtualBox.

https://www.virtualbox.org/

De fleste Linux distibutioner har den i deres pakke/software installation. Du vil også få brug VirtualBox Extension Pack som kan hentes på VirtualBox web. Mac OSX fungerer muligvis anderledes.

For brug af USB lager skal din bruger tilhøre gruppen ‘vboxusers’ og det er en manuel opgave – check gruppe medlemskab

$ groups
lp wheel network video audio storage users

Tilknyt dit brugernavn

$ sudo gpasswd -a $USER vboxusers

Husk at gruppe medlemskab først træder i kraft ved næste login.

I eksemplet herunder er forudsat

  • en værts maskine med dual-core cpu, 4GB RAM, Intel lydkort
  • engelske mappe navne i home-folder
  • VHDX filen indeholder en Windows 10 (32-bit)
  • virtuel maskin-navn “din-vm”

Opret en mappe til din virtuelle maskine (BEMÆRK: venstre-vendt skråstreg før mellemrum)

$ mkdir -P ~/VirtualBox\ VMs/din-vm

Konverter vhdx-filen til vdi

$ VBoxManage clonehd /path/to/din-vm.vhdx ~/VirtualBox\ VMs/din-vm/din-vm.vdi

Hvis du er mest fortrolig med GUI kan du nu åbne VirtualBox fra genvejen i din distro’s menu system eller du kan forsætte i terminalen.

Terminal kommando til oprettelse og konfigurering af en virtual maskine der bruger din konverterede Hyper-V maskine er som følger.

Opret virtuel maskine

$ VBoxManage createvm --name "din-vm" --ostype "Windows10" --register

Sætte ram og cpu

$ VBoxManage modifyvm "din-vm" --cpus 1 --memory 2048 --longmode on --ioapic on

Sætte boot rækkefølge

$ VBoxManage modifyvm "din-vm" --boot1 disk --boot2 dvd

Sætte grafik og skærm

$ VBoxManage modifyvm "din-vm" --vram 128 --monitorcount 1

Sætte lydkort

$ VBoxManage modifyvm "din-vm" --audio pulse --audiocontroller hda

Sætte mus

$ VBoxManage modifyvm "din-vm" --usb on --usbehci on --mouse usbtablet

Sætte netværk til NAT/DHCP

$ VBoxManage modifyvm "din-vm" --nic1 nat

Oprette disk-styre-enhed

$ VBoxManage storagectl "din-vm" --name "IDE" --add ide --controller PIIX4 --hostiocache on --bootable

Sætte virtuel disk på disk-styre-enhed

$ VBoxManage storageattach "din-vm" --storagectl "IDE" --port 0 --device 0 --type hdd --medium "din-vm.vdi"

Sætte DVD-drev på disk-styre-enhed

$ VBoxManage storageattach "din-vm" --storagectl "IDE" --port 1 --device 0 --type dvddrive --passthrough off --medium host:/dev/sr0

Oprette delt mappe til Linux-home-folder Documents (Dokumenter)

$ VBoxManage sharedfolder add "din-vm" --name $(basename $HOME) --hostpath $HOME/Documents --automount

Windows til Hyper-V

Overfør din windows til virtuel maskine.

Windows opsættes til RDP (Remote Desktop Protocol) på dansk Fjernskrivebord.
Vær sikker på at du har ret til login på Fjernskrivebord.

Flyt data væk fra C:
Det kan være sekundær disk, flytbar disk, cloud, netværk …

Skift størrelse på C: til maks 127GB.
Ved fysisk disk med mere end 127GB kan det være nødvendigt at defragmentere den frie plads før det er muligt at skifte størrelse på C:.

Windows XP bruges fx. http://www.aomeitech.com/download.html

Windows 7, 8.x, 10 bruges Diskhåndtering.

Efter størrelsesændring kan det være en fordel men ikke nødvendigt at konsolidere den frie plads med SDelete, et gratis Microsoft program.

Hvis du bruger SSD diske skal du ikke bruge SDelete da dette slider unødigt på hukommelseskredsene.

https://technet.microsoft.com/en-us/sysinternals/sdelete.aspx

Nu bruges et andet gratis Microsoft program Disk2vhd.

https://technet.microsoft.com/en-us/sysinternals/ee656415.aspx

Dette program kloner computer fra dit C: drev til et format der kan bruges med Microsoft HyperV eller VirtualPC.

Husk at gemme den virtuelle disk som VHDX – det udvidede HyperV format.

Disk2vhd kan gemme den på den computer der klones men kan med fordel gemmes på et eksternt medie fx. en flytbar harddisk, USB eller netværkslager. Husk at der skal være mindst 127GB ledig plads da dette er den maksimale størrelse for den virtuelle harddisk.

HyperV til VirtualBox

Smartphone Portkontrol med RaspberryPi

1 RPi A+ eller B rev.2 eller nyere

1 PSU 5v DC 1.2A
1 USB WiFi
1 SD-card 8GB 
1 Relæ Modul 
1 Magnet kontakt 
Jumperwire med HUN-HUN stik men det kan også loddes.
Signalkabel min. 2x0.6 - de fleste kabler har flere ledere.

Du kan nok finde det hele her http://elektronik-lavpris.dk/.

Værktøj
Multimeter
Små skruetrækkere (PZ1, PH1, 5mm)
Evt. lille loddekolbe + tin med flus

Python controller modul
Et python script med en webservice.
Webservicen bruger GPIO til at levere status-data og aktiverings-signal for åbning/lukning.
[plain]git clone https://github.com/andrewshilliday/garage-door-controller[/plain]

TRIGGER
[plain] RPi pin 1 (3.3v) => Relæ Modul pin Vcc
RPi pin 16 (BCM GPIO 17) => Relæ Modul pin In1
RPi pin 3 (GND) => Relæ Modul pin Gnd
[/plain] STATUS
[plain] RPi pin 9 (GND) => MK reed
RPi pin 11 (BCM GPIO 23) => MK reed
[/plain] RELÆ
[plain] Common => portstyring
Normally Open => portstyring
[/plain]

Setting up a Magento VM (maintenance purpose)

A client recently asked me to move their Magento to another host. A problem arise since the new host do not provide shell access thus maintaining Magento patches became an issue.

I found and forked this from
Credit where credit is due.
https://www.nerdoncoffee.com/uncategorized/setting-up-a-magento-vm-and-allowing-remote-access/

Grab the VMDK from here

https://bitnami.com/stack/magento/virtual-machine
  • Convert to a qcow2 image

    qemu-img convert -f vmdk -O qcow2 bitnami-magento-1.9.1.0-0-ubuntu-14.04.vmdk magento.qcow2

  • Create a vm and set that is the hard disk image

  • Change all interfaces to virtio 14.04 has paravirtual drivers already installed so is good to go. Why ? Because it will speed up slow as Magento
  • Create a bridge
  • Follow the wiki

    https://wiki.archlinux.org/index.php/Bridge_with_netctl

  • Add your interfaces as appropriate e.g

    Description=”Example Bridge connection”
    Interface=br0
    Connection=bridge
    BindsToInterfaces=(eth0 eth1 tap0 enp2s0)
    IP=dhcp

  • Start it and enable it at boot

    sudo netctl start bridge
    sudo netctl enable bridge

  • Change the Nic to use the new bridge (br0) as the Network source

  • Start the VM
  • Configure whatever you like on your vm
    you could use port forwarding, port triggering, dmz, vpn, ssh etc…

As I don’t really care about this little vm (its just for dev purposes) I threw it in the DMZ zone (make sure it has a static IP – I just did a dhcp reservation and set the mac of the vnic)

  • Adding a DNS A record so you don’t have to remember the ip
    log in to your dns registrar (look up terminology) – I use cloudflare so I just added it in there for this blog as magento.nerdoncoffee.com)

  • Modify your vm
    in /opt/bitnami/apps/magento/conf/htaccess.conf php_value memory_limit 512M

  • Update Apache2 on your vm
    [text] #

ServerName magento.example.com

ServerAlias www.magento.example.com

DocumentRoot “/opt/bitnami/apps/magento/htdocs”

#

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#
ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com www.magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#

ServerName magento.example.com

ServerAlias www.magento.example.com

DocumentRoot “/opt/bitnami/apps/magento/htdocs”

SSLEngine on

SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”

SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

#

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#

ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com www.magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
SSLEngine on
SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”
SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”
[/text] OR
[text] ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#

ServerName magento.example.com

ServerAlias www.magento.example.com

DocumentRoot “/opt/bitnami/apps/magento/htdocs”

SSLEngine on

SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”

SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

#

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”

#
ServerName magento.nerdoncoffee.com
ServerAlias magento.nerdoncoffee.com
DocumentRoot “/opt/bitnami/apps/magento/htdocs”
SSLEngine on
SSLCertificateFile “/opt/bitnami/apps/magento/conf/certs/server.crt”
SSLCertificateKeyFile “/opt/bitnami/apps/magento/conf/certs/server.key”

Include “/opt/bitnami/apps/magento/conf/httpd-app.conf”
[/text]

nano /opt/bitnami/apps/magento/conf/htaccess.conf

at the bottom in the directories node

[text] SetEnvIf Host www.magento.nerdoncoffee.com MAGE_RUN_CODE=magento.nerdoncoffee.com
SetEnvIf Host www.magento.nerdoncoffee.com MAGE_RUN_TYPE=website
SetEnvIf Host ^magento.nerdoncoffee.com MAGE_RUN_CODE=magento.nerdoncoffee.com
SetEnvIf Host ^magento.nerdoncoffee.com MAGE_RUN_TYPE=website
[/text] Now uncomment the following file in /opt/bitnami/apps/magento/conf/htaccess.conf
[text]

you can put here your magento root folder

path relative to web root

RewriteBase /magento/
[/text] Restart apache in your vm

sudo /opt/bitnami/ctlscript.sh restart apache

References
* https://bitnami.com/stack/magento/virtual-machine
* https://wiki.archlinux.org/index.php/Bridge_with_netctl
* https://wiki.bitnami.com/Virtual_Appliances_Quick_Start_Guide
* https://wiki.bitnami.com/Virtual_Appliances_Quick_Start_Guide#How_to_enable_sshd.3f

Replace a String in Multiple Files

I recently had to search a huge amount of files (Magento webshop) and replace an url. I did a search an found this.

Credit where credit is due
Forked from http://vasir.net/blog/ubuntu/replace_string_in_multiple_files

I recently had to replace every occurrence of a certain word / string in a ton of files spanning multiple directories, and this is the quickest way I’ve found to do it. It uses grep to search for a certain word and if it find its it runs sed to replace the strings you want. Note: This will not work on windows systems
Basic Format

grep -rl matchstring somedir/ | xargs sed -i ‘s/string1/string2/g’

Note: The forward slash ‘/’ delimiter in the sed argument could also be a different delimiter (such as the pipe ‘|’ character). The pipe delimiter might be useful when searching through a lot of html files if you didn’t want to escape the forward slash, for instance.
matchstring is the string you want to match, e.g., “football” string1 would ideally be the same string as matchstring, as the matchstring in the grep command will pipe only files with matchstring in them to sed. string2 is the string that replace string1. There may be times when you want to use grep to find only files that have some matchstring and then replace on a different string in the file than matchstring. For example, maybe you have a lot of files and only want to only replace on files that have the matchstring of ‘phonenumber’ in them, and then replace ‘555-5555’ with ‘555-1337’. Not that great of an example (you could just search files for that phone number instead of the string ‘phonenumber’), but your imagination is probably better than mine.
Example

grep -rl ‘windows’ ./ | xargs sed -i ‘s/windows/linux/g’

This will search for the string ‘windows’ in all files relative to the current directory and replace ‘windows’ with ‘linux’ for each occurrence of the string in each file.

Using USB harddrives on RaspberryPi

This is surprisingly easy.

  • Make sure your PI has enough power – at least a 2Ah or better.
  • Mount the root partition your SD card
  • Mount your USB harddrive (ext4 formatted
  • Copy the root partition of the sdcard to a ext4 formatted usb-harddrive.
  • Rebember to sync to ensure all data are flushed from cache.
mount /dev/sdxY /your/sdcard/mountfolder
mount /dev/sdxY /your/usb/mountfolder
cp -r /your/sdcard/mountfolder/* /your/usb/mountfolder
sync

On the boot partition of the sdcard copy the file cmdline.txt -> cmdline.txt.bak.

cp /boot/cmdline.txt /boot/cmdline.txt.bak

Open cmdline.txt and find where it reads

root=/dev/mmcblk0p6

Change it to

root=/dev/sda1

Save your file.

Attach your USB drive to your PI, insert your SD card and plugin power. Your PI will boot faster and you dont wear your SD card down.

Linux: cifs share in fstab

Mount cifs share in fstab

Install cifs-utils (even if you already have Samba and related packages installed):

sudo pacman install cifs-utils

Edit /etc/fstab and add your entry:

//server/share /pathto/mountpoint cifs credentials=/etc/samba/.smbcredentials 0 0

Create the .smbcredentials file in /etc/samba:

$ sudo touch /etc/samba/.smbcredentials
$ sudo nano /etc/samba/.smbcredentials


username=shareuser
password=sharepassword
domain=domain_or_workgroupname

Make sure you secure your /etc/samba/.smbcredentials file:

sudo chmod 0400 /etc/samba/.smbcredentials

Finally, test the mount with:

sudo mount -a

Linux: XDMCP summary

XDMCP

locally – and locally only

Installer XDM

Archlinux

# pacman -S xorg-xdm

Ubuntu

# apt-get install xdm

When installing select xdm as default login manager

Edit as root

# nano /etc/X11/xdm/Xaccess
## remove remark (#) from the line reading
#*        #any host can get a login window

# nano /etc/X11/xdm/Xservers
##add remark (#) for the line - probably last - reading
:0 local ..(rest omitted)

# nano /etc/X11/xdm/xdm-config
## add remark (!) for the line - probably last - reading
DisplayManager.requestPort:    0

Raspberry Pi: resources

Resources

Raspberry Pi

http://www.raspberrypi.org/documentation/configuration/device-tree.md

http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=97314

https://github.com/Hexxeh/rpi-firmware/tree/master/overlays

ArchLinux

http://archlinuxarm.org/platforms/armv6/raspberry-pi

http://archpi.dabase.com/

https://wiki.archlinux.org/index.php/Raspberry_Pi

http://elinux.org/ArchLinux_Install_Guide

http://docs.rpi-dashboard.com/system_configuration/enable_spi.html
http://www.raspberrypi.org/tag/arch-linux/

http://docs.rpi-dashboard.com/build_from_source/build_on_arch_linux.html