{"id":1990,"date":"2025-06-10T03:02:12","date_gmt":"2025-06-10T03:02:12","guid":{"rendered":"https:\/\/www.nicktailor.com\/?p=1990"},"modified":"2025-07-11T03:23:43","modified_gmt":"2025-07-11T03:23:43","slug":"automating-rocky-linux-vm-creation-with-packer-virtualbox","status":"publish","type":"post","link":"https:\/\/nicktailor.com\/tech-blog\/automating-rocky-linux-vm-creation-with-packer-virtualbox\/","title":{"rendered":"Automating Rocky Linux VM Creation with Packer + VirtualBox"},"content":{"rendered":"<p><style>\n    body {<br \/>\n      font-family: Arial, sans-serif;<br \/>\n      line-height: 1.6;<br \/>\n      max-width: 800px;<br \/>\n      margin: 0 auto;<br \/>\n      padding: 2em;<br \/>\n      background: #fff;<br \/>\n      color: #333;<br \/>\n    }<br \/>\n    pre {<br \/>\n      background: #f5f5f5;<br \/>\n      padding: 1em;<br \/>\n      overflow-x: auto;<br \/>\n      border-radius: 4px;<br \/>\n    }<br \/>\n    code {<br \/>\n      font-family: Consolas, monospace;<br \/>\n    }<br \/>\n    h1, h2, h3 {<br \/>\n      color: #222;<br \/>\n    }<br \/>\n  <\/style><\/p>\n<p>If you&#8217;ve ever needed to spin up a clean, minimal Linux VM for testing or local automation \u2014 and got tired of clicking through the VirtualBox GUI \u2014 this guide is for you.<\/p>\n<p>We\u2019ll walk through how to use <strong>HashiCorp Packer<\/strong> and <strong>VirtualBox<\/strong> to automatically create a <strong>Rocky Linux 8.10<\/strong> image, ready to boot and use \u2014 no Vagrant, no fluff.<\/p>\n<h2>What You\u2019ll Need<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.packer.io\/downloads\">Packer<\/a> installed<\/li>\n<li><a href=\"https:\/\/www.virtualbox.org\/\">VirtualBox<\/a> installed<\/li>\n<li>Rocky Linux 8.10 ISO link (we use minimal)<\/li>\n<li>Basic understanding of Linux + VirtualBox<\/li>\n<\/ul>\n<h2>Project Structure<\/h2>\n<pre><code>packer-rocky\/\n\u251c\u2500\u2500 http\/\n\u2502   \u2514\u2500\u2500 ks.cfg       # Kickstart file for unattended install\n\u251c\u2500\u2500 rocky.pkr.hcl    # Main Packer config\n<\/code><\/pre>\n<h2>Step 1: Create the Kickstart File (http\/ks.cfg)<\/h2>\n<pre><code>install\ncdrom\nlang en_US.UTF-8\nkeyboard us\nnetwork --bootproto=dhcp\nrootpw packer\nfirewall --disabled\nselinux --permissive\ntimezone UTC\nbootloader --location=mbr\ntext\nskipx\nzerombr\n\n# Partition disk\nclearpart --all --initlabel\npart \/boot --fstype=\"xfs\" --size=1024\npart pv.01 --fstype=\"lvmpv\" --grow\nvolgroup vg0 pv.01\nlogvol \/ --vgname=vg0 --fstype=\"xfs\" --size=10240 --name=root\nlogvol swap --vgname=vg0 --size=4096 --name=swap\n\nreboot\n\n%packages --ignoremissing\n@core\n@base\n%end\n\n%post\n# Post-install steps can be added here\n%end<\/code><\/pre>\n<h2>Step 2: Create the Packer HCL Template (rocky.pkr.hcl)<\/h2>\n<pre><code>packer {\n  required_plugins {\n    virtualbox = {\n      version = \"&gt;= 1.0.5\"\n      source  = \"github.com\/hashicorp\/virtualbox\"\n    }\n  }\n}\n\nsource \"virtualbox-iso\" \"rocky\" {\n  iso_url                 = \"https:\/\/download.rockylinux.org\/pub\/rocky\/8\/isos\/x86_64\/Rocky-8.10-x86_64-minimal.iso\"\n  iso_checksum            = \"2c735d3b0de921bd671a0e2d08461e3593ac84f64cdaef32e3ed56ba01f74f4b\"\n  guest_os_type           = \"RedHat_64\"\n  memory                  = 2048\n  cpus                    = 2\n  disk_size               = 40000\n  vm_name                 = \"rocky-8\"\n  headless                = false\n  guest_additions_mode    = \"disable\"\n  boot_command            = [\" inst.text inst.ks=http:\/\/{{ .HTTPIP }}:{{ .HTTPPort }}\/ks.cfg\"]\n  http_directory          = \"http\"\n  ssh_username            = \"root\"\n  ssh_password            = \"packer\"\n  ssh_timeout             = \"20m\"\n  shutdown_command        = \"shutdown -P now\"\n  vboxmanage = [\n    [\"modifyvm\", \"{{.Name}}\", \"--vram\", \"32\"],\n    [\"modifyvm\", \"{{.Name}}\", \"--vrde\", \"off\"],\n    [\"modifyvm\", \"{{.Name}}\", \"--ioapic\", \"off\"],\n    [\"modifyvm\", \"{{.Name}}\", \"--pae\", \"off\"],\n    [\"modifyvm\", \"{{.Name}}\", \"--nested-hw-virt\", \"on\"]\n  ]\n}\n\nbuild {\n  sources = [\"source.virtualbox-iso.rocky\"]\n}<\/code><\/pre>\n<h2>Step 3: Run the Build<\/h2>\n<pre><code>cd packer-rocky\npacker init .\npacker build .<\/code><\/pre>\n<p>Packer will:<\/p>\n<ol>\n<li>Download and boot the ISO in VirtualBox<\/li>\n<li>Serve the ks.cfg file over HTTP<\/li>\n<li>Automatically install Rocky Linux<\/li>\n<li>Power off the machine once complete<\/li>\n<\/ol>\n<h2>Result<\/h2>\n<p>You now have a fully installed Rocky Linux 8.10 image in VirtualBox \u2014 no manual setup required.<\/p>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/www.nicktailor.com\/wp-content\/uploads\/2025\/07\/packer1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"546\" src=\"http:\/\/www.nicktailor.com\/wp-content\/uploads\/2025\/07\/packer1.png\" alt=\"\" class=\"wp-image-1993\" srcset=\"https:\/\/nicktailor.com\/tech-blog\/wp-content\/uploads\/2025\/07\/packer1.png 628w, https:\/\/nicktailor.com\/tech-blog\/wp-content\/uploads\/2025\/07\/packer1-600x522.png 600w, https:\/\/nicktailor.com\/tech-blog\/wp-content\/uploads\/2025\/07\/packer1-300x261.png 300w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/www.nicktailor.com\/wp-content\/uploads\/2025\/07\/packer2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"546\" src=\"http:\/\/www.nicktailor.com\/wp-content\/uploads\/2025\/07\/packer2.png\" alt=\"\" class=\"wp-image-1994\" srcset=\"https:\/\/nicktailor.com\/tech-blog\/wp-content\/uploads\/2025\/07\/packer2.png 628w, https:\/\/nicktailor.com\/tech-blog\/wp-content\/uploads\/2025\/07\/packer2-600x522.png 600w, https:\/\/nicktailor.com\/tech-blog\/wp-content\/uploads\/2025\/07\/packer2-300x261.png 300w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever needed to spin up a clean, minimal Linux VM for testing or local automation \u2014 and got tired of clicking through the VirtualBox GUI \u2014 this guide is for you. We\u2019ll walk through how to use HashiCorp Packer and VirtualBox to automatically create a Rocky Linux 8.10 image, ready to boot and use \u2014 no Vagrant, no<a href=\"https:\/\/nicktailor.com\/tech-blog\/automating-rocky-linux-vm-creation-with-packer-virtualbox\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[146,138],"tags":[],"class_list":["post-1990","post","type-post","status-publish","format-standard","hentry","category-azure","category-linux"],"_links":{"self":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/1990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=1990"}],"version-history":[{"count":3,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/1990\/revisions"}],"predecessor-version":[{"id":1996,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/1990\/revisions\/1996"}],"wp:attachment":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=1990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=1990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=1990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}