libvirt_cloud/roles/ansible-gentoo_install/tasks/disk.yml

145 lines
4.8 KiB
YAML
Raw Normal View History

2023-12-29 19:40:31 +00:00
# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
---
- name: "DEBUG: ansible-gentoo_install disk.yml"
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install disk.yml"
2023-12-30 22:09:49 +00:00
2023-12-29 19:40:31 +00:00
- name: test we are NOT in the chroot
shell: |
grep '/dev/{{AGI_NBD_DEV}}' /proc/mounts && exit 1
[ -n "{{AGI_NBD_MP}}" ] || exit 2
[ -d "{{AGI_NBD_MP}}" ] || exit 3
[ "{{ansible_distribution}}" == 'Gentoo' ] || \
2023-12-30 22:04:40 +00:00
( {{AGI_GENTOO_FROM_MP}} != '' && '{{AGI_GENTOO_FROM_MP}}' != '/' ) || \
2023-12-29 19:40:31 +00:00
exit 4
2023-12-30 22:09:49 +00:00
[ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
2023-12-29 19:40:31 +00:00
check_mode: false
2024-01-02 02:13:28 +00:00
- name: check for partitions
shell: |
grep '/dev/{{AGI_NBD_DEV}}p3' /proc/partitions && exit 0
exit 1
register: partitions_out
failed_when: false
2023-12-30 22:04:40 +00:00
- block:
2024-01-02 02:13:28 +00:00
# old code
2023-12-30 22:04:40 +00:00
- name: create disklabel
command: parted -s {{ AGI_install_disk }} mklabel {{ AGI_install_disklabel }}
register: disklabel_out
# stderr: 'Warning: Error fsyncing/closing /dev/nbd1: Input/output error'
failed_when: false
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: disklabel_out
debug:
var: disklabel_out
# you can get into a wierd state with /dev/nbd - partprobe reports
# Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64 on /dev/nbd3 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
2023-12-30 22:09:49 +00:00
# and the same thing on all of the rest of your disks! All untrue
# but the qemu -d /dev/nbd1 command will fail silently if busy
when: disklabel_out.rc != 0
2023-12-30 22:04:40 +00:00
- name: This is fatal - you must reboot
fail:
msg: "This is fatal - you must reboot. {{disklabel_out.stderr}}"
when:
- disklabel_out.rc == 1
check_mode: no
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
# We need to leave a small gap at the beginning of the disk, or grub won't be
# able to install to the MBR
- name: create boot partition
shell: |
2024-01-02 02:13:28 +00:00
parted -s {{ AGI_install_disk }} mkpart primary {{'ext2' if AGI_install_bootloader != 'syslinux' else 'fat32'}} 1M 200M
2023-12-30 22:04:40 +00:00
args:
creates: "{{ AGI_install_disk }}p1"
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: mark boot partition as active
shell: |
parted -s {{ AGI_install_disk }} set 1 boot on
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: create swap partition
shell: |
parted -s {{ AGI_install_disk }} -- mkpart primary linux-swap 201M 2200M
args:
creates: "{{ AGI_install_disk }}p2"
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: create root partition
shell: |
parted -s {{ AGI_install_disk }} -- mkpart primary ext4 2201M 20070M
args:
creates: "{{ AGI_install_disk }}p3"
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: format boot partition
2024-01-02 02:13:28 +00:00
filesystem: dev={{ AGI_install_disk }}p1 fstype={{'ext2' if AGI_install_bootloader != 'syslinux' else 'vfat'}} force=yes
2023-12-30 22:04:40 +00:00
check_mode: false
when: not ansible_check_mode
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: format swap partition
filesystem: dev={{ AGI_install_disk }}p2 fstype=swap force=yes
check_mode: false
when: false
2023-12-30 22:09:49 +00:00
2023-12-30 22:04:40 +00:00
- name: format root partition
filesystem: dev={{ AGI_install_disk }}p3 fstype=ext4 force=yes
check_mode: false
when: not ansible_check_mode
2023-12-30 22:09:49 +00:00
2023-12-31 07:39:01 +00:00
- name: label partitions
shell: |
partprobe
e2label {{ AGI_install_disk }}p3 root
e2label {{ AGI_install_disk }}p1 boot
mkswap -L swap "{{ AGI_install_disk }}p2"
2024-01-02 02:13:28 +00:00
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'
2023-12-31 07:39:01 +00:00
2023-12-29 19:40:31 +00:00
when: false
2023-12-30 22:04:40 +00:00
- block:
2023-12-30 22:09:49 +00:00
- name: create disk partitions
shell: |
sfdisk {{ AGI_install_disk }} << EOF
label: dos
label-id: 0x14a8b958
device: {{ AGI_install_disk }}
unit: sectors
sector-size: 512
2024-01-02 02:13:28 +00:00
{{ AGI_install_disk }}p1 : start= 2048, size= 819200, type={{'83' if AGI_install_bootloader != 'syslinux' else 'c'}}, bootable
2023-12-30 22:09:49 +00:00
{{ AGI_install_disk }}p2 : start= 821248, size= 4096000, type=82
{{ AGI_install_disk }}p3 : start= 4917248, size= 37025792, type=83
EOF
2023-12-31 07:39:01 +00:00
partprobe
2024-01-02 02:13:28 +00:00
- name: format disk partitions grub:2
shell: |
2023-12-31 07:39:01 +00:00
mke2fs -L boot {{ AGI_install_disk }}p1
mke2fs -L root {{ AGI_install_disk }}p3
mkswap -L swap "{{ AGI_install_disk }}p2"
2024-01-02 02:13:28 +00:00
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
2023-12-30 22:09:49 +00:00