1.ダウンロードとUSB HDDへの書込み
まずは、Ubuntu Serverをインストールする。
事前にOSイメージをダウンロードしておいた方が早くHDDに書き込めるし、やり直しも早くできると思う。
Windowsのraspi imagerでHDDにUbuntu Serverを書き込む。
2.USB bootできるように事前各種設定
OSを書き込んだHDDのsystem-bootパーティション内で事前に各種設定を行う。(Windowsで作業)
2-1.カーネル解凍
system-bootパーティション内の"vmlinuz"を7zipで解凍して"vmlinuz~"を"vmlinux"に名前変更
2-2.Headlessインストールの準備
/system-boot/network-configを編集(wifiのコメントを外し、アクセスポイントとPWDを記入)
Ubuntu ServerではdefaultでSSHが有効になっている。
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
→ "aterm-xxxx-a":
→ password: "passwordxxx"
:
:
2-3.ユーザPWDを無期限にする(しなくても良い)
/system-boot/user-data 編集
defaultのユーザー/パスワードは、ubuntu/ubuntu
fqdn: ubuntu # ホスト名 追記しなくても良い
chpasswd:
→ expire: false # trueから変更する
list:
- ubuntu:ubuntu
:
:
2-4.USB boot用の設定
/system-boot/config.txt に追記
[pi4]
#kernel=uboot_rpi_4.bin # コメントアウトする
max_framebuffers=2
# 以下追記
dtoverlay=vc4-fkms-v3d
boot_delay
kernel=vmlinux
initramfs initrd.img followkernel
:
:
2-5.USB boot用カーネルの自動解凍プログラム
以下の内容で'auto_decompress_kernel'と云うスクリプトファイルを作成し、/system-bootパーティションに置く。
#!/bin/bash -e
#Set Variables
BTPATH=/boot/firmware
CKPATH=$BTPATH/vmlinuz
DKPATH=$BTPATH/vmlinux
#Check if compression needs to be done.
if [ -e $BTPATH/check.md5 ]; then
if md5sum --status --ignore-missing -c $BTPATH/check.md5; then
echo -e "\e[32mFiles have not changed, Decompression not needed\e[0m"
exit 0
else echo -e "\e[31mHash failed, kernel will be compressed\e[0m"
fi
fi
#Backup the old decompressed kernel
mv $DKPATH $DKPATH.bak
if [ ! $? == 0 ]; then
echo -e "\e[31mDECOMPRESSED KERNEL BACKUP FAILED!\e[0m"
exit 1
else echo -e "\e[32mDecompressed kernel backup was successful\e[0m"
fi
#Decompress the new kernel
echo "Decompressing kernel: "$CKPATH".............."
zcat $CKPATH > $DKPATH
if [ ! $? == 0 ]; then
echo -e "\e[31mKERNEL FAILED TO DECOMPRESS!\e[0m"
exit 1
else
echo -e "\e[32mKernel Decompressed Succesfully\e[0m"
fi
#Hash the new kernel for checking
md5sum $CKPATH $DKPATH > $BTPATH/check.md5
if [ ! $? == 0 ]; then
echo -e "\e[31mMD5 GENERATION FAILED!\e[0m"
else echo -e "\e[32mMD5 generated Succesfully\e[0m"
fi
#Exit
exit 0
3.毎回USB boot出来るように準備
raspiにHDDと最初は有線LANを繋いで起動しSSHでIPアドレス接続(私の環境では初回に無線LAN使用不可だった)
$ cd /etc/apt/apt.conf.d
$ sudo nano 999_decompress_rpi_kernel # 新規ファイル
# 下記を記入
DPkg::Post-Invoke {"/bin/bash /boot/firmware/auto_decompress_kernel"; };
# 作成したファイルを実行可にする
$ sudo chmod +x 999_decompress_rpi_kernel
# 2-5で作成したスクリプトを実行し、USB bootを可能にするカーネルを解凍
$ cd /boot/firmware/
$ sudo ./auto_decompress_kernel # 実行
# successが表示されたら
$ sudo reboot
4.基本設定
reboot後、SSH接続し以下の順番に実行
$ sudo timedatectl set-timezone Asia/Tokyo # 日本時間
$ sudo dpkg-reconfigure locales # ロケール設定
$ sudo reboot # または、SSH再接続
$ sudo apt update;sudo apt dist-upgrade -y
$ sudo apt install avahi-daemon -y # 名前解決用
# メモリ領域を増やすためSwapファイルを作成
$ free -h # swap sizeの確認
$ sudo apt install dphys-swapfile -y # パッケージ入れる
$ sudo dphys-swapfile install # Swapファイルを作って適用
computing size, want /var/swap=1724MByte, checking existing: keeping it
$ sudo nano /etc/dphys-swapfile # サイズを変更する場合(今回、Defaultで大丈夫だった)
--- CONF_SWAPSIZE=
+++ CONF_SWAPSIZE=2048
$ sudo reboot
5.Ubuntu MATEのインストール
reboot後、SSH接続で以下実行
$ sudo apt install ubuntu-mate-desktop -y # ubuntu Mate
$ sudo reboot
$ sudo apt install xrdp -y # リモートデスクトップ接続用
# ※以降、WindowsのリモートデスクトップでUbuntu Mateにアクセスして作業