Last active
March 27, 2022 21:50
-
-
Save sulincix/0ca4af4619d25c21d39466bae31a8e14 to your computer and use it in GitHub Desktop.
Devuan vagrant imager
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
#!/bin/bash | |
set -ex | |
apt update | |
apt install qemu-kvm debootstrap grub-pc-bin -yq | |
mkdir -p work/ | |
[[ ! -f work/rootfs/etc/os-release ]] && debootstrap --variant=minbase --arch amd64 --no-merged-usr --no-check-gpg stable work/rootfs https://pkgmaster.devuan.org/merged | |
chroot work/rootfs apt install devuan-keyring -yq | |
### Anti bloat | |
cat > work/rootfs/etc/apt/apt.conf.d/01norecommend << EOF | |
APT::Install-Recommends "0"; | |
APT::Install-Suggests "0"; | |
EOF | |
#### Remove bloat files after dpkg invoke | |
cat > work/rootfs/etc/apt/apt.conf.d/02antibloat << EOF | |
DPkg::Post-Invoke {"rm -rf /usr/share/locale || true";}; | |
DPkg::Post-Invoke {"rm -rf /usr/share/man || true";}; | |
DPkg::Post-Invoke {"rm -rf /usr/share/help || true";}; | |
DPkg::Post-Invoke {"rm -rf /usr/share/doc || true";}; | |
DPkg::Post-Invoke {"rm -rf /usr/share/info || true";}; | |
EOF | |
### Apt sandbox user root | |
echo "APT::Sandbox::User root;" > work/rootfs/etc/apt/apt.conf.d/99sandboxroot | |
chroot work/rootfs apt install gnupg -y | |
### Vital packages | |
chroot work/rootfs apt update | |
chroot work/rootfs apt install linux-image-amd64 openssh-server netcat sudo -yq | |
### User creation | |
chroot work/rootfs useradd vagrant -s /bin/bash -m | |
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 apt install network-manager --no-install-recommends -yq | |
### Clean | |
chroot work/rootfs apt clean | |
find work/rootfs/var/log -type f | xargs rm -f | |
#### create image and partitons | |
size=$(du -s "work/rootfs" | cut -f 1) | |
qemu-img create "devuan.img" 60G | |
parted "devuan.img" mklabel msdos | |
echo Ignore | parted "devuan.img" mkpart primary ext2 2048s 100% | |
#### format image | |
losetup -d /dev/loop0 || true | |
loop=$(losetup --partscan --find --show "devuan.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 /vmlinuz root=/dev/sda1 rw quiet" > /mnt/boot/grub/grub.cfg | |
echo "initrd /initrd.img" >> /mnt/boot/grub/grub.cfg | |
echo "boot" >> /mnt/boot/grub/grub.cfg | |
sync | |
while umount -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 devuan.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 ../../devuan.box * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment