how to create a VM
This commit is contained in:
parent
6f368b37e8
commit
ba0643504c
37
content/bootstrap_alpine.rst
Normal file
37
content/bootstrap_alpine.rst
Normal file
@ -0,0 +1,37 @@
|
||||
1 - boot a VM with the last alpine linux iso and a hard disk
|
||||
2 - setup network interface (setup-interfaces, then ifup eth0)
|
||||
3 - setup dns (add gateway / any DNS to /etc/resolv.conf)
|
||||
4 - apk add e2fsprogs
|
||||
5 - mkfs.ext4 /dev/vda
|
||||
6 - mount -t ext4 /dev/vda /mnt
|
||||
7 - /sbin/apk --arch x86_64 -X http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/ -U --allow-untrusted --root /mnt --initdb add alpine-base agetty # replace latest-stable by the wanted version
|
||||
8 - echo "UUID=`blkid -s UUID -o value /dev/vda` / ext4 defaults,errors=remount-ro,discard,noatime 0 1" > /mnt/etc/fstab
|
||||
9 - (optional) tty1::respawn:/sbin/agetty --autologin root tty1 linux # replace tty line from /etc/inittab with this line to have autologin - no need to set root password. you can remove other ttys
|
||||
10 - cp /etc/network/interfaces /mnt/etc/network/interfaces
|
||||
11 - cp /etc/resolv.conf /mnt/etc/resolv.conf
|
||||
12 - vi /mnt/etc/hostname # setup hostname
|
||||
13 - cp /etc/apk/repositories /mnt/etc/apk/repositories # setup alpine repos (edit to set alpine version), enable community
|
||||
14 - for a in proc sys dev; do mount -o bind /$a /mnt/$a; done; chroot /mnt /bin/ash # chroot into target
|
||||
15 - apk update
|
||||
16 - apk add linux-virt linux-firmware-none acpi mkinitfs vim screen qemu-guest-agent
|
||||
17 - enable services
|
||||
rc-update add seedrng boot
|
||||
rc-update add swap boot
|
||||
rc-update add networking boot
|
||||
rc-update add modules boot
|
||||
rc-update add hostname boot
|
||||
rc-update add hwclock boot
|
||||
rc-update add bootmisc boot
|
||||
rc-update add acpid default
|
||||
rc-update add crond default
|
||||
rc-update add qemu-guest-agent default
|
||||
rc-update add devfs sysinit
|
||||
rc-update add dmesg sysinit
|
||||
rc-update add mdev sysinit
|
||||
rc-update add hwdrivers sysinit
|
||||
rc-update add killprocs shutdown
|
||||
rc-update add mount-ro shutdown
|
||||
rc-update add savecache shutdown
|
||||
18 - shutdown VM (force)
|
||||
19 - setup kernel
|
||||
|
||||
121
content/vm_creation
Normal file
121
content/vm_creation
Normal file
@ -0,0 +1,121 @@
|
||||
# choose a name ($NEW_VM)
|
||||
# choose a volume size ($SIZE)
|
||||
virsh vol-create-as vg0 rootfs-$NEW_VM $SIZE --format logical
|
||||
virsh define $NEW_VM
|
||||
virsh edit $NEW_VM
|
||||
# add hard disk as "vda" and set volume to boot on (vg0/rootfs-$NEW_VM)
|
||||
# add cdrom as "hda" and set volume to the distro iso (use "virt" version)
|
||||
# copy the mac address of the network card ($MAC)
|
||||
# choose an ip ($IP)
|
||||
~/libvirt/scripts/net-add_static_lease new_vm $MAC $IP
|
||||
virsh start $NEW_VM
|
||||
virsh domdisplay $NEW_VM
|
||||
# check the port the vnc display is switched on ($PORT)
|
||||
virsh domdisplay $NEW_VM | cut -d: -f3
|
||||
# on the local machine, create a ssh tunnel:
|
||||
ssh root@freepoteries.fr -L 5900:127.0.0.1:59$PORT
|
||||
# out of the newly created ssh session (keep it open for log messages)
|
||||
vncviewer 127.0.0.1:5900
|
||||
# login into your newly booted os
|
||||
# all the following instructions are done into the VM, by the VNC client
|
||||
# (vncviewer)
|
||||
|
||||
# instructions for alpine linux :
|
||||
# choose your keymap $KM (fr)
|
||||
setup-keymap $KM
|
||||
# choose your hostname
|
||||
setup-hostname
|
||||
# answer your system hostname (that will also be its subdomain)
|
||||
# choose your timezone $TZ (Europe/Paris)
|
||||
setup-timezone -z $TZ
|
||||
# setup interfaces (answer "eth0" and "dhcp")
|
||||
setup-interfaces
|
||||
/etc/init.d/networking restart
|
||||
# choose your ssh server (openssh)
|
||||
setup-sshd
|
||||
# choose your ntp server (chrony)
|
||||
setup-ntp
|
||||
# choose your repo (36 : alpine.42.fr)
|
||||
setup-apkrepos
|
||||
# setup the dns
|
||||
setup-dns
|
||||
# answer 1 : freepoteries.fr
|
||||
# answer 2 : 192.168.42.11
|
||||
# test by pinging freepoteries.fr and belugaspot.freepoteries.fr (always up),
|
||||
# they should give "192.168.42.1" and "192.168.42.55"
|
||||
# setup mail server
|
||||
setup-mta
|
||||
# answer: mail.freepoteries.fr
|
||||
# install syslinux and e2fsprogs if not installed
|
||||
apk add syslinux e2fsprogs xfsprogs
|
||||
# create your disks
|
||||
fdisk /dev/vda
|
||||
# create a partition that takes the whole hard disk
|
||||
# make it bootable "a"
|
||||
# save your changes "w"
|
||||
# format it to the right fs
|
||||
mkfs.xfs /dev/vda1
|
||||
# fix the mbr
|
||||
dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/vda
|
||||
# mount the partition
|
||||
mount /dev/vda1 /mnt
|
||||
mkdir /mnt/boot
|
||||
# install the system on the created partition
|
||||
setup-disk -m sys /mnt
|
||||
mount -o bind /dev /mnt/dev
|
||||
mount -o bind /proc /mnt/proc
|
||||
chroot /mnt
|
||||
# install the bootloader
|
||||
extlinux -i /boot
|
||||
update-extlinux
|
||||
# change password (toor)
|
||||
passwd
|
||||
|
||||
exit
|
||||
poweroff
|
||||
|
||||
# in the first ssh session
|
||||
virsh edit $NEW_VM
|
||||
# set the boot dev to "hd" - ~/libvirt/scripts/switch_boot_device.sh $NEW_VM
|
||||
virsh destroy $NEW_VM
|
||||
virsh start $NEW_VM
|
||||
|
||||
# ssh
|
||||
vim /etc/ssh/sshd_config
|
||||
# set "PermitRootLogin yes"
|
||||
rc-service sshd restart
|
||||
mkdir ~/.ssh
|
||||
|
||||
# on the host:
|
||||
scp ~/.ssh/authorized_keys new_host.freepoteries.fr:~/.ssh/
|
||||
|
||||
# on the vm
|
||||
vim /etc/ssh/sshd_config
|
||||
# set "PermitRootLogin without-password"
|
||||
rc-service sshd restart
|
||||
|
||||
# on the host
|
||||
eval $(ssh-agent)
|
||||
ssh-add ~/.ssh/*
|
||||
ssh root@new_host.freepoteries.fr (should not ask password)
|
||||
|
||||
# add zone on unbound
|
||||
# add proxy on revproxy
|
||||
|
||||
# packages :
|
||||
screen
|
||||
vim
|
||||
git
|
||||
nginx
|
||||
php7-fpm
|
||||
ruby
|
||||
python3
|
||||
|
||||
# var/www :
|
||||
garradin
|
||||
|
||||
# etc/nginx/conf.d :
|
||||
garradin.conf
|
||||
|
||||
# follow these instructions
|
||||
https://wiki.alpinelinux.org/wiki/Nginx_with_PHP#PHP7_Installation
|
||||
Loading…
Reference in New Issue
Block a user