Last active
March 22, 2022 12:35
-
-
Save sulincix/e97c4b3a38e227c701790f5d73a29a82 to your computer and use it in GitHub Desktop.
archlinux vagrant images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### tool-init | |
| set -ex | |
| mkdir -p work | |
| if [[ ! -f /bin/archstrap ]] ; then | |
| wget https://gitlab.com/tearch-linux/applications-and-tools/archstrap/-/raw/master/archstrap.sh -O archstrap | |
| mv archstrap /bin/archstrap | |
| chmod +x /bin/archstrap | |
| fi | |
| ### create archlinux chroot | |
| archstrap work/rootfs | |
| mount --bind /proc work/rootfs/proc | |
| mount --bind /dev work/rootfs/dev | |
| sed -i 's/^CheckSpace/#CheckSpace/g' work/rootfs/etc/pacman.conf | |
| chroot work/rootfs pacman-key --init | |
| chroot work/rootfs pacman-key --populate archlinux | |
| chroot work/rootfs pacman -Syyu --noconfirm | |
| chroot work/rootfs pacman -Syy sudo openssh linux --noconfirm | |
| chroot work/rootfs systemctl enable sshd | |
| ### User creation | |
| chroot work/rootfs useradd vagrant -s /bin/bash -m | |
| chroot work/rootfs usermod -aG wheel vagrant | |
| chroot work/rootfs usermod -p $(openssl passwd devuan) vagrant | |
| chroot work/rootfs usermod -p $(openssl passwd devuan) root | |
| ### Ssh key add | |
| mkdir work/rootfs/home/vagrant/.ssh | |
| wget -O work/rootfs/home/vagrant/.ssh/authorized_keys https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub | |
| chroot work/rootfs chown -R vagrant:vagrant /home/vagrant/.ssh | |
| chmod 0700 work/rootfs/home/vagrant/.ssh | |
| chmod 0600 work/rootfs/home/vagrant/.ssh/authorized_keys | |
| ### Sudo without password | |
| cat >> work/rootfs/etc/sudoers <<EOF | |
| vagrant ALL=(ALL) NOPASSWD: ALL | |
| EOF | |
| ### Networking | |
| chroot work/rootfs pacman -Sy networkmanager --noconfirm | |
| chroot work/rootfs systemctl enable NetworkManager | |
| ### Clean | |
| find work/rootfs/var/log -type f | xargs rm -f | |
| rm -rf work/rootfs/var/cache/pacman/pkg/* || true | |
| ### Umount | |
| umount -lf -R work/rootfs/proc | |
| umount -lf -R work/rootfs/dev | |
| #### create image and partitons | |
| size=$(du -s "work/rootfs" | cut -f 1) | |
| qemu-img create "archlinux.img" 60G | |
| parted "archlinux.img" mklabel msdos | |
| echo Ignore | parted "archlinux.img" mkpart primary ext2 2048s 100% | |
| #### format image | |
| losetup -d /dev/loop0 || true | |
| loop=$(losetup --partscan --find --show "archlinux.img" | grep "/dev/loop") | |
| mkfs.ext4 ${loop}p1 | |
| mount ${loop}p1 /mnt | |
| cp -prfv work/rootfs/* /mnt/ | |
| mkdir -p /mnt/boot/grub | |
| echo "(hd0) ${loop}" > /mnt/boot/grub/device.map | |
| #### copy partition | |
| mount --bind /dev /mnt/dev | |
| grub-install --locales="" --removable --grub-mkdevicemap=/mnt/boot/grub/device.map --target=i386-pc --root-directory=/mnt ${loop} | |
| mkdir -p /mnt/boot/grub/ | |
| echo "linux /boot/vmlinuz-linux root=/dev/sda1 rw quiet" > /mnt/boot/grub/grub.cfg | |
| echo "initrd /boot/initramfs-linux.img" >> /mnt/boot/grub/grub.cfg | |
| echo "boot" >> /mnt/boot/grub/grub.cfg | |
| sync | |
| while umount -l -f /mnt/dev /mnt; do true ; done | |
| losetup -d ${loop}* || true | |
| #### Create vagrant box | |
| mkdir -p work/vagrant/ | |
| qemu-img convert -f raw -O vmdk archlinux.img work/vagrant/box.vmdk | |
| echo '{"provider":"virtualbox"}' > work/vagrant/metadata.json | |
| echo 'Vagrant.configure("2") do |config|' > work/vagrant/Vagrantfile | |
| echo 'config.vm.base_mac = "0800278dc04d"' >> work/vagrant/Vagrantfile | |
| echo 'config.vm.post_up_message = "Hello World"' >> work/vagrant/Vagrantfile | |
| echo 'end' >> work/vagrant/Vagrantfile | |
| cat > work/vagrant/box.ovf << EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!-- Imported by import2vbox.pl --> | |
| <ovf:Envelope ovf:version="1.0" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vbox="http://www.virtualbox.org/ovf/machine" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"> | |
| <References> | |
| <File ovf:href="box.vmdk" ovf:id="box0" ovf:size="21474836480" ovf:description="Imported by import2vbox.pl"></File> | |
| </References> | |
| <NetworkSection> | |
| <Info>List of networks</Info> | |
| <Network ovf:name="NAT"> | |
| <Description>NAT network used by this VM</Description> | |
| </Network> | |
| </NetworkSection> | |
| <DiskSection> | |
| <Info>List of Virtual Disks</Info> | |
| <Disk ovf:diskId="vmdisk0" ovf:capacity="21474836480" ovf:fileRef="box0" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" ovf:disk-type="System" ovf:boot="True" vbox:uuid="cc0e5888-bdd7-49cd-8dab-9f7377d523dc"></Disk> | |
| </DiskSection> | |
| <VirtualSystem ovf:id="box"> | |
| <Info>devuan linux x86_64 11.2</Info> | |
| <Name>bullseye</Name> | |
| <OperatingSystemSection ovf:id="96" ovf:required="false"> | |
| <Info>The kind of operating system contained in this VM</Info> | |
| <Description>devuan</Description> | |
| </OperatingSystemSection> | |
| <VirtualHardwareSection> | |
| <Info>2 CPU, 512 Memory</Info> | |
| <Item> | |
| <rasd:Caption>2 virtual cpu</rasd:Caption> | |
| <rasd:Description>Number of virtual CPU</rasd:Description> | |
| <rasd:InstanceID>1</rasd:InstanceID> | |
| <rasd:ResourceType>3</rasd:ResourceType> | |
| <rasd:VirtualQuantity>2</rasd:VirtualQuantity> | |
| </Item> | |
| <Item> | |
| <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> | |
| <rasd:Caption>512 MB of memory</rasd:Caption> | |
| <rasd:Description>Memory Size</rasd:Description> | |
| <rasd:InstanceID>2</rasd:InstanceID> | |
| <rasd:ResourceType>4</rasd:ResourceType> | |
| <rasd:VirtualQuantity>512</rasd:VirtualQuantity> | |
| </Item> | |
| <Item> | |
| <rasd:Address>0</rasd:Address> | |
| <rasd:Caption>sataController0</rasd:Caption> | |
| <rasd:Description>SATA Controller</rasd:Description> | |
| <rasd:ElementName>sataController0</rasd:ElementName> | |
| <rasd:InstanceID>3</rasd:InstanceID> | |
| <rasd:ResourceSubType>AHCI</rasd:ResourceSubType> | |
| <rasd:ResourceType>20</rasd:ResourceType> | |
| </Item> | |
| <Item> | |
| <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> | |
| <rasd:Caption>Ethernet adapter on 'NAT'</rasd:Caption> | |
| <rasd:Connection>NAT</rasd:Connection> | |
| <rasd:ElementName>Ethernet Adapter on 'NAT'</rasd:ElementName> | |
| <rasd:InstanceID>4</rasd:InstanceID> | |
| <rasd:ResourceSubType>E1000</rasd:ResourceSubType> | |
| <rasd:ResourceType>10</rasd:ResourceType> | |
| </Item> | |
| <Item> | |
| <rasd:AddressOnParent>0</rasd:AddressOnParent> | |
| <rasd:ElementName>Drive 0</rasd:ElementName> | |
| <rasd:HostResource>ovf:/disk/vmdisk0</rasd:HostResource> | |
| <rasd:InstanceID>5</rasd:InstanceID> | |
| <rasd:Parent>3</rasd:Parent> | |
| <rasd:ResourceType>17</rasd:ResourceType> | |
| </Item> | |
| </VirtualHardwareSection> | |
| <vbox:Machine ovf:required="false" version="1.16-linux" uuid="{7ec3b584-e298-44ad-b669-9278e082ff5a}" name="box"> | |
| <ovf:Info>Extra Virtual Machine Configuration in VirtualBoxFormat</ovf:Info> | |
| <Hardware> | |
| <CPU count="2"></CPU> | |
| <BIOS></BIOS> | |
| <Memory RAMSize="512" /> | |
| <Display controller="VMSVGA" /> | |
| <Network> | |
| <Adapter slot="0" enabled="true" type="82540EM"> | |
| <NAT /> | |
| </Adapter> | |
| <Adapter slot="1" type="82540EM" /> | |
| <Adapter slot="2" type="82540EM" /> | |
| <Adapter slot="3" type="82540EM" /> | |
| <Adapter slot="4" type="82540EM" /> | |
| <Adapter slot="5" type="82540EM" /> | |
| <Adapter slot="6" type="82540EM" /> | |
| <Adapter slot="7" type="82540EM" /> | |
| </Network> | |
| </Hardware> | |
| <StorageControllers> | |
| <StorageController name="SATA Controller" type="AHCI" PortCount="1"> | |
| <AttachedDevice type="HardDisk" hotpluggable="false" port="0" device="0"> | |
| <Image uuid="{cc0e5888-bdd7-49cd-8dab-9f7377d523dc}" /> | |
| </AttachedDevice> | |
| </StorageController> | |
| <StorageController name="Floppy Controller Controller" type="I82078" PortCount="1" /> | |
| </StorageControllers> | |
| </vbox:Machine> | |
| </VirtualSystem> | |
| </ovf:Envelope> | |
| EOF | |
| cd work/vagrant | |
| tar --gz -cvf ../../archlinux.box * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment