{"id":2325,"date":"2023-05-29T15:50:46","date_gmt":"2023-05-29T14:50:46","guid":{"rendered":"https:\/\/cdblog.cdstealer.com\/?p=2325"},"modified":"2025-01-03T07:28:06","modified_gmt":"2025-01-03T07:28:06","slug":"gentoo-install-via-ansible","status":"publish","type":"post","link":"https:\/\/cdblog.cdstealer.com\/?p=2325","title":{"rendered":"Gentoo Install with LVM\/EFI via Ansible"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Assumptions:  You have a host with Ansible and a network.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Download the Gentoo iso from <a href=\"https:\/\/bouncer.gentoo.org\/fetch\/root\/all\/releases\/amd64\/autobuilds\/current-install-amd64-minimal\/\" data-type=\"URL\" data-id=\"https:\/\/bouncer.gentoo.org\/fetch\/root\/all\/releases\/amd64\/autobuilds\/current-install-amd64-minimal\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<br>Download the role from <a href=\"https:\/\/cdstealer.com\/filez\/gentoobase_ansible_role.tgz\" data-type=\"URL\" data-id=\"https:\/\/cdstealer.com\/filez\/gentoobase_ansible_roles.tgz\">here<\/a>.<br><br>You will need to edit:<br>gentoobase\/vars\/main.yml - encrypt password<br><br>Boot with the ISO (cached), ensuring that networking is present.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once booted, set a password and start the ssh daemon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unmount the ISO.<br><br>SSH as the root user to the target server.<br>mkdir .ssh<br>Copy the pubkey of the user executing the playbook into \/root\/.ssh\/authorized_keys<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CD to your playbook role directory.<br>Unpack the role tarball<br>Create the playbook below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Playbook<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">---<br>- name: Base Gentoo Installation<br>  gather_subset: min<br>  hosts: vms<br>  tasks:<br>    - import_role:<br>        name: gentoobase<br>...<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"> ansible-playbook -u root gentoo_install_base.yml<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will take ~3 hours to complete the base system.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Timings are based on a VM (i7 6700K x4, 16Gb RAM)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you wish to change any settings, edit:<br>roles\/gentoobase\/vars\/main.yml<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now go outside and get some fresh air.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The below is to understand the build process.<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Manual Steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Partition the HDD:<br>gdisk \/dev\/Xda<br>part1 = 512M 8300 [boot]<br>part2 = 100M ef00 efi [efi]<br>part3 = LVM 8e00 [LVM]<br>part4 = 4G 8200 [swap]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create LVMs:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>pvcreate \/dev\/Xda2\nvgcreate vg00 \/dev\/Xda2\nlvcreate -L 20G -n root vg00\nlvcreate -L 10G -n home vg00<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Format FileSystems:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mke2fs -t ext4 -L BOOT \/dev\/Xda1\nmkfs.vfat -F 32 -n EFI \/dev\/Xda2\nmke2fs -t ext4 -L ROOT \/dev\/mapper\/vg00-root\nmke2fs -t ext4 -L HOME \/dev\/mapper\/vg00-home<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Mount FileSystems:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mount -t ext4 \/dev\/mapper\/vg00-root \/mnt\/gentoo\nmkdir -p \/mnt\/gentoo\/boot\/EFI\nmount -t ext4 \/dev\/vda1 \/mnt\/gentoo\/boot\nmount -t vfat \/dev\/vda2 \/mnt\/gentoo\/boot\/EFI\nmount swap if configured<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">SCP the stage3 and portage files to the VM<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Download Tarballs:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">wget <a href=\"https:\/\/distfiles.gentoo.org\/releases\/amd64\/autobuilds\/current-stage3-amd64-systemd\/stage3-amd64-systemd-20240616T153408Z.tar.xz\">https:\/\/distfiles.gentoo.org\/releases\/amd64\/autobuilds\/current-stage3-amd64-systemd\/stage3-amd64-systemd-20240616T153408Z.tar.xz<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wget <a href=\"https:\/\/gentoo.osuosl.org\/snapshots\/portage-latest.tar.xz\">https:\/\/gentoo.osuosl.org\/snapshots\/portage-latest.tar.xz<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Unpack files:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>tar xpf stage3...xz -C \/mnt\/gentoo\ntar xpf portage-latest...xz -C \/mnt\/gentoo\/usr\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Mount Some More FileSystems:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mount -t proc \/proc \/mnt\/gentoo\/proc\nmount --rbind \/sys \/mnt\/gentoo\/sys\nmount --make-rslave \/mnt\/gentoo\/sys\nmount --rbind \/dev \/mnt\/gentoo\/dev\nmount --make-rslave \/mnt\/gentoo\/dev\nmount --rbind \/run \/mnt\/gentoo\/run\nmount --make-rslave \/mnt\/gentoo\/run\ntest -L \/dev\/shm &amp;&amp; rm \/dev\/shm &amp;&amp; mkdir \/dev\/shm\nmount -t tmpfs -o nosuid,nodev,noexec shm \/dev\/shm\nchmod 1777 \/dev\/shm<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setup Rsync Mirror:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">mirrorselect -i -o &gt;&gt; \/mnt\/gentoo\/etc\/portage\/make.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DNS:<br>cp -L \/etc\/resolv.conf \/mnt\/gentoo\/etc\/resolv.conf<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setup Portage:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/mnt\/gentoo\/var\/db\/repos\/gentoo\nmkdir \/mnt\/gentoo\/etc\/portage\/repos.conf\nnano -w \/mnt\/gentoo\/etc\/portage\/repos.conf\/gentoo.conf\n<\/code><\/pre>\n\n\n\n<pre id=\"block-b3f38190-2c9b-4bf4-b441-9d97ab2096e5\" class=\"wp-block-preformatted\">[DEFAULT]<br>main-repo = gentoo<br>[gentoo]<br>location = \/usr\/portage<br>sync-type = rsync<br>sync-uri = rsync:\/\/rsync.europe.gentoo.org\/gentoo-portage<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Chroot into the VM:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>chroot \/mnt\/gentoo \/bin\/bash\nenv-update\nsource \/etc\/profile<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Set Locale:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -sf \/usr\/share\/zoneinfo\/Europe\/London \/etc\/localtime\nnano -w \/etc\/locale.gen\n    <code>en_GB.UTF-8 UTF-8<\/code>\nExecute locale-gen<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Set Profile:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>eselect profile list (choose the number in brackets)\n\"&#91;30]  default\/linux\/amd64\/23.0\/no-multilib\/systemd (stable)\"\neselect profile set 30<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Let's Start Building:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>emerge -av gentoo-sources\nln -s \/usr\/src\/linux-&lt;version&gt;-gentoo \/usr\/src\/linux\ncd \/usr\/src\/linux\nmake defconfig &amp;&amp; make &amp;&amp; make modules_install\ncp arch\/x86_64\/boot\/bzImage \/boot\/kernel-&lt;version&gt;\ncp .config \/boot\/config-&lt;version&gt;-gentoo (optional)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cpan Locale::gettext<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>emerge -q vim genkernel grub lvm2 gptfdisk efibootmgr<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Setup Grub:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>grub-install --target=x86_64-efi --efi-directory=\/boot\/EFI \/dev\/Xda\nvi \/etc\/default\/grub\n    GRUB_CMDLINE_LINUX=\"rootfstype=ext4 init=\/usr\/lib\/systemd\/systemd dolvm\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Update fstab:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>blkid\nCopy the UUID for \/boot and \/\nUUID1=$(blkid | grep Xda1 | grep -Po \"(UUID.*?)\\\"\\s\")\nUUID2=$(blkid | grep Xda2 | grep -Po \"(UUID.*?)\\\"\\s\")\necho -e \"${UUID1}\\t\/boot\\text4\\tdefaults\\t1 2\" &gt;&gt; \/etc\/fstab\necho -e \"${UUID2}\\t\/\\text4\\tdefaults\\t1 1\" &gt;&gt; \/etc\/fstab<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/etc\/\ncp -p genkernel.conf genkernel.conf.orig\nvi genkernel.conf\n\nuncomment:\nMAKEOPTS=\"$(portageq envvar MAKEOPTS)\"\nLVM=\"yes\"\n\ngenkernel initramfs --lvm <mark style=\"background-color:#000\" class=\"has-inline-color has-white-color\">(this does not overwrite the kernel above)<\/mark>\ngrub-mkconfig -o \/boot\/grub\/grub.cfg\n\npasswd\n\nemerge -q networkmanager gentoolkit gpm\nsystemctl enable sshd NetworkManager<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Assumptions: You have a host with Ansible and a network. Download the Gentoo iso from here.Download the role from here. You will need to edit:gentoobase\/vars\/main.yml - encrypt password Boot with the ISO (cached), ensuring that networking is present. Once booted, set a password and start the ssh daemon. Unmount the ISO. SSH as the root &hellip; <a href=\"https:\/\/cdblog.cdstealer.com\/?p=2325\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Gentoo Install with LVM\/EFI via Ansible<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[328,329,213,10,18],"class_list":["post-2325","post","type-post","status-publish","format-standard","hentry","category-gentoo","tag-ansible","tag-automate","tag-gentoo","tag-install","tag-linux"],"_links":{"self":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2325"}],"version-history":[{"count":55,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2325\/revisions"}],"predecessor-version":[{"id":2495,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2325\/revisions\/2495"}],"wp:attachment":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}