<commit_before>[b]Prerequisites to install Raspbian to a SD Card[/b]
- Raspberry Pi Model B or higher with at least 512 MB 
- SDHC Card with at least 16GB
  Should be compatible for the Raspberry Pi and class 10 for best results.
  I have used SanDisk SDSDU-016G-U46 Ultra SDHC Class 10.
- Network cable
  To connect from your computer via SSH to the Raspberry Pi.
  You can also use mouse/keyboard/display instead and forget the SSH stuff.
- Internet connection
  The Raspberry Pi should be connected to the internet. 
1. Download Raspian SD Card image from
https://www.raspberrypi.org/downloads/
and follow the given instructions located at 
https://www.raspberrypi.org/documentation/installation/installing-images/README.md
In the next few steps I'll show you this for GNU/Linux Debian. 
Feel free to add instructions for other systems here as well.
2. Format the SD Card with GParted
and get to know the location of your SD Card.
This is something like /dev/sdCHAR but you really need to be sure.
If you are not sure you may format your entire hard drive later.
3. Type into the terminal
[code]$ sudo dd if=path_to_your_raspbian.img of=/dev/sdCHAR bs=4m[/code]
and wait this can take a while up to 1/2 hour
4. Eject the SD Card
[code]$ sync[/code]
and put it into your Raspberry Pi.
5. Put the SD Card into Raspberry Pi, connect the Raspberry Pi with your Computer and boot
6. Find out the IP and connect via SSH to it. 
To find out the IP you also could put the SD Card into your computer, then edit /boot/cmdline.txt
[code]$ vi /boot/cmdline.txt[/code]
and add a
[code]ip=192.168.3.133[/code]
at the end of the line for example.
Then setup the ip on the computer to be 
192.168.3.2 with a 255.255.255.0 netmask.
Connect both with a cable, put the SD Card back into the MacPi and boot the MacPi.
SSH Server is already installed and activated on Raspbian.
The default user is "pi" and password "<PASSWORD>".
[code]$ ssh -l pi IP[/code]


[b]Mount an USB Stick[/b]
Prerequisites:
- USB Stick
- Tutorial done above
1. Get su
[code]$ sudo su[/code]
2. Put USB Stick into the Raspberry Pi and get the system name
[code]$ tail -f /var/log/messages[/code]
The part after sda: ... should give the name for me its sda1 which I'll use from now on
3. Format the USB Stick
[code]$ mkfs.ext4 /dev/sda1[/code]
4. Create a directory
[code]$ mkdir /media/usbstick[/code]
5. If sda1 is the name then mount it with
[code]$ mount /dev/sda1 /media/usbstick/[/code]
6. To automatically mount the drive at every start just get the UUID
[code]$ blkid /dev/sda1[/code]
7. And add the line "UUID=BF12-15E9 /media/usbstick ext4 defaults 0 2" to
[code]$ vi /etc/fstab[/code]
while using your own UUID I used here mine its BF12-15E9

[b]Put a swapfile onto the mounted USB Stick[/b]
Prerequisites:
- Tutorials done above
1. Get su
[code]$ sudo su[/code]
2. Do
[code]$ vi /etc/dphys-swapfile [/code]
and add
CONF_SWAPFILE=/media/usbstick/swap
CONF_SWAPSIZE=1024
to it
3. Do some magic
[code]$ dphys-swapfile swapoff
$ dd if=/dev/zero of=/media/usbstick/swap bs=1M count=1024
$ mkswap /media/usbstick/swap
$ dphys-swapfile setup
$ dphys-swapfile swapon[/code]
4. Check if its in there
[code]$ swapon -s[/code]

[b]Activate WLAN[/b]
Prerequisites:
- Tutorials done above
- WLAN Stick
  I have used EDIMAX EW-7811 Wifi Wireless Wlan USB dongle.
1. Get su
[code]$ sudo su[/code]
2. Put the WLAN Stick into the Raspberry Pi and then run
[code]$ dmesg[/code]
This should give a result like "usbcore: registered new interface driver rtl8192cu..." 
3. Check if the new network device wlan0 can be seen at
[code]$ ifconfig[/code]
4. Deactivate the energy save function of the EDIMAX driver
[code]$ vi /etc/modprobe.d/8192cu.conf[/code]
And add "options 8192cu rtw_power_mgnt=0 rtw_enusbss=0" to it.
5. Reboot
[code]$ reboot[/code]
6. Check if the energy save function of the EDIMAX driver was deactivated it should return 0
[code]$ cat /sys/module/8192cu/parameters/rtw_power_mgnt[/code] 
7. Now edit
[code]$ vi /etc/network/interfaces[/code]
Which should look like this at the beginning:
[code]auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp[/code]
It depends on your WLAN settings but this works for me with WPA.
[code]# loopback
auto lo
iface lo inet loopback

# ethernet (static config)
auto eth0
iface eth0 inet static
address 192.168.3.134
netmask 255.255.255.0
broadcast 192.168.3.255
network 192.168.3.0
#gateway 192.168.3.1
#dns-nameservers 192.168.3.1

# wifi (static config)
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
#iface wlan0 inet static
#address 192.168.2.134
#netmask 255.255.255.0
#broadcast 192.168.2.255
#network 192.168.2.0
#gateway 192.168.2.1
#dns-nameservers 192.168.2.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp[/code]

The file "/etc/wpa_supplicant/wpa_supplicant.conf" where you then just have to configure YOURSSID and YOURPSK looks like this:

[code]ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOURSSID"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="YOURPSK"
}[/code]

8. Finally we need a fix so that the MacPi reconnects to a Wi-Fi network in case the connection was lost. For this you either can use a short script

[code]#!/bin/bash                                  
                                               
TESTIP=192.168.2.1                           
                                               
ping -c4 ${TESTIP} > /dev/null               
                                               
if [ $? != 0 ]                               
then                                         
    logger -t $0 "WiFi is probably down, restarting"
    ifdown --force wlan0                     
    ifup wlan0                               
else                                        
    logger -t $0 "WiFi is probably up."           
fi [/code]

and create a new cronjob

[code]	
*/5 * * * * root /usr/local/bin/testwifi.sh
[/code]

or you can 

[code]$ /etc/ifplugd/action.d $ sudo mv ifupdown ifupdown.original
$ /etc/ifplugd/action.d $ sudo cp /etc/wpa_supplicant/ifupdown.sh ./ifupdown
$ /etc/ifplugd/action.d $ sudo reboot[/code]

[b]Expand the partition size to use the full 16GB of the SD Card[/b]
1. Get su
[code]$ sudo su[/code]
2. Type in 
[code]$ df -h[/code]
and look for the filesystem where its mounted at /boot for me its [code]"/dev/mmcblk0p1"[/code]
3. Type in 
[code]$ fdisk -u -c /dev/mmcblk0[/code]
After this you land in the environment of fdisk
4. Inside fdisk type in
[code]$ p ENTER[/code]
Don't write ENTER but press ENTER on your keyboard.
You'll see something then.
Copy that you'll need it later.
For me its
[code]Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     5785599     2831360   83  Linux[/code]
5. Inside fdisk delete the partitions that are not boot. In my case its partition 2. <commit_msg>System update, some changes to deal with the new Raspian version<commit_after>[b]Prerequisites to install Raspbian to a SD Card[/b]
- Raspberry Pi Model B or higher with at least 512 MB 
- SDHC Card with at least 16GB
  Should be compatible for the Raspberry Pi and class 10 for best results.
  I have used SanDisk SDSDU-016G-U46 Ultra SDHC Class 10.
- Network cable
  To connect from your computer via SSH to the Raspberry Pi.
  You can also use mouse/keyboard/display instead and forget the SSH stuff.
- Internet connection
  The Raspberry Pi should be connected to the internet. 
1. Download Raspian SD Card image from
https://www.raspberrypi.org/downloads/
and follow the given instructions located at 
https://www.raspberrypi.org/documentation/installation/installing-images/README.md
In the next few steps I'll show you this for GNU/Linux Debian. 
Feel free to add instructions for other systems here as well.
2. Format the SD Card with GParted
and get to know the location of your SD Card.
This is something like /dev/sdCHAR but you really need to be sure.
If you are not sure you may format your entire hard drive later.
3. Type into the terminal
[code]$ sudo dd if=path_to_your_raspbian.img of=/dev/sdCHAR bs=4m[/code]
and wait this can take a while up to 1/2 hour
4. Eject the SD Card
[code]$ sync[/code]
and put it into your Raspberry Pi.
5. Put the SD Card into Raspberry Pi, connect the Raspberry Pi with your Computer and boot
6. Find out the IP and connect via SSH to it. 
To find out the IP you also could put the SD Card into your computer, then edit /boot/cmdline.txt
[code]$ vi /boot/cmdline.txt[/code]
and add a
[code]ip=192.168.3.133[/code]
at the end of the line for example.
Then setup the ip on the computer to be 
192.168.3.2 with a 255.255.255.0 netmask.
Connect both with a cable, put the SD Card back into the MacPi and boot the MacPi.
SSH Server is already installed and activated on Raspbian.
The default user is "pi" and password "<PASSWORD>".
[code]$ ssh -l pi IP[/code]

[b]System update[/b]
[code]$ sudo apt-get update && sudo apt-get upgrade[/code]

[b]Mount an USB Stick[/b]
Prerequisites:
- USB Stick
- Tutorial done above
1. Get su
[code]$ sudo su[/code]
2. Put USB Stick into the Raspberry Pi and get the system name
[code]$ tail -f /var/log/messages[/code]
The part after sda: ... should give the name for me its sda1 which I'll use from now on
3. Format the USB Stick
[code]$ mkfs.ext4 /dev/sda1[/code]
4. Create a directory
[code]$ mkdir /media/usbstick[/code]
5. If sda1 is the name then mount it with
[code]$ mount /dev/sda1 /media/usbstick/[/code]
6. To automatically mount the drive at every start just get the UUID
[code]$ blkid /dev/sda1[/code]
7. And add the line "UUID=BF12-15E9 /media/usbstick ext4 defaults 0 2" to
[code]$ vi /etc/fstab[/code]
while using your own UUID I used here mine its BF12-15E9

[b]Put a swapfile onto the mounted USB Stick[/b]
Prerequisites:
- Tutorials done above
1. Get su
[code]$ sudo su[/code]
2. Do
[code]$ vi /etc/dphys-swapfile [/code]
and add
CONF_SWAPFILE=/media/usbstick/swap
CONF_SWAPSIZE=1024
to it
3. Do some magic
[code]$ dphys-swapfile swapoff
$ dd if=/dev/zero of=/media/usbstick/swap bs=1M count=1024
$ mkswap /media/usbstick/swap
$ dphys-swapfile setup
$ dphys-swapfile swapon[/code]
4. Check if its in there
[code]$ swapon -s[/code]

[b]Activate WLAN[/b]
Prerequisites:
- Tutorials done above
- WLAN Stick
  I have used EDIMAX EW-7811 Wifi Wireless Wlan USB dongle.
1. Get su
[code]$ sudo su[/code]
2. Put the WLAN Stick into the Raspberry Pi and then run
[code]$ dmesg[/code]
This should give a result like "usbcore: registered new interface driver rtl8192cu..." 
3. Check if the new network device wlan0 can be seen at
[code]$ ifconfig[/code]
4. Deactivate the energy save function of the EDIMAX driver
[code]$ vi /etc/modprobe.d/8192cu.conf[/code]
And add "options 8192cu rtw_power_mgnt=0 rtw_enusbss=0" to it.
5. Reboot
[code]$ reboot[/code]
6. Check if the energy save function of the EDIMAX driver was deactivated it should return 0
[code]$ cat /sys/module/8192cu/parameters/rtw_power_mgnt[/code] 
7. Now edit
[code]$ vi /etc/network/interfaces[/code]
Which should look like this at the beginning:
[code]# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf[/code]
It depends on your WLAN settings but this works for me with WPA.
[code]# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp[/code]

The file "/etc/wpa_supplicant/wpa_supplicant.conf" where you then just have to configure YOURSSID and YOURPSK looks like this:

[code]country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
[/code]

turn it into something like

[code]country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOURSSID"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="YOURPSK"
}[/code]

8. Finally we need a fix so that the MacPi reconnects to a Wi-Fi network in case the connection was lost. For this you either can use a short script

[code]#!/bin/bash                                  
                                               
TESTIP=192.168.2.1                           
                                               
ping -c4 ${TESTIP} > /dev/null               
                                               
if [ $? != 0 ]                               
then                                         
    logger -t $0 "WiFi is probably down, restarting"
    ifdown --force wlan0                     
    ifup wlan0                               
else                                        
    logger -t $0 "WiFi is probably up."           
fi [/code]

and create a new cronjob

[code]	
*/5 * * * * root /usr/local/bin/testwifi.sh
[/code]

[b]Expand the partition size to use the full 16GB of the SD Card[/b]
1. Get su
[code]$ sudo su[/code]
2. Type in 
[code]$ df -h[/code]
and look for the filesystem where its mounted at /boot for me its [code]"/dev/mmcblk0p1"[/code]
3. Type in 
[code]$ fdisk -u -c /dev/mmcblk0[/code]
After this you land in the environment of fdisk
4. Inside fdisk type in
[code]$ p ENTER[/code]
Don't write ENTER but press ENTER on your keyboard.
You'll see something then.
Copy that you'll need it later.
For me its
[code]Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     5785599     2831360   83  Linux[/code]
5. Inside fdisk delete the partitions that are not boot. In my case its partition 2. 
{'fraction_non_alphanumeric': 0.08605851979345955, 'fraction_numerical': 0.03580034423407917, 'mean_word_length': 2.8881156316916488, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 20, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7529922', 'n_tokens_mistral': 5208, 'n_tokens_neox': 4729, 'n_words': 1951}