# Debian on the SiFive HiFive Unmatched RISC-V Motherboard

```
sudo apt install mmdebstrap qemu-user-static binfmt-support debian-ports-archive-keyring

sudo mmdebstrap								\
	--architectures=riscv64						\
	--include="debian-ports-archive-keyring"			\
	sid								\
	unmatched-root							\
	"deb http://deb.debian.org/debian-ports/ sid main"		\
	"deb http://deb.debian.org/debian-ports/ unreleased main"	\
	--aptopt='Acquire::Languages { "environment"; "en"; }'		\
	--aptopt='Acquire::Languages "none"'				\
	--aptopt='Apt::Install-Recommends "false"'			\
	--aptopt='Acquire::http::Proxy "http://192.168.110.8:3142"'	\
	--variant=apt							\
	--dpkgopt="path-exclude=/usr/share/man/*"			\
	--dpkgopt='path-exclude=/usr/share/doc/*'			\
	--include=net-tools,iproute2,isc-dhcp-client,systemd,udev,debian-archive-keyring,debian-ports-archive-keyring,debian-keyring,gnupg2,systemd-sysv,procps,lshw,ifupdown,kmod,nano,fdisk,parted,e2fsprogs,sshfs,rsyslog,less,sudo,apt-utils,locales

# Go into root and fix some stuff up:
# /etc/fstab
# /dev/mmc*
# mkdir /dev/pts
# /dev/nvme*
# symlink /sbin/init

cd unmatched-root/etc/
sudo vim fstab
# thusly:
proc            /proc           proc    defaults                                0  0
devpts          /dev/pts        devpts  mode=0620,ptmxmode=0666,gid=5           0  0
tmpfs           /run            tmpfs   mode=0755,nodev,nosuid,strictatime      0  0
sysfs           /sys            sysfs   defaults        0 0

/dev/nvme0n1p4  /               auto    errors=remount-ro                       0  1
/dev/mmcblk0p3  /boot           vfat    defaults                                0  0



####
cd ../dev
#sudo mkdir -p pts
# maybe?
sudo mknod mmcblk0 b 179 0
sudo mknod mmcblk0p1 b 179 1
sudo mknod mmcblk0p2 b 179 2
sudo mknod mmcblk0p3 b 179 3
sudo mknod mmcblk0p4 b 179 4
sudo mknod mmcblk0p5 b 179 5
sudo mknod mmcblk0p6 b 179 6
# nvme ?
# XXX NOTE /dev permissions are bad! XXX
sudo chmod 600 console
sudo chown root:disk mmcblk0*
sudo chmod 660 mmcblk0*

cd ../sbin/
# already there?
sudo ln -s /lib/systemd/systemd init

# Set up network
vim etc/network/interfaces
# fill with:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

###
# root image is done, tarball it
cd ../../
sudo tar cf unmatched-root.tar unmatched-root/
# put unmatched-root.tar on webserver for Unmatched to wget
# put sda1 sda2 sda3 for Umatched to wget
dd if=sda1 of=/dev/nvme0n1p1
dd if=sda2 of=/dev/nvme0n1p2
dd if=sda3 of=/dev/nvme0n1p3 status=progress
sync
```

# On the Unmatched
Log in via serial to the default Unmatched image.

## Get root tarball
wget http://192.168.1.1/unmatched-root.tar
sync

## Partition nvme drives
Set up partions similar to sd card:
```
root@unmatched:~# fdisk -l /dev/mmcblk0
...
Device          Start      End  Sectors  Size Type
/dev/mmcblk0p1     34     2081     2048    1M HiFive Unleashed FSBL
/dev/mmcblk0p2   2082    10273     8192    4M HiFive Unleashed BBL
/dev/mmcblk0p3  16384   282623   266240  130M Microsoft basic data
/dev/mmcblk0p4 286720 13918207 13631488  6.5G Linux filesystem
```

```
fdisk /dev/nvme0n1
# g for GPT partition
# n for new partion
# 1 for partition 1
# 2048 for first sector
# +1M for size
# t for type
# 107 for HiFive Unleashed FSBL
# n for new partition
# 2 for partition 2
# 4096 for first sector
# +4M for size
# t for type
# 2 for partition 2
# 108 for HiFive Unleashed BBL
# n for new partition
# 3 for partition 3
# 12288 for first sector
# +130M for size
# t for type
# 3 for partition 3
# 11 for Microsoft basic data
# n for new partition
# 4 for partition 4
# 278528 for first sector
# <enter> for last sector (max size)
# w for write and exit

# format the thing:
mkfs.vfat /dev/nvme0n1p3
mkfs.ext4 /dev/nvme0n1p4

# set the time or tar complains:
date -u --set="20210602 12:00:00"

# mount up
mount /dev/nvme0n1p4 /mnt
cd /mnt
tar xf ~/unmatched-root.tar
mv unmatched-root/*
rmdir unmatched-root
cd
vim etc/shadow
vim etc/hostname
umount /mnt
fsck /dev/nvme0n1p4

# XXX CRYPTSETUP
# XXX hostname
# XXX root password
sed -i -e 's/root:\*/root:/g' /run/media/nvme0n1p4/etc/shadow
# XXX dd sda1 sda2 onto nvme
apt install dialog
```
## Edit /boot/extlinux/extlinux.conf
default debian
label debian
   menu label debian
   kernel /Image.gz
   fdt /hifive-unmatched-a00.dtb
   append earlyprintk rw root=/dev/nvme0n1p4 rootfstype=ext4 rootwait console=ttySIF0,115200 earlycon

#
umount /boot/
fsck /dev/mmcblk0p3

poweroff

```
