Add basic user-data yaml, update README
This commit is contained in:
parent
54243ab99d
commit
1a2788ab29
111
README.md
111
README.md
@ -1,3 +1,112 @@
|
||||
# kvm
|
||||
|
||||
Working on scripting to create a VM from a template.
|
||||
Working on scripting to create a VM from a template.
|
||||
|
||||
[Ubuntu 22.04.5 LTS (Jammy Jellyfish)](https://releases.ubuntu.com/jammy/ubuntu-22.04.5-live-server-amd64.iso)
|
||||
|
||||
Note that the following steps are derived from this [guide](https://www.pugetsystems.com/labs/hpc/ubuntu-22-04-server-autoinstall-iso/)
|
||||
|
||||
1. Install necessary packages
|
||||
|
||||
```bash
|
||||
apt install xorriso
|
||||
apt install p7zip
|
||||
```
|
||||
|
||||
2. Download the Ubuntu image
|
||||
|
||||
```bash
|
||||
mkdir iso-build
|
||||
cd iso-build
|
||||
wget https://releases.ubuntu.com/jammy/ubuntu-22.04.5-live-server-amd64.iso
|
||||
```
|
||||
|
||||
3. Unpack the files and partition the images
|
||||
|
||||
```bash
|
||||
mkdir source-files
|
||||
7z -y x ubuntu-22.04.5-live-server-amd64.iso -osource-files
|
||||
```
|
||||
|
||||
4. In the source-files directory, you will see the ISO files plus a directory named ‘[BOOT]’, which contains 1-Boot-NoEmul.img and 2-Boot-NoEmul.img. Those are, respectively, the mbr (master boot record) and efi (UEFI) partition images from the ISO. They will be used to create the modified ISO. There is no reason to leave the raw image files on the new ISO, so move them out of the way and give the directory a better name.
|
||||
|
||||
```bash
|
||||
cd source-files
|
||||
ls
|
||||
mv '[BOOT]' ../BOOT
|
||||
```
|
||||
|
||||
5. Edit the grub.cfg file at `source-files/boot/grub/grub.cfg`
|
||||
|
||||
```bash
|
||||
vim boot/grub/grub.cfg
|
||||
```
|
||||
|
||||
Add the following above the existing menu entries:
|
||||
|
||||
```bash
|
||||
menuentry "Autoinstall Ubuntu Server" {
|
||||
set gfxpayload=keep
|
||||
linux /casper/vmlinuz quiet autoinstall ds=nocloud\;s=/cdrom/server/ ---
|
||||
initrd /casper/initrd
|
||||
}
|
||||
```
|
||||
|
||||
This will enable autoinstall and reference the `server` directory where our `user-data` and `meta-data` files will be located.
|
||||
|
||||
6. Create and add your custom autoinstall data files
|
||||
|
||||
```bash
|
||||
mkdir server
|
||||
cd server
|
||||
touch meta-data
|
||||
vim user-data
|
||||
```
|
||||
|
||||
Paste the `user-data.yaml` content into the `user-data` file.
|
||||
|
||||
7. Generate a new Ubuntu 22.04 server autoinstall ISO
|
||||
|
||||
The following command is helpful when trying to set up the arguments for building an ISO. It will give flags and data to closely reproduce the source base install ISO.
|
||||
|
||||
```bash
|
||||
cd ../..
|
||||
xorriso -indev ubuntu-22.04.5-live-server-amd64.iso -report_el_torito as_mkisofs
|
||||
```
|
||||
|
||||
Using the output of the above, we create the following command. Make sure to run this from the `source-files` directory.
|
||||
|
||||
```bash
|
||||
cd source-files
|
||||
xorriso -as mkisofs -r \
|
||||
-V 'Ubuntu-Server 22.04.5 LTS amd64' \
|
||||
-o ../ubuntu-22.04-autoinstall.iso \
|
||||
--grub2-mbr ../BOOT/1-Boot-NoEmul.img \
|
||||
-partition_offset 16 \
|
||||
--mbr-force-bootable \
|
||||
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b ../BOOT/2-Boot-NoEmul.img \
|
||||
-appended_part_as_gpt \
|
||||
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
|
||||
-c '/boot.catalog' \
|
||||
-b '/boot/grub/i386-pc/eltorito.img' \
|
||||
-no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
|
||||
-eltorito-alt-boot \
|
||||
-e '--interval:appended_partition_2_start_1040737s_size_10072d:all::' \
|
||||
-no-emul-boot \
|
||||
.
|
||||
```
|
||||
|
||||
If you want to verify the structure of the `user-data` file before running this or to troubleshoot later, the following can be helpful.
|
||||
|
||||
```bash
|
||||
cloud-init schema --config-file server/user-data
|
||||
```
|
||||
|
||||
Alternatively, you can also verify with:
|
||||
|
||||
```bash
|
||||
sudo apt install yamllint
|
||||
yamllint server/user-data
|
||||
```
|
||||
|
||||
Once the `xorriso` command is run successfully, the `ubuntu-22.04-autoinstall.iso` will be created in the `iso-build` directory.
|
42
user-data.yaml
Normal file
42
user-data.yaml
Normal file
@ -0,0 +1,42 @@
|
||||
#cloud-config
|
||||
---
|
||||
autoinstall:
|
||||
version: 1
|
||||
locale: en_US.UTF-8
|
||||
keyboard:
|
||||
layout: us
|
||||
identity:
|
||||
hostname: vm-template-staging
|
||||
username: moeny
|
||||
password: '$6$rounds=4096$saltsaltsaltsalt$hashedpasswordhere'
|
||||
ssh:
|
||||
install-server: true
|
||||
authorized-keys:
|
||||
# Add username or email to end of authorized-key below
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCRMJNdI/n/7xYN65zHFN8hlRSDg5OPJ12AwOsUyP8OmKCQTapoVQ/suvjaUTCtt8o28QNIQm1vAD03hFNzVJn6F6FJu9vUbR+YqlmzmzGJXB6sWWTEnc9/GsVvLoculuzFYfa2qU9xFbuUTtqFRu6qor82TPAhy/yVWzIvRxlfuxKLpdU9paKiV+WtCkSpVoBgIH6soBE1swMX4ILIOGeFTrmCdBac4K1Bs0OarKtShR6PHdNiqPlwpCeQQDZD8ops69yBMc0t6poFZC9FYSj7arJEWvZN9YtUr+PJiYZQc+gIG4enPW1Zf4FEkXXvH/t6RaYMq9w/P5lIUNOVe169
|
||||
allow-pw: false
|
||||
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
enp1s0:
|
||||
dhcp4: false
|
||||
addresses:
|
||||
- 100.40.223.190/24
|
||||
gateway4: 100.40.223.1
|
||||
nameservers:
|
||||
addresses:
|
||||
- 8.8.8.8
|
||||
- 8.8.4.4
|
||||
storage:
|
||||
layout:
|
||||
name: lvm
|
||||
packages:
|
||||
- vim
|
||||
- htop
|
||||
- net-tools
|
||||
user-data:
|
||||
disable_root: false
|
||||
|
||||
late-commands:
|
||||
- curtin in-target --target=/target apt-get update
|
Loading…
Reference in New Issue
Block a user