# grow the root partition
sgdisk -n 0:0

# grow root filesystem
lsblk
resize2fs /dev/nvme0n1pX

# Ethernet
ip l s
dhclient <device>

# Wifi
rmmod brcmfmac
rmmod brcmutil
mount /dev/sda1 /mnt
tar -C /lib/firmware/ -xf /mnt/linux-firmware.tar
umount /mnt
modprobe brcmfmac
vim /etc/wpa_supplicant/wpa_supplicant.conf
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
dhclient wlan0

# Time
ntpdate pool.ntp.org
date --set 2022-01-25
date --set 14:21

# Configure timezone
dpkg-reconfigure tzdata

# Fix grub
# We deinstall grub-efi-arm64-signed- because it creates a file fbaa64.efi
# which makes u-boot hang.
apt-get install grub-efi grub-efi-arm64-signed-
grub-install --target=arm64-efi --efi-directory=/boot/efi --removable
update-grub
# Set removable media to yes and nvram to no to make later grub updates work
dpkg-reconfigure grub-efi-arm64

See also: https://github.com/AsahiLinux/docs/wiki/U-Boot

# xorg

# Keyboard use capslock as additional ctrl
cat > /etc/X11/xorg.conf.d/00-keyboard.conf <<'EOF'
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us"
        Option "XkbModel" "pc105"
        Option "XkbVariant" "de_se_fi"
        Option "XkbOptions" "ctrl:nocaps"
EndSection
EOF

# Swap command and option (windows and alt like on a pc keyboard)
echo 1 > /sys/module/hid_apple/parameters/swap_opt_cmd

# Configure the touchpad
cat > /etc/X11/xorg.conf.d/30-input.conf <<'EOF'
Section "InputClass"
  Identifier "libinput touchpad catchall"
  MatchIsTouchpad "on"
  MatchDevicePath "/dev/input/event*"
  Option "Tapping" "False"
  Option "TappingDrag" "False"
  Option "DisableWhileTyping" "True"
  Option "AccelProfile" "adaptive"
  Option "AccelSpeed" "0.3"
  Option "AccelerationNumerator" "2"
  Option "AccelerationDenominator" "1"
  Option "AccelerationThreshold" "4"
  Option "AdaptiveDeceleration" "2"
  Option "NaturalScrolling" "0"
        Option "TappingButtonMap" "lmr"
        Option "ClickMethod" "clickfinger"
  Driver "libinput"
EndSection
EOF

# Create a user
useradd -m -c 'firstname lastname' -s /bin/bash username
passwd username

# Lightweight desktop
apt-get install lightdm blackbox xterm firefox-esr

# Install gnome
apt-get install gnome
/etc/init.d/gdm3 start

# If you need to install the kernel on a bootstrapped system or one that needs recovery
wget https://tg.st/u/k.deb
dpkg -i k.deb

# asahi does not handle sleep well at the moment
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

- You can also use the live system to install Debian on the m1, the rough outline is:

        - Create two paritions:

                - One 1 GB vfat
                - Rest with ext4

        - Use debootstrap to bootstrap debian

        - Install the kernel

        - Install grub

        - reboot

Repack live
===========
You might want to save the state of your live system to the usb stick. In order
to do so, run the following commands:

apt update
apt-get install -y cpio pigz
rm /etc/rc.local
# remove '#' before allow-hotplug
vi /etc/network/interfaces
mount /dev/sda1 /mnt
mv /mnt/initrd.gz /mnt/initrd.old
cd /
find . -xdev | cpio --quiet -H newc -o | pigz -9 > /mnt/initrd.gz
umount /mnt