Install Raspbian from scratch on Unix/Linux

Raspbian is based on Debian operating system for the Raspberry Pi. There are several versions of Raspbian, including Raspbian wheezy and Raspbian Jessie. With 2015 officially presented Raspbian the Raspberry Pi Foundation as the primary operating system for single Board computers Raspberry Pi.

I bought raspberries to start making smart home. To Take only the cost

Download the package from Raspbian, I took this one:

$ wget -O && unzip ./

Wait for finish, and while you can see the desired information about a mounted SD flash drive. Insert the USB flash drive ( my OS — Makos) and find the mount area:

$ diskutil list
/dev/disk0 (internal, physical):
 0: GUID_partition_scheme *500.3 GB disk0
 1: EFI EFI 209.7 MB disk0s1
 2: Apple_APFS Container disk1 499.4 GB disk0s2

/dev/disk1 (synthesized):
 0: APFS Container Scheme - +499.4 GB disk1
 Physical Store disk0s2
 1: APFS Volume Macintosh HD 472.9 GB disk1s1
 2: APFS Volume Preboot 44.1 MB disk1s2
 3: APFS Volume Recovery 522.8 MB disk1s3
 4: APFS Volume VM 1.1 GB disk1s4

/dev/disk3 (internal, physical):
 0: FDisk_partition_scheme *128.2 GB disk3
 1: Windows_NTFS 128.2 GB disk3s1

PS: you Can use (but not very informative as for me):

$ mount

From the output it is evident that mine was /dev/disk3. For Linux systems you can use:

$ df-aTh


$ cat /proc/mounts
$ cat /proc/self/mounts

Format the SD card as follows:

$ sudo diskutil eraseDisk FAT32 RASPBIAN MBRFormat /dev/disk3

Started erase on disk3
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Disk3s1 Formatting as MS-DOS (FAT32) with name RASPBIAN
512 bytes per physical sector
/dev/rdisk3s1: 250253568 sectors in 3910212 FAT32 clusters (32768 bytes/cluster)
bps=512 spc=64 res=32 nft=2 mid=0xf8 spt=32 hds=255 hid=32768 drv=0x80 bsec=250314752 bspf=30549 rdcl=2 part no infs=1 bkbs=6
Mounting disk
Finished erase on disk3


  • sudo — Gives super user rights.
  • diskutil — is the utility.
  • eraseDisk Command for formatting.
  • FAT32 — Setting type of FS.
  • RASPBIAN is the name of the device.
  • MBRFormat Says disk utility to format the flash drive in the Master Boot Record.
  • /dev/disk3 — Locationpath to the SD card.

After raspalubki archive image for rebiana, I have a file 2019-04-08-raspbian-stretch-lite.img which should be written on the SD card, I’ll use dd as follows:

$ sudo dd if=2019-04-08-raspbian-stretch-lite.img of=/dev/disk3 bs=1m

Got error:

dd: /dev/disk2: Resource busy

To fix, it should unmount the volyum, because the OS is running with it:

$ diskutil unmountDisk /dev/disk3

Unmount of all volumes on disk3 was successful

And then, again execute:

$ sudo dd if=2019-04-08-raspbian-stretch-lite.img of=/dev/disk3 bs=1m

1720+0 records in
1720+0 records out
1803550720 bytes transferred in 590.702848 secs (3053228 bytes/sec)

Manual for working with DD here:

<Alas, still only in draft ? >

To disable USB flash drive ( for MacOS), I zayuzat:

$ diskutil eject /dev/disk3

Disk /dev/disk3 ejected

Useful reading:

Make a bootable USB from an ISO image on Unix/Linux

You can now insert this SD card in rasberry PI and start the installation. Of course, this will need keyboard, screen, power. I have all these… let’s get started! Have raspberry no power button, this is it. at once. And so to enter we need:

  • Login: pi
  • Password: raspberry

Immediately login as root and:

$ sudo-s

The need now is to connect to the raspberry. And start tweaking. I think I’ll start with the updates:

# apt update && apt upgrade && apt dist-upgrade

Then set the desired locale, I have:

# dpkg-reconfigure locales

And in so also:

# localedef -i en_US -f UTF-8 en_US.UTF-8


# LANG=en_US.utf8

And look there:

[email protected]:~ $ locale


Custom time-zone:

# dpkg-reconfigure tzdata

To check date run:

# date
Thu May 9 17:04:52 EEST 2019

Create a new user:

# adduser captain

Add user to sudo group:

# usermod -a-G sudo captain

Update the firmware and reboot in case of success:

# rpi-update && reboot

Update set, you can now configure the network, open:

# vim /etc/network/interfaces 

And bring to mind:

# 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

# dns-* options are implemented by the resolvconf package, if installed

iface eth0 inet manual

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

# default

With a Raspberry Pi 3 also has a Wi-Fi module for this, it is possible to use and configure it to do this, open:

# vim /etc/wpa_supplicant/wpa_supplicant.conf

Bring to mind:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


  • ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev — googled what it is. It was by default.
  • update_config=1 — Also defaulted.
  • country=UA — Set country code.
  • ssid=”Captain” — the Name of the Wi-Fi.
  • psk=”Jocker666″ — the Password from the Wi-Fi.
  • proto=RSN
  • key_mgmt=WPA-PSK Encryption. I have configured WPA2 personal.
  • pairwise=CCMP
  • group=CCMP
  • auth_alg=OPEN

Or you can do this using the tool:

# raspi-config

I googled what else you need to put this:

# apt install wicd wicd-curses

Not sure what you need, but I put my network on the Wi-Fi.

Also, add ssh into the startup OS:

# systemctl enable ssh

Now, you can photounit fstab, open:

# vim /etc/fstab

Add “noatime” to everything, I have this:

proc /proc proc defaults 0 0
PARTUUID=126fbf65-01 /boot vfat ro,noatime 0 2
PARTUUID=126fbf65-02 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that

Also, for `boot`, prescribed “ro”.

Open config.txt:

# vim /boot/config.txt

You can add:

# for more options see


# vim /boot/cmdline.txt

In the “elevator” added noop:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=126fbf65-02 rootfstype=ext4 elevator=noop rootwait

You can create a file “/etc/default/rcS” and add the following:

# automatically repair filesystems with inconsistencies during boot

Then execute:

# tune2fs -c 3 /dev/mmcblk0p2

tune2fs 1.43.4 (31-Jan-2017)
Setting maximal mount count to 3

Note: If you do not are very sure with the partition (I have /dev/mmcblk0p2), it is possible to look with the utility:

# fdisk-l

Install log2ram to optimize I/O on the flash drive:

# curl -Lo log2ram.tar.gz && tar xf log2ram.tar.gz && cd log2ram-master && chmod +x && sudo ./ && cd .. && rm-r log2ram*

This automatiza need to logs as possible were written to the SD card. The card is not eternal and isness is fast!

Turn off swapping:

# dphys-swapfile swapoff
# dphys-swapfile uninstall
# update-rc.d dphys-swapfile remove

After that, do reboot:

# reboot

I have a router — time capsule, and to open the port in the world, it took me a while and some help from a friend (Thanks Loper). You configure this here. Open “AirPort Utility”:

Click on the capsule and click on “Edit”. Then, go to the tab “Network”:

In the “DHCP Reservation”, click on “+” to reserve a WLAN IP address, for example:


  • Description — The Name.
  • Reserve Address By — Should choose “Mac Address”.
  • Mac Address Is the Mac address of your raspberry on WLAN.
  • IPv4 Address — Address of the reserve.

To view the Mac address, perform at the Malin:

# ifconfig -a wlan0 | grep -E "ether"| awk '{print $2}'

After all the additions, click on “Save”. Now, we need to open a port, go to “Port Settings” and click on “+”:


  • Description — Select “Remote login — SSH”.
  • Public TCP Ports Select the desired port for probrasyvanie. I have this 22.
  • Private IP Address — a Reserved address of IP ( done above).
  • Private TCP Ports — the Port to listen on raspberries. I have it too — 22.

Click on “Save” and then “Update”. Wait until the charged capsule update settings.

That’s all, “Install Raspbian from scratch on a Unix/Linux” has come to an end.


(Visited 67 times, 1 visits today)