Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheNicholasNick/28f21f5ad724b4e8658c07f1999f5af1 to your computer and use it in GitHub Desktop.
Save TheNicholasNick/28f21f5ad724b4e8658c07f1999f5af1 to your computer and use it in GitHub Desktop.
Arch Linux, UEFI, LVM - Hyper-V Guest

Install Arch Linux Guest on Hyper-V

Published: 11 Sep 2018 / Updated: 03 May 2023
Original: https://gist.github.com/SoreGums/28f21f5ad724b4e8658c07f1999f5af1
Continuation of: https://gist.github.com/SoreGums/9171333

Simple to the point no fluff install Arch Linux on Windows Hyper-V
I don't explain much - if you want explanations hit up the Wiki or Arch on UEFI Machines or Josh Braun's blog.
I used Josh's guide, the Wiki and Tech Mint article to come up with the below.

This laptop fo mine has incompatible linux drivers for the Nvidia GTX 980m (2018-09-01) and I can't run a Linux Desktop well at all. Screen won't turn on when resume from sleep, lid open, desktop locked, hiberation, etc - pretty rubbish.

Configure Hyper-V VM

  • Arch Linux (64bit) going to use 12GB of RAM
    • host: Windows 10 x64 w/ 64GB RAM, Core i7-6820HK @ 2.7GHz
  • Generation 2 (UEFI)
  • Base Memory: 12288MB
  • Processors: 4
  • Execution Cap: 90%
  • 127GB Dynamic VHD
  • Network: Interent + Internal (192.168.10.x/24)
  • Secure Boot: OFF
  • Boot from (latest ISO 2023.04.01)(https://www.archlinux.org/download/)

Install Arch

Turn on the VM

Should boot to a root prompt

systemctl start sshd
passwd
ip a
ip a add 192.168.10.10/24 dev eth1

Connect via PuTTY

Mirrors

Set the mirrors to use from mirrorlist generator

cd /etc/pacman.d/
mv mirrorlist mirrorlist.old
nano /etc/pacman.d/mirrorlist
>>> paste in your list from before, make sure you remove comments of the mirrors you want to use

Partition, Format and mount

No Fluff

cfdisk /dev/sda
>> 1G(EFI), rest (ext4)
mkfs.fat -F32 /dev/sda1
mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt

Docker Idea

cfdisk /dev/sda
>> 1G(EFI), rest (ext4)
mkfs.fat -F32 /dev/sda1
vgcreate vg /dev/sda2
lvcreate -L 2G -n swap vg
lvcreate -L 20G -n root vg
lvcreate -L 50G -n docker vg
modprobe dm_mod
vgscan
vgchange -ay
mkswap /dev/mapper/vg-swap
swapon /dev/mapper/vg-swap
mkfs.ext4 /dev/mapper/vg-root
modprobe btrfs
mkfs.btrfs /dev/mapper/vg-docker
mount /dev/mapper/vg-root /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
mkdir -p /mnt/var/lib/docker
mount /dev/mapper/vg-docker /mnt/var/lib/docker

Install

cd /
pacstrap /mnt base base-devel nano linux linux-firmware

Wait a long time or short time depending on your connection...

pacstrap /mnt base base-devel  38.49s user 38.37s system 4% cpu 29:05.81 total
run on Windows 8.1x64 mechanical 20Mbps ADSL2+ connection

Nice it tells you how long it took, need to run this again on my laptop at the office then (SSD).

12 Dec 2016 run on Win10x64 Laptop w/ PrimoCache (RAM > SSD > HDD)
pacstrap /mnt base base-devel  30.32s user 3.60s system 12% cpu 4:36.22 total

Finishing up to Reboot

Remember this guide is no frills, these are the minimum commands to run.

genfstab -p /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab
mkdir /mnt/hostrun
mount --bind /run /mnt/hostrun
arch-chroot /mnt /bin/bash
mount --bind /hostrun/lvm /run/lvm
nano /etc/locale.gen
locale-gen
echo LANG=en_AU.UTF-8 > /etc/locale.conf
ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime
date
hwclock --systohc --utc
# EDIT THESE APPS as required, I'm using Docker and want gui containers on my windows host
pacman -S zsh grub efibootmgr dosfstools os-prober mtools openssh sudo lvm2 btrfs-progs git xorg-x11
passwd
useradd -mg users -G wheel,storage,power,adm -s /bin/zsh user
passwd user
export EDITOR="nano"
visudo
>>>> uncomment line: %wheel ALL=(ALL) ALL
nano /etc/ssh/sshd_config
>>>> ListenAddress 192.168.10.10
>>>> PasswordAuthentication no
mkdir -p /home/user/.ssh
touch /home/user/.ssh/authorized_keys
chmod 700 /home/user/.ssh
chmod 600 /home/user/.ssh/*
cat << 'EOT' > /home/user/.ssh/authorized_keys
sshkeyhere
EOT
chown -R user:users /home/user
nano /etc/mkinitcpio.conf
>>>> HOOKS="....ock lvm2 file..."
mkdir /boot/EFI
mount /dev/sda1 /boot/EFI
grub-install --target=x86_64-efi  --bootloader-id=grub_uefi --recheck
sudo nano /etc/default/grub
>>>> set GRUB_TIMEOUT to 1
grub-mkconfig -o /boot/grub/grub.cfg
cat << 'EOT' > /etc/netctl/eth0-dhcp
Description='A basic dhcp ethernet connection'
Interface=eth0
Connection=ethernet
IP=dhcp
## for IPv6 autoconfiguration
IP6=stateless
EOT
cat /etc/netctl/eth1-static
Description='A basic static ethernet connection'
Interface=eth1
Connection=ethernet
IP=static
Address=('192.168.10.10/24')
## For IPv6 autoconfiguration
IP6=stateless
EOT
systemctl enable sshd eth0-dhcp eth1-static
# stop console going blank
echo -ne "\033[9;0]" >> /etc/issue
exit
umount -R /mnt
shutdown -h now
>>> remove the cd
>>> start vm
>>> restart ssh session, login as user this time
sudo pacman -Syu
sudo hostnamectl set-hostname arch
sudo reboot 

All done.
You'll notice that Arch Linux is a speed demon to restart, it is almost instant, by the time you get your bearings the prompt is flashing reading to login again.

That's it you're on your own now.

Notes

kernel at the time was 4.18.6 the hyper-v drivers seem to work.
To get the info to populate the network tab, need hv_kvp_daemon which can be got by compiling the hv tool in the kernel sources

uname -a
> Linux arch 4.18.6-arch1-1-ARCH #1 SMP PREEMPT Wed Sep 5 11:54:09 UTC 2018 x86_64 GNU/Linux
cd /tmp  
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.18.6.tar.sign
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.18.6.tar.xz
unxz linux-4.18.6.tar.xz
gpg2 --locate-keys torvalds@kernel.org gregkh@kernel.org
gpg2 --verify linux-4.18.6.tar.sign
tar xf linux-4.18.6.tar.xz
cd linux-4.18.6/tools
make hv
sudo make hv_install
hv_kvp_daemon -n

so that works, however it isn't really complete as each distro does things differenctly and linux kernel can't exactly handle all distros. there is a bug outstanding in Arch to fix up the tool in pacman https://bugs.archlinux.org/task/55579

Server Swap less

sudo nano /etc/sysctl.d/99-sysctl.conf
vm.swappiness=10

Power aliases

cat << 'EOT' > /home/user/.bashrc_aliases
alias reboot="sudo systemctl reboot"
alias poweroff="sudo systemctl poweroff"
alias halt="sudo systemctl halt"
EOT
cat << 'EOT' >> /home/user/.bashrc
# include .bashrc_aiases if it exists
if [ -f $HOME/.bashrc_aliases ]; then
    . $HOME/.bashrc_aliases
fi
EOT

VSCode, VNC, i3

I use vscode in a vnc window and do everything else on the Windows host. Maybe I'll figure out i3 commands and make it full screen. For now turned off sending special keys (realvnc client) so can alt+tab. Using a 4K screen so made window fairly large and is a lot more performant than X11 over ssh.

sudo pacman -Syu tigervnc code i3-wm i3status ttf-dejavu ttf-fira-code
mkdir -p /home/user/.config/i3
cat << 'EOT' > /home/user/.config/i3/config
# i3 config file (v4)
font pango:DejaVu Sans Mono 14
bar {
        status_command i3status
}
exec code
EOT

# run vncserver once to create config
vncserver
vncserver -kill :1
cat << 'EOT' > /home/user/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
i3 &
EOT

cat << 'EOT' > /home/user/.vnc/config
geometry=3400x1700
interface=192.168.10.10
EOT

mkdir -p /home/user/.config/Code\ -\ OSS/User
cat << 'EOT' > /home/user/.config/Code\ -\ OSS/User/settings.json
{
    "workbench.colorTheme": "Solarized Dark",
    "window.zoomLevel": 1.5,
    "editor.fontFamily": "'Fira Code'",
    "editor.fontLigatures": true
}
EOT

vncserver
@ktec
Copy link

ktec commented Sep 10, 2018

Yaourt is not recommended any more - plenty others to choose from https://wiki.archlinux.org/index.php/AUR_helpers

@TheNicholasNick
Copy link
Author

i didn't actually install that, so will remove - I don't need it - thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment