Skip to content

Commit b679d4a

Browse files
committed
initial commit
1 parent 9e89887 commit b679d4a

10 files changed

+842
-0
lines changed
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
#
3+
# download latest x86 & amd64 stage3 image
4+
5+
6+
pause() {
7+
local Answer=""
8+
echo "Pause."
9+
echo -n "Enter to continue: "
10+
read Answer
11+
}
12+
13+
14+
download_variant() {
15+
local Arch=$1
16+
local Variant=$2
17+
18+
case $Arch in
19+
x86) FArch=i686;;
20+
*) FArch=$Arch;;
21+
esac
22+
23+
#FILE_amd64=$(curl -L https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt | sed '/^#/d' | cut -f1 -d" " )
24+
#FILE_amd64_musl=$(curl -L https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt | sed '/^#/d' | cut -f1 -d" " )
25+
#FILE_x86=$(curl -L https://bouncer.gentoo.org/fetch/root/all/releases/x86/autobuilds/latest-stage3-i686-systemd.txt | sed '/^#/d' | cut -f1 -d" " )
26+
#echo "x86: https://bouncer.gentoo.org/fetch/root/all/releases/x86/autobuilds/$FILE_x86"
27+
#echo "amd64: https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/$FILE_amd64"
28+
#echo "amd64-musl: https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/$FILE_amd64_musl"
29+
30+
FILE=$(curl -L https://bouncer.gentoo.org/fetch/root/all/releases/$Arch/autobuilds/latest-stage3-$FArch-$Variant.txt | sed '/^#/d' | cut -f1 -d" " )
31+
FILEPATH="https://bouncer.gentoo.org/fetch/root/all/releases/$Arch/autobuilds/$FILE"
32+
33+
echo "Download URL: $FILEPATH"
34+
pause
35+
curl -LO -C - "$FILEPATH" && echo "Download successful."
36+
echo
37+
}
38+
39+
40+
echo "download latest gentoo stage3 images"
41+
echo "===================================="
42+
echo " optional parameters: <architecure> <variant>"
43+
echo " example combinations:"
44+
echo " $0 amd64 systemd"
45+
echo " $0 amd64 openrc"
46+
echo " $0 amd64 musl"
47+
echo " $0 x86 systemd"
48+
echo
49+
echo " $0 all"
50+
51+
if [ -z "$1" ]; then
52+
exit
53+
fi
54+
55+
if [ "$1" = "all" ]
56+
then
57+
download_variant amd64 systemd
58+
download_variant amd64 musl
59+
download_variant x86 systemd
60+
else
61+
download_variant "$1" "$2"
62+
fi
63+

20-prepare-vm-from-stage3.sh

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
#
3+
# create virtual machine image from stage3 image
4+
5+
pause() {
6+
local Answer=""
7+
echo "Pause."
8+
echo -n "Enter to continue: "
9+
read Answer
10+
}
11+
12+
13+
# read parameters
14+
15+
if [ -n "$1" ]; then
16+
STAGE3="$1"
17+
else
18+
STAGE3="stage3-amd64-systemd-20201206T214503Z.tar.xz"
19+
echo "default image: $STAGE3"
20+
fi
21+
STAGE3=$(readlink --canonicalize $STAGE3)
22+
if [ ! -e "$STAGE3" ]; then
23+
echo "Stage3 image $STAGE3 does not exist. exit."
24+
fi
25+
26+
set -x -v -e
27+
28+
# VM_NAME=pkg-tester
29+
DISK_NAME="${STAGE3%.tar.*}.qcow2"
30+
DISK_SIZE=20G
31+
echo "VM Disk Name: $DISK_NAME"
32+
33+
34+
if [ -e $DISK_NAME ]; then
35+
set +x +v +e
36+
echo
37+
echo
38+
echo "Disk $DISK_NAME exists, exit"
39+
exit 1
40+
fi
41+
42+
cd $(dirname $0)
43+
44+
qemu-img create -f qcow2 "$DISK_NAME" "$DISK_SIZE"
45+
46+
47+
48+
49+
#
50+
#
51+
# How to mount a qcow2 disk image
52+
#
53+
#This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.
54+
#
55+
# Step 1 - Enable NBD on the Host
56+
#
57+
# modprobe nbd max_part=8
58+
#
59+
# Step 2 - Connect the QCOW2 as network block device
60+
#
61+
# qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2
62+
#
63+
# Step 3 - Find The Virtual Machine Partitions
64+
#
65+
# fdisk /dev/nbd0 -l
66+
#
67+
# Step 4 - Mount the partition from the VM
68+
#
69+
# mount /dev/nbd0p1 /mnt/somepoint/
70+
#
71+
# Step 5 - After you done, unmount and disconnect
72+
#
73+
# umount /mnt/somepoint/
74+
# qemu-nbd --disconnect /dev/nbd0
75+
# rmmod nbd
76+
77+
LANG=C
78+
79+
# trap on exit or STRG-C
80+
trap 'set +e; umount /mnt/new/dev/ /mnt/new/sys/ /mnt/new/proc/; umount /mnt/new/; qemu-nbd --disconnect /dev/nbd0; rmmod nbd' EXIT TERM INT
81+
82+
modprobe nbd max_part=8
83+
sleep 1
84+
85+
qemu-nbd --connect=/dev/nbd0 "$DISK_NAME"
86+
sleep 1
87+
88+
fdisk /dev/nbd0 -l
89+
parted --script --align optimal /dev/nbd0 mklabel msdos -- mkpart primary xfs 1 -0
90+
mkfs.xfs -L pktester /dev/nbd0p1
91+
92+
93+
mount /dev/nbd0p1 /mnt/new/
94+
95+
pause
96+
97+
pushd /mnt/new/
98+
#tar xvf "$STAGE3"
99+
# root #tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
100+
tar xpvf "$STAGE3" --xattrs-include='*.*' --numeric-owner
101+
102+
rsync -a --progress /usr/portage/ var/db/repos/gentoo
103+
mount -o bind /dev/ /mnt/new/dev/
104+
mount -o bind /sys/ /mnt/new/sys/
105+
mount -o bind /proc/ /mnt/new/proc/
106+
107+
cp /etc/locale.gen /mnt/new/etc/locale.gen
108+
cp /etc/resolv.conf /mnt/new/etc/resolv.conf
109+
cp /root/.aliases /mnt/new/root/.aliases
110+
111+
popd
112+
113+
cp ??-inside-*-prepare-vm-from-stage3.sh /mnt/new/
114+
set +x +v +e
115+
116+
echo "do CHROOT, your next step is: run the script /30-inside-chroot-prepare-vm-from-stage3.sh now!"
117+
chroot /mnt/new/
118+
119+
echo
120+
echo "VM disk image file: $DISK_NAME"
121+
122+
# on exit, "trap" umounts all etc.
123+
+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/bin/bash
2+
#
3+
# create virtual machine from stage3 image
4+
# this must be run inside chroot
5+
6+
# chroot /mnt/new/
7+
8+
LANG=C
9+
10+
# check if we are really inside the chrooted system
11+
if [ -e /30-inside-chroot-prepare-vm-from-stage3.sh ]; then
12+
echo "inside chroot, start working"
13+
else
14+
echo "not inside chroot, exit"
15+
exit 1
16+
fi
17+
18+
# necessary base settings
19+
locale-gen
20+
eselect locale set de_DE.utf8
21+
. /etc/profile
22+
23+
# set a root password
24+
echo "root:root123.." | chpasswd
25+
26+
# determine which ARCH we have here
27+
ARCH=$(eselect profile list | head -n 2 | awk --field-separator "/" '/default/ { print $3; }')
28+
29+
# set Use-Flags for minimum features for grub / nfs-utils
30+
cat >>/etc/portage/package.use/zzz_common <<EOF
31+
sys-boot/grub -grub_platforms_efi-64 -fonts -nls -themes
32+
net-fs/nfs-utils -libmount -nfsidmap -nfsv4 -tcpd -uuid
33+
net-nds/rpcbind -tcpd
34+
35+
EOF
36+
37+
# add settings to make.conf
38+
cat >>/etc/portage/make.conf <<'EOF'
39+
40+
## MD: added lines start here
41+
42+
EMERGE_DEFAULT_OPTS="--keep-going --ask-enter-invalid --quiet-build=y --verbose-conflicts --jobs=3"
43+
# build binary packages
44+
45+
#FEATURES="${FEATURES} buildpkg"
46+
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --buildpkg --buildpkg-exclude 'sys-kernel/gentoo-sources virtual/* acct-group/* acct-user/* */*-bin'"
47+
48+
ACCEPT_LICENSE="* -@EULA"
49+
MAKEOPTS="-j2"
50+
51+
VDR_MAINTAINER_MODE="1"
52+
PORTAGE_ELOG_CLASSES="warn error info log qa"
53+
54+
# xorg
55+
VIDEO_CARDS="vesa qxl"
56+
INPUT_DEVICES="libinput synaptics"
57+
58+
PORTDIR_OVERLAY="
59+
/var/db/repos/md-private/
60+
$PORTDIR_OVERLAY
61+
"
62+
63+
64+
EOF
65+
66+
# populate fstab
67+
cat >>/etc/fstab <<EOF
68+
LABEL=pktester / xfs noatime 0 1
69+
70+
192.168.122.1:/data/virt/package-tester/work /root/work nfs defaults 0 0
71+
192.168.122.1:/data/virt/package-tester/distfiles /var/cache/distfiles nfs defaults 0 0
72+
192.168.122.1:/data/virt/package-tester/binpkgs-$ARCH /var/cache/binpkgs nfs defaults 0 0
73+
192.168.122.1:/var/lib/layman/md-private /var/db/repos/md-private nfs defaults 0 0
74+
EOF
75+
76+
# create mountpoints
77+
mkdir -p /var/db/repos/md-private /root/work
78+
79+
# install sys-kernel/gentoo-kernel-bin
80+
emerge -av sys-kernel/gentoo-kernel-bin sys-boot/grub net-fs/nfs-utils
81+
# grub-install --target=i386-pc --boot-directory=./boot/ /dev/nbd0
82+
grub-install --target=i386-pc /dev/nbd0
83+
grub-mkconfig -o /boot/grub/grub.cfg
84+
85+
86+
# cleanup distfiles, nfs share is later mounted on top of this
87+
find /var/cache/distfiles/ -type f -delete
88+
89+
# configure network
90+
systemctl enable systemd-networkd
91+
systemctl enable sshd
92+
echo "PermitRootLogin yes" >>/etc/ssh/sshd_config
93+
94+
cat >/etc/systemd/network/10-enp1s0.network <<EOF
95+
[Match]
96+
Name=enp1s0
97+
98+
[Network]
99+
DHCP=yes
100+
EOF
101+
102+
# set unstable keywords for packages I work with, ~amd64
103+
cat >/etc/portage/package.accept_keywords <<EOF
104+
dev-embedded/esptool ~amd64
105+
media-tv/oscam ~amd64
106+
sys-fs/btrfsmaintenance ~amd64
107+
dev-python/reedsolomon ~amd64
108+
app-admin/passwordsafe ~amd64
109+
net-im/signal-cli-bin ~amd64
110+
111+
media-video/vdr ~amd64
112+
media-tv/gentoo-vdr-scripts ~amd64
113+
sys-process/wait_on_pid ~amd64
114+
115+
app-eselect/eselect-vdr ~amd64
116+
media-fonts/vdrsymbols-ttf ~amd64
117+
media-plugins/vdr-* ~amd64
118+
media-plugins/xbmc-addon-pvr ~amd64
119+
www-misc/vdradmin-am ~amd64
120+
x11-themes/vdr-channel-logos ~amd64
121+
virtual/linuxtv-dvb-headers ~amd64
122+
123+
media-video/naludump ~amd64
124+
media-video/noad ~amd64
125+
sys-firmware/tt-s2-6400-firmware ~amd64
126+
media-tv/v4l-dvb-saa716x ~amd64
127+
EOF
128+
129+
# npw adjust ARCH in case it is not ~amd64
130+
if [ "$ARCH" != "amd64" ]
131+
then
132+
sed -i "s/amd64/$ARCH/" /etc/portage/package.accept_keywords
133+
fi
134+
135+
# some settings for the bash
136+
cat >/etc/profile.d/history.sh <<EOF
137+
HISTSIZE=2500
138+
HISTCONTROL="ignoreboth"
139+
#HISTCONTROL="ignoredups"
140+
#HISTIGNORE='fg:bg:exit:history:[ \t]*'
141+
HISTTIMEFORMAT='%F %H:%M:%S '
142+
EOF
143+
144+
cat >/etc/profile.d/load-aliases.sh <<EOF
145+
if [ -r ~/.aliases ]
146+
then
147+
alias sa='alias>~/.aliases'
148+
source ~/.aliases
149+
fi
150+
EOF
151+
152+
set +x +v
153+
154+
echo
155+
echo
156+
echo "now leave CHROOT,"
157+
echo "boot virtual machine, then after first login execute"
158+
echo " /40-inside-running-vm-prepare-vm-from-stage3.sh"
159+
echo
160+
echo "Note: on the first boot, the VM does not configure the network."
161+
echo "Don't panic, this will work after running the script above."
162+
163+
#exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
#
3+
# create virtual machine from stage3 image
4+
# this must be run inside running VM with systemd
5+
6+
LANG=C
7+
8+
# check if we are really inside the virtual server
9+
if [ -e /40-inside-running-vm-prepare-vm-from-stage3.sh ]; then
10+
if lscpu | grep -e "BIOS Vendor.*QEMU" -q
11+
then
12+
echo "inside virtual machine, start working"
13+
else
14+
echo "not inside virtual machine, exit"
15+
exit 1
16+
fi
17+
else
18+
echo "not inside chroot/vm, exit"
19+
exit 1
20+
fi
21+
22+
set -e -x -v
23+
24+
ARCH=$(eselect profile list | head -n 2 | awk --field-separator "/" '/default/ { print $3; }')
25+
26+
# configure hostname
27+
hostnamectl set-hostname "pkgtester-$ARCH"
28+
29+
# configure keyboard layout
30+
localectl set-keymap de-latin1-nodeadkeys
31+
32+
# configure timezone
33+
timedatectl set-timezone Europe/Berlin
34+
35+
# create machine id, VERY important for networking
36+
systemd-machine-id-setup
37+

0 commit comments

Comments
 (0)