This commit is contained in:
emdee 2024-01-02 02:13:28 +00:00
parent c417a6f3f9
commit 33a439173c
17 changed files with 1298 additions and 95 deletions

View file

@ -7,35 +7,107 @@
- name: test we are in the chroot
shell: |
df | grep {{AGI_NBD_MP}} && exit 1
df | grep {{AGI_install_disk}} && exit 1
check_mode: false
- name: install grub
- name: install grub or syslinx
portage:
package: sys-boot/grub:2
package: sys-boot/{{AGI_install_bootloader}}
state: installed
- name: install grub to MBR
command: grub-install {{ AGI_install_disk }}
args:
creates: /boot/grub
- block:
- name: generate grub config
shell: grub-mkconfig -o /boot/grub/grub.cfg
args:
creates: /boot/grub/grub.cfg
- name: setup syslinux
shell: |
[ -d /boot/syslinux ] || mkdir /boot/syslinux
[ -f /boot/syslinux/syslinux.cfg ] || \
cat > /boot/syslinux/syslinux.cfg << EOF
# -*-mode: sh; tab-width: 8; coding: utf-8-dos -*-
default vesamenu.c32
prompt 0
# timeout 150
menu title nbd2
menu background splash.png
menu color title 1;36;44 #c0ffffff #00000000 std
menu color sel 7;37;40 #e0000000 #20ECEAC7 all
menu rows 15
menu tabmsgrow 21
menu timeoutrow 23
menu helpmsgrow 23
# drm.debug=0xe
# rd.shell rd.debug
label pentoo2019-Pen19-6.1.52-pentoo_2023_09_30_0x037f
menu label pentoo2019_Pen19_6.1.52-pentoo_2023_09_30_0x037f
menu default
kernel vmlinuz-6.1.52-pentoo_2023_09_30
INITRD initramfs-pentoo-x86_64-6.1.52-pentoo_2023_09_30.img
# was vga=0x315
APPEND root=LABEL=root {{''.join(AGI_install_syslinux_kernel_commands)}}
label MAIN hd0 MBR
menu label MAIN hd0 0
com32 chain.c32
APPEND hd0
EOF
[ ! -d /usr/share/syslinux/ ] || \
for elt in {{' '.join(AGI_install_syslinux_c32)}}; do
[ -f /boot/syslinux/$elt ] && continue
cp -np /usr/share/syslinux/$elt /boot/syslinux
done
exit 0
- name: edit grub config
shell: |
[ -f /etc/default/grub.dst ] || cp -p /etc/default/grub /etc/default/grub.dst
a=$(cat /proc/cmdline | sed -e 's/ BOOT_IMAGE=[^ ]*/ /' \
-e 's/ initrd=[^ ]*/ /'
-e 's/ resume=[^ ]*/ /'
-e 's/ root=[^ ]*/ /')
sed -e "s/^#*GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"$a\"/" \
-i /etc/default/grub
grub-script-check /etc/default/grub
- name: do syslinux install manually
shell: |
df | grep {{AGI_install_disk}} && \
echo ERROR: somethings wrong - {{AGI_install_disk}} isnt mounted
&& exit 1
# should unmount it?
dd if={{AGI_install_disk}}p1 count=440 bs=1|strings|grep SYSLINUX
[ $? -eq 0 ] && exit 0
echo HALT: YOU MUST INSTALL THE MBR YOURSELF - do this
echo dd if=/usr/share/syslinux/mbr.bin of={{AGI_install_disk}}p1 count=440 bs=1 conv=notrunc
echo HALT: YOU MUST INSTALL SYSLINUX YOURSELF - do this
syslinux -d syslinux --install {{AGI_install_disk}}p1
exit 999
register: syslinux_out
failed_when: false
- name: install syslinux install manually
fail:
msg: "HALT: install syslinux install manually"
when: syslinux_out.rc != 0
when: AGI_install_bootloader == 'syslinux'
- block:
- name: install grub to MBR
command: grub-install {{ AGI_install_disk }}
args:
creates: /boot/grub
- name: generate grub config
shell: grub-mkconfig -o /boot/grub/grub.cfg
args:
creates: /boot/grub/grub.cfg
- name: edit grub config
shell: |
[ -f /etc/default/grub.dst ] || cp -p /etc/default/grub /etc/default/grub.dst
a=$(cat /proc/cmdline | sed -e 's/ BOOT_IMAGE=[^ ]*/ /' \
-e 's/ initrd=[^ ]*/ /'
-e 's/ resume=[^ ]*/ /'
-e 's/ root=[^ ]*/ /')
sed -e "s/^#*GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"$a\"/" \
-i /etc/default/grub
grub-script-check /etc/default/grub
when: AGI_install_bootloader == 'grub:2'
- name: fstab root
lineinfile:
dest: /etc/fstab
@ -80,6 +152,27 @@
line: 'consolefont="ter-v{{AGI_consolefont_font_size}}b"'
regexp: '^consolefont=.*'
- name: /etc/default/grub
lineinfile:
dest: /etc/default/grub
line: '{{item.from}}="{{item.to}}"'
regexp: '^#*{{item.from}}=.*'
with_items:
# Append parameters to the linux kernel command line for non-recovery entries
- from: GRUB_CMDLINE_LINUX_DEFAULT
to: " rd.skipfsck=1 ipv6.disable=1 console=tty1 lang=en keymap=us intel_iommu=on vga=0x315 text"
# The resolution used on graphical terminal.
# Note that you can use only modes which your graphic card supports via VBE.
# You can see them in real GRUB with the command `vbeinfo'.
- from: GRUB_GFXMODE
to: 640x480
# Set to 'text' to force the Linux kernel to boot in normal text
- from: GRUB_GFXPAYLOAD_LINUX
to: text
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to kernel
- from: GRUB_DISABLE_LINUX_UUID
to: true
- name: roles/ansible-gentoo_install/tasks/
shell: |
LINE="rd.skipfsck=1 ipv6.disable=1 console=tty1 lang=en keymap=us "
@ -88,11 +181,13 @@
df | grep /boot || mount /dev/vda1 /boot
[ -d /boot/grub ] || exit 2
[ -f /boot/grub/grub.cfg ] || exit 3
sed -e "s@ ro *$@ $LINE ro@" -i /boot/grub/grub.cfg
cd /
# ln -s boot/vmlinuz* vmlinuz
# boot/initramfs-pentoo-x86_64-6.1.52-pentoo_2023_09_30.img
ln -s boot/initramfs* initrd.img
- name: consolefont
shell: |
rc-update add consolefont
cat >> /etc/rc.local << EOF
/etc/init.d consolefont stop
/etc/init.d consolefont start
@ -103,6 +198,7 @@
- name: rc-update add bootlogd boot
shell: |
rc-update add consolefont
rc-update | grep -q 'bootlogd .* boot' || \
rc-update add bootlogd boot
exit 0

View file

@ -16,8 +16,16 @@
[ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
check_mode: false
- name: check for partitions
shell: |
grep '/dev/{{AGI_NBD_DEV}}p3' /proc/partitions && exit 0
exit 1
register: partitions_out
failed_when: false
- block:
# old code
- name: create disklabel
command: parted -s {{ AGI_install_disk }} mklabel {{ AGI_install_disklabel }}
register: disklabel_out
@ -44,7 +52,7 @@
# able to install to the MBR
- name: create boot partition
shell: |
parted -s {{ AGI_install_disk }} mkpart primary ext2 1M 200M
parted -s {{ AGI_install_disk }} mkpart primary {{'ext2' if AGI_install_bootloader != 'syslinux' else 'fat32'}} 1M 200M
args:
creates: "{{ AGI_install_disk }}p1"
@ -65,7 +73,7 @@
creates: "{{ AGI_install_disk }}p3"
- name: format boot partition
filesystem: dev={{ AGI_install_disk }}p1 fstype=ext2 force=yes
filesystem: dev={{ AGI_install_disk }}p1 fstype={{'ext2' if AGI_install_bootloader != 'syslinux' else 'vfat'}} force=yes
check_mode: false
when: not ansible_check_mode
@ -85,7 +93,15 @@
e2label {{ AGI_install_disk }}p3 root
e2label {{ AGI_install_disk }}p1 boot
mkswap -L swap "{{ AGI_install_disk }}p2"
sync
when: AGI_install_bootloader != 'syslinux'
- name: label partitions syslinux
shell: |
partprobe
fatlabel {{ AGI_install_disk }}p3 root
e2label {{ AGI_install_disk }}p1 boot
mkswap -L swap "{{ AGI_install_disk }}p2"
when: AGI_install_bootloader == 'syslinux'
when: false
@ -100,15 +116,29 @@
unit: sectors
sector-size: 512
{{ AGI_install_disk }}p1 : start= 2048, size= 819200, type=83, bootable
{{ AGI_install_disk }}p1 : start= 2048, size= 819200, type={{'83' if AGI_install_bootloader != 'syslinux' else 'c'}}, bootable
{{ AGI_install_disk }}p2 : start= 821248, size= 4096000, type=82
{{ AGI_install_disk }}p3 : start= 4917248, size= 37025792, type=83
EOF
partprobe
- name: format disk partitions grub:2
shell: |
mke2fs -L boot {{ AGI_install_disk }}p1
mke2fs -L root {{ AGI_install_disk }}p3
mkswap -L swap "{{ AGI_install_disk }}p2"
sync
when: true
when: AGI_install_bootloader != 'syslinux'
- name: format disk partitions syslinux
shell: |
mkfs.vfat -F 32 -n boot {{ AGI_install_disk }}p1
mke2fs -L root {{ AGI_install_disk }}p3
mkswap -L swap "{{ AGI_install_disk }}p2"
when: AGI_install_bootloader == 'syslinux'
when:
- partitions_out.rc != 0

View file

@ -143,7 +143,7 @@
check_mode: false
when:
- "ansible_connection in ['chroot'] or (ansible_connection in ['local'] or and chroot_out.rc|default(1) == 0)"
- "ansible_connection in ['chroot'] or (ansible_connection in ['local'] and chroot_out.rc|default(1) == 0)"
rescue:
- debug:
msg: "ERROR: error during chroot execution"

View file

@ -113,7 +113,8 @@
action: status
loglevel: "{{BOX_NBD_LOGLEVEL}}"
threads: 1
config: "{{AGI_GENTOOIMGR_CONFIGFILE}}" # base.json - bare filename in configs
# base.json - bare filename in configs
config: "{{AGI_GENTOOIMGR_CONFIGFILE}}"
profile: "{{BOX_NBD_BASE_PROFILE}}"
kernel_dir: "{{BOX_NBD_KERNEL_DIR}}"
portage: "{{BOX_NBD_PORTAGE_FILE}}"

View file

@ -86,6 +86,13 @@
user:
name: gentoo
password: "{{ gentoo_password_out.stdout }}"
group: "{{ BOX_USER_GROUP }}"
append: true
groups: ['{{ BOX_ALSO_GROUP }}', 'wheel']
create_home: yes
shell: /bin/bash
#? usermod: user vagrant is currently used by process 2190
ignore_errors: true
- name: configure sudoers
lineinfile:
@ -96,6 +103,13 @@
owner: root
mode: '0640'
- name: make symlinks
shell: |
[ -e /var/db/repos/gentoo ] || \
ln -s /usr/portage /var/db/repos/gentoo
grep -q ^tmpfs /etc/fstab || \
echo >> /etc/fstab 'tmpfs /dev/shm tmpfs defaults,noexec,size=5% 0 0'
- block:
- name: make symlinks

View file

@ -5,11 +5,6 @@
verbosity: 1
msg: "DEBUG: ansible-gentoo_install portage ansible_shell_executable={{ansible_shell_executable}}"
- name: reenable chroot wrapper
set_fact:
ansible_shell_executable: /var/tmp/chroot_wrapper.sh
ansible_python_interpreter: "/usr/bin/python3"
- name: test we are in the chroot
shell: |
df | grep /mnt/gentoo && exit 1