community.riocities.com
  • Home
  • Categories
  • Tags
  • Archives

A Basic Alpine Linux XEN domU

Contents

  • A Basic Alpine Linux XEN domU
    • dom0 work
      • Create Installation config
      • Mount /domU_installer
      • Start domU
    • domU work
      • Format root disk
      • Mountpoints etc
      • setup-alpine
      • Store filesystem
      • Update grub
      • Time to halt
    • Post-Install actions
      • Fix dom0's domU config file
      • Start domU
      • Add normal user
      • Add sudo
      • Add swap
      • Confirm network ok
      • Update system
      • Fix autostart of domU
  • Appendix
    • Disk from a storage driver domain running ZFS

A Basic Alpine Linux XEN domU¶

Guide to configure an basic XEN domU based on Alpine 3.8. As Dom0 we use Alpine Dom0 V3.8.

To do this I have the following extra hardware - No extra hardware is needed.

dom0 work¶

We need to create the domU installation configuration file, mount installation image location, and start the installation

Download iso and unpack kernel and initramfs see here: domu-preparation

Create Installation config¶

Now we need to create the domU configuration file.

  • Observe that the MAC address has to be uniq among dom0 and all domU. A tool to help you with this is to use random_mac.py for instance.
  • The cdrom points to the installer image which was prepared in the dom0 installation.

If you do it manually, please start with "00:16:3E" followed by a unique combination for you. For instance "00:16:3e:AA:AA:01"

# cat << EOF > /etc/xen/<domU-hostname>.cfg
#####
##### <domU-hostname> domU
#####
vcpus       = '1'
memory      = '256'
maxmem      = '256'
kernel      = "/domU_installer/vmlinuz-vanilla"
ramdisk     = "/domU_installer/initramfs-vanilla"
extra       = "alpine_dev=hdc:iso9660 modules=loop,squashfs,sd-mod,usb-storage console=hvc0"
disk        = [
                  'file://domU_installer/alpine-extended-3.8.1-x86_64.iso,hdc:cdrom,r',
                  'phy:/<root disk path>/<root disk>,xvda1,w',                  
                  'phy:/<swap disk path>/<swap disk>,xvda2,w',                  
              ]
name        = '<domU-hostname>'
## ENSURE MAC ADDRESS IS UNIQUE!!!
vif         = [ 'mac=<Unique MAC Address>,bridge=br0' ]
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'
EOF

If you are using zfs disks, please see the Appendix.

If you are using LVM disks, it might look like this.

'phy:/dev/vg_domU/<domU-name>-disk,xvda1,w'

If you are using normal disks, it might look like this.

'phy:/dev/sdb1,xvda1,w'

If you are using an file as a disk, you need to create the file, and then use it. Something like this.

# # Create a 3GB file to be used as a disk
# dd if=/dev/zero of=/path/to/disk.img bs=1M count=3000

# # And then use this disk file in the configuration file
‘file:/path/to/disk.img,xvda,w’,

Mount /domU_installer¶

And last we need to make sure that /domU_installer is mounted.

dom0 # mount /domU_installer

Start domU¶

It is time to start the installation, to do this we simple start the domU

dom0 # xl create /etc/xen/<domU-hostname>.cfg -c

To get back to the dom0 environment from the console, you press CTRL+]

Hint If CTRL+] does not work, CTRL+5 could work instead. Please see here for more info Xen_FAQ_Console

At login prompt, simply enter root and no password (default at installation time)

domU work¶

Format root disk¶

# apk add e2fsprogs
# mkfs.ext4 /dev/xvda1

Mountpoints etc¶

Time to configure the mountpoints for root, as well as mount it. We will mount it under /mnt for the installation process.

# mount -t ext4 /dev/xvda1 /mnt

setup-alpine¶

Finally, time to configure (setup) the actual alpine part

Key things to remember

  • Answer none on last questions (Disks, config, and apk repository)
  • Which disk(s) would you like to use? (or '?' for help or 'none') none
  • Enter where to store configs ('floppy', 'usb' or 'none') [none]:
  • Enter apk cache directory (or '?' or 'none') [/var/cache/apk]: none
# setup-alpine
Available keyboard layouts:
af     be     cn     fi     hu     jp     lt     my     ro     tj
al     bg     cz     fo     ie     ke     lv     ng     rs     tm
am     br     de     fr     il     kg     ma     nl     ru     tr
ara    brai   dk     gb     in     kr     md     no     se     tw
at     by     dz     ge     iq     kz     me     ph     si     ua
az     ca     ee     gh     ir     la     mk     pk     sk     us
ba     ch     epo    gr     is     latam  ml     pl     sy     uz
bd     cm     es     hr     it     lk     mt     pt     th
Select keyboard layout [none]: us
Available variants: us-alt-intl us-altgr-intl us-chr us-colemak us-dvorak-alt-intl us-dvorak-classic us-dvorak-intl us-dvorak-l us-dvorak-r us-dvorak us-dvp us-euro us-hbs us-intl us-mac us-olpc2 us-rus us-workman-intl us-workman us
Select variant []: us
 * Caching service dependencies ... [ ok ]
 * Setting keymap ... [ ok ]
Enter system hostname (short form, e.g. 'foo') [localhost]: `<domU-hostname>`
Available interfaces are: eth0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0]
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] 192.168.1.20/24
Gateway? (or 'none') [none] 192.168.1.1
Configuration for eth0:
  type=static
  address=192.168.1.20
  netmask=255.255.255.0
  gateway=192.168.1.1
Do you want to do any manual network configuration? [no]
DNS domain name? (e.g 'bar.com') [] example.com
DNS nameserver(s)? [] 8.8.8.8
Changing password for root
New password:
Retype password:
passwd: password for root changed by root
Which timezone are you in? ('?' for list) [UTC] Australia/Melbourne
 * Starting busybox acpid ... [ ok ]
 * Starting busybox crond ... [ ok ]
HTTP/FTP proxy URL? (e.g. 'http://proxy:8080', or 'none') [none]

Available mirrors:
1) dl-cdn.alpinelinux.org
...
19) http://mirror.aarnet.edu.au
...
36) mirrors.shu.edu.cn

r) Add random from the above list
f) Detect and add fastest mirror from above list
e) Edit /etc/apk/repositories with text editor

Enter mirror number (1-36) or URL to add (or r/f/e/done) [f]: 19
Added mirror mirror.aarnet.edu.au
Updating repository indexes... done.
Which SSH server? ('openssh', 'dropbear' or 'none') [openssh]
 * service sshd added to runlevel default
 * Caching service dependencies ... [ ok ]
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
 * Starting sshd ... [ ok ]
Which NTP client to run? ('busybox', 'openntpd', 'chrony' or 'none') [chrony]
 * service chronyd added to runlevel default
 * Caching service dependencies ... [ ok ]
 * Starting chronyd ... [ ok ]
Available disks are:
  xvda2 (0.5 GB  )
Which disk(s) would you like to use? (or '?' for help or 'none') [none]
Enter where to store configs ('floppy', 'usb' or 'none') [none]:
Enter apk cache directory (or '?' or 'none') [/var/cache/apk]: none
#

Store filesystem¶

Time to install this domU to the filesystem on /mnt (which points to the disk for the / partition after first reboot)

We will use the -m (write system to disk) parameters.

# setup-disk -m sys /mnt
Installing system on /dev/xvda1:
extlinux: Not a directory: /mnt/boot
100% ############################################==> initramfs: creating /boot/initramfs-vanilla
/boot is device /dev/xvda1
extlinux: no previous syslinux boot sector found
You might need fix the MBR to be able to boot

Update grub¶

We need to create a grub boot stanza

# mkdir /mnt/boot/grub
# cat << EOF >  /mnt/boot/grub/grub.cfg
set timeout=2
set default=0
menuentry "alpine" {
    linux /boot/vmlinuz-vanilla modules=ext4 console=hvc0 root=/dev/xvda1
    initrd /boot/initramfs-vanilla
}
EOF

Time to halt¶

Time to halt this newly installed system, and go back to dom0 for some changes.

# halt

Post-Install actions¶

Fix dom0's domU config file¶

We need to update the domU configuration file to use the pv grub bootloader, as well as remove the cdrom entry.

dom0 # cat << EOF >  /etc/xen/<domU-hostname>.cfg
####
#### <domU-hostname> domU
####
vcpus       = '1'
memory      = '256'
maxmem      = '256'
kernel      = "/usr/lib/grub-xen/grub-x86_64-xen.bin"
disk        = [
                  'phy:/<root disk path>/<root disk>,xvda1,w',                  
                  'phy:/<swap disk path>/<swap disk>,xvda2,w',                  
              ]
name        = '<domU-hostname>'
## ENSURE MAC ADDRESS IS UNIQ!!!
vif         = [ 'mac=<Unique MAC Address>,bridge=br0' ]
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'
EOF

And lastly we need to make these changes restart safe

dom0 # lbu commit

Start domU¶

Finally time to start the newly created domU, and see if it all works.

dom0 # xl create /etc/xen/<domU-hostname>.cfg -c

Add normal user¶

As per normal security, we should not use the root account for normal operations, so we need to create a normal user, add it to wheel

# adduser <username>

Add sudo¶

For security reasons, and good practice, lets install sudo

# apk add sudo
# sed -e 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g' -i /etc/sudoers
# adduser <username> wheel

Add swap¶

We need to put the swap on the swap disk

# mkswap /dev/xvda2
# swapon /dev/xvda2
# echo "/dev/xvda2  none  swap  sw 0  0" >> /etc/fstab
# swapon -a
# rc-update add swap

Confirm network ok¶

Ensure we can ping google

# ping www.google.com

Update system¶

Good practice to update the system

# apk update
# apk upgrade

Fix autostart of domU¶

Time to fix so that this domU is automatically started on reboot

Lets stop domU

# halt

And on the dom0 we create the auto start link, remember, do not forget to give the lbu commit command.

If you want to have some control of when this particular domU will be started, preceed the config file name with a numeric part, where 00 is first in priority, and 99 is last. For instance, if you want this particular domU to be started first, you should give it the following link name. 00-.cfg

dom0 # ln -s /etc/xen/<domU-hostname>.cfg /etc/xen/auto/<NN-domU-hostname>.cfg
dom0 # lbu commit

Reboot to verify

dom0 # reboot

or if you prefere to just restart the service

dom0 # service xendomains restart

and after dom0 is up and running again, check that the newly created domU domain is running

dom0 # xl list

Appendix¶

Disk from a storage driver domain running ZFS¶

If you are using a storage driver domU with ZFS, like Alpine Storage DomU V3.8, you need to add the backend= to the disk specification. For how to create the zfs based disks, please look at Alpine Storage DomU V3.8

Example

disk        = [
                  'backend=<Storage driver domU name>,phy:/dev/zvol/tank/xen/<domU name>-disk,xvda1,w',
              ]

Example on my system

disk        = [
                  'backend=zfshost,phy:/dev/zvol/tank/xen/dns-disk,xvda1,w',
              ]

  • « Alpine v3.8 Linux as a XEN dom0 from a USB stick
  • Alpine Linux XEN dom0 from a USB stick - upgrading »

Published

Aug 24, 2018

Last Updated

2018-11-06 05:12:46+01:00

Author

bengt

Category

HOWTOs

Tags

  • Alpine 15
  • XEN 21

Social

  • atom feed
  • rss feed
  • ipv6 ready
  • Powered by Pelican. Theme: Elegant by Talha Mansoor