개발하는 핑구
article thumbnail

MacOS에서 Raspberry Pi 4에 Ubuntu Server 20.04를 설치하는 과정을 알아보고자 한다.

원격으로 접속할 것이기 때문에 HDMI나 모니터는 따로 필요 없다.

https://roboticsbackend.com/install-ubuntu-on-raspberry-pi-without-monitor/를 참조했다.

 

Install Ubuntu 20.04 on Raspberry Pi 4 (without monitor) - The Robotics Back-End

Install Ubuntu 20.04 on Raspberry Pi 4. Complete step by step tutorial to install and configure everything you need to get started.

roboticsbackend.com

What you'll need

  • A microSD card (4GB minimum, 8GB recommended)
  • A Raspberry Pi 4
  • A micro-USB power cable (USB-C for the Pi 4)
  • A microSD card Reader

위의 네 가지 부품이 준비가 되었다면, microSD카드에 ubuntu를 굽기 위해 Rasberry Pi Imager를 설치한다.

https://www.raspberrypi.com/software/

위 링크에서 직접 다운로드하거나 터미널로 설치하는 것도 가능하다.

brew install --cask raspberry-pi-imager

만약에 homebrew가 설치되지 않은 상태라면 homebrew를 먼저 설치한다.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Flash Ubuntu image into a micro SD card

다음 과정은 카드 리더기에 microSD카드를 장착 후 컴퓨터에 연결한 상태를 가정하고 있다.

microSD카드에 우분투 이미지를 굽기 위해 Raspberry Pi Imager를 실행한다.

CHOOSE OS를 눌러 우리가 설치할 우분투를 선택.

해당 소프트웨어에서 여러가지 버전을 제공해주고 있는데, 나는 Ubuntu Server 20.04.5 LTS(64-bit)를 선택했다.

그리고 Desktop과 Server로 나누어져있는데, 항상 ssh로 접속할 것이기 때문에 Server를 선택했다. Server는 기본적으로 GUI를 제공하지 않는다. 하지만 Server 버전으로 우분투를 설치했더라도 추후에 Desktop 환경을 추가로 설치할 수 있다.

다음 CHOOSE STORAGE를 눌러 컴퓨터에 꽂은 microSD카드를 선택. 이후 WRITE를 눌러 설치를 시작.

설치가 완료되면 리더기가 바로 컴퓨터에서 Eject된 상태가 되는데 네트워크 설정을 위해 다시 컴퓨터에 연결해준다.

Setup Wi-Fi and ssh for your Raspberry Pi 4 without a monitor

지금부턴 터미널에서 네트워크 설정을 진행한다.

vi /Volumes/system-boot/network-config

초기 network-config 상태.

# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#
# Some additional examples are commented out below

version: 2
ethernets:
  eth0:
    dhcp4: true
    optional: true
#wifis:
#  wlan0:
#    dhcp4: true
#    optional: true
#    access-points:
#      myhomewifi:
#        password: "S3kr1t"
#      myworkwifi:
#        password: "correct battery horse staple"
#      workssid:
#        auth:
#          key-management: eap
#          method: peap
#          identity: "me@example.com"
#          password: "passw0rd"
#          ca-certificate: /etc/my_ca.pem

컴퓨터에 연결되어 있는 네트워크와 동일한 네트워크의 이름과 패스워드를 다음과 같이 추가해준다. 들여쓰기 공백은 항상 탭이 아닌 space 두번으로 입력해야 한다.

version: 2
ethernets:
  eth0:
    dhcp4: true
    optional: true
wifis:
  wlan0:
    dhcp4: true
    optional: true
    access-points:
      "YOUR_WIFI_NAME":
        password: "YOUR_WIFI_PASSWORD"

ssh 접속을 위해 따로 수정할 것은 없고 user-data에 다음과 같이 정상적으로 저장되어 있는지 확인한다.

vi /Volumes/system-boot/user-data
...

# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
  expire: true
  list:
  - ubuntu:ubuntu

# Enable password authentication with the SSH daemon
ssh_pwauth: true

...

Find the Pi’s IP address

먼저 Raspberry Pi 4를 부팅하기 전에, IP List를 확인할 수 있는 환경을 먼저 만들어준다.

먼저 인터넷 창에 http://192.168.0.1 입력해 공유기에 접속.

비밀번호를 입력 후,

관리도구 -> 고급 설정 -> 내부 네트워크 설정에 들어가게 되면, 현재 공유기에 접속되어 있는 단말기의 IP를 확인할 수 있다.

Ubuntu 20.04 boot on Raspberry Pi 4

모든 세팅이 끝났기 때문에 microSD카드를 컴퓨터에서 제거 후 Raspberry Pi 4에 장착해준다. 이때 microSD를 장착한 후에 Power를 연결한다. Power를 연결 후 green LED가 깜빡거려야 정상적으로 부팅되고 있는 것이다. 부팅이 되고나면 위에서 설정했던 네트워크 정보를 가지고 자동으로 네트워크에 접속된다.

 

주의!

첫 부팅 시에, IP가 확인되지 않을 수 있다. 다시 말해, 네트워크에 정상적으로 연결이 안될 수 있는데 이 경우에는 2분 정도 기다렸다가 Raspberry Pi 4의 Power를 껐다 켜준다. 재부팅 후에 네트워크에 정상적으로 연결되어 IP를 확인할 수 있다.

ssh connection to the Raspberry Pi 4

현재 Raspberry Pi 4의 hostname과 username은 ubuntu로 설정되어 있다.

ssh ubuntu@[IP of Raspberry Pi 4]

첫 ssh 접속 시에 다음과 같은 문구가 나오면 yes를 입력.

The authenticity of host '192.168.x.x (192.168.x.x)' can't be established.
ECDSA key fingerprint is SHA256:rNDFgv1H3GqIhNPJ7wYI5963+/vbob2HOY1W4FekG/0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

다음 새 비밀번호까지 입력해주고나면, Ubuntu가 설치된 Raspberry Pi 4를 사용할 준비가 끝난다.

profile

개발하는 핑구

@sinq

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!