A bash script to install Void Linux with LUKS encryption, optional LVM, btrfs filesystem and optional swap as file.
Go to file
2022-07-26 21:51:53 +02:00
ASCIIArt Upload logo ASCII art 2022-07-14 20:29:06 +02:00
old_unused Add old script to separated folder 2022-07-18 23:15:09 +02:00
LICENSE Upload files 2022-07-05 20:42:36 +02:00
README.md Improve instructions after refactoring LVM 2022-07-26 21:35:42 +02:00
vli.sh Improve final unmounting partitions 2022-07-26 21:51:53 +02:00

VoidLinuxInstaller script

The VoidLinuxInstaller script is an attempt to make my gist an interactive bash script.

As stated in the gist, this script provides:

  • Full Disk Encryption (including /boot) with LUKS;
  • Logic Volume Management (LVM);
  • BTRFS as filesystem.
  • Trim on SSD;

To know how the script works in details, please jump to the How does it work? section!

To know how to run the script, please jump to the How to run it? section!

This script comes from my need to automate my gist as much as I can, and also as a way to learn Bash scripting as well. This is my first Bash script ever created so bugs, errors and really ugly code are expected!

I've tried this script a lot with virtual machines and following every step always brought me to a functional system, so there should be no problem from this point of view!

Pull requests are absolutely welcome!


How to run it?

First update xbps package:

xbps-install -Sy xbps

then install wget or curl package:

# For wget
xbps-install -Sy wget

# For curl
xbps-install -Sy curl

then use wget to download the needed file:

wget https://raw.githubusercontent.com/Le0xFF/VoidLinuxInstaller/main/vli.sh -O $HOME/vli.sh

or curl if you prefer:

curl -o $HOME/vli.sh https://raw.githubusercontent.com/Le0xFF/VoidLinuxInstaller/main/vli.sh

then make it executable:

chmod +x $HOME/vli.sh

and finally run it:

bash $HOME/vli.sh

How does it work?

Here is documented how the script works in details and what will ask to the user in each different step. It will:

  1. prompt the user to eventually change their keyboard layout from a list of all the different available layouts.
  2. check internet connection and eventually guide the user to connect to the internet;
  3. wipe a user choosen drive and that drive will be the one also selected for partitioning;
  4. partition a user choosen drive:
    • if the previous drive was not the right one, it will ask the user if they want to change it eventually;
    • check the Suggested partition layout to follow the script workflow;
  5. encrypt a user choosen partition for Full Disk Encryption:
    • it will ask for a mountpoint name, so that the encrypted partition will be mounted as
      /dev/mapper/<encrypted_name>;
  6. apply Logical Volume Management to the previous encrypted partition, to have the flexibility to resize / and to add more space in the future without reformatting the whole system:
    • it will ask for a Volume Group name, so that will be mounted as
      /dev/mapper/<volume_group>;
    • it will ask for a Logical Volume name for root partition and its size will be the previously selected partition, so that will be mounted as
      /dev/mapper/<volume_group>-<lv_root_name>;
    • check the Final partitioning result to get an overview of what the outcome will be;
  7. Formatting partitions to proper filesystems:
    • it will prompt user to select which partition to use as boot partition and to choose its label; it will be formatted as FAT32 and mounted as
      /boot/efi;
    • it will prompt user to select a label for the root logical volume, that will be formatted as BTRFS;
  8. create BTRFS subvolumes with specific fstab mount options; if user wants to change them, please edit the script looking for create_btrfs_subvolumes function (BTRFS mount options official documentation):
    • BTRFS mounting options:
      • rw,noatime,discard=async,compress-force=zstd,space_cache=v2,commit=120
    • BTRFS subvolumes that will be created:
      • /@
      • /@home
      • /@snapshots
      • /var/cache/xbps
      • /var/tmp
      • /var/log
  9. install base system:
    • It will ask user to choose between x86_64 and x86_64-musl;
  10. chroot:
    • set root password and / permissions;
    • create proper /etc/fstab file;
    • generate random key to avoid typing password two times at boot;
    • create proper dracut configuration and initramfs;
    • install grub;
    • enable internet at first boot with NetworkManager.

Suggested partition layout

To have a smooth script workflow, the following is the suggested disk layout:

  • GPT as disk label type for UEFI systems, also because this script will only works on UEFI systems;
  • Less than 1 GB for /boot/efi as first partition, as EFI System type;
  • Rest of the disk for the Volume Group, where LVM will be applied, as second partition as Linux filesystem.

Those two will be physical partition.
You don't need to create a /home partition because BTRFS subvolumes will take care of that.

Final partitioning result

Following the script, at the very end your drive will end up being like the following:

/dev/nvme0n1                                    259:0    0 953,9G  0 disk  
├─/dev/nvme0n1p1                                259:1    0     1G  0 part  /boot/efi
└─/dev/nvme0n1p2                                259:2    0 942,9G  0 part  
  └─/dev/mapper/<encrypted_name>                254:0    0 942,9G  0 crypt 
    └─/dev/mapper/<volume_group>-<lv_root_name> 254:1    0 942,9G  0 lvm   /.snapshots
                                                                           /home
                                                                           /

Note: /.snapshots will be available after creating a snapper configuration for /, after following the [Follow up for '@snapshotssubvolume](#follow-up-for-snapshots-subvolume) section and finally after uncommenting the relative line from/etc/fstab`.


Follow up for @snapshots subvolume

With this script, the @snapshots subvolume will be created, but not the /.snapshots folder. This is done to avoid stupid snapper issues when trying to create a configuration for /.

So after installing snapper from Void Linux's repositories, you have to delete the subvolume that it will automatically create, then create the /.snapshots folder and then uncomment the relative line from /etc/fstab:

# run these commands as root

btrfs subvolume delete /.snapshots
mkdir /.snapshots
## edit /etc/fstab uncommenting the line relative to @snapshots subvolume ##
reboot

Source: Arch Wiki


What to do if system breaks?

In case anything will break, you will just have to delete the @ subvolume, create it again and reinstall your distro. /home folder won't be affected in any way.

In details, after booting a LiveCD, mount the encrypted partition:

cryptsetup open /dev/nvme0n1p2 LinuxCrypt

Scan for Volume Groups and then enable the one you need:

vgscan
vgchange -ay LinuxGroup

Mount the true btrfs root by its subvol or by its subvolid:

# by subvol
mount -o subvol=/ /dev/mapper/LinuxGroup-LinuxSystem /mnt

# or by subvolid
mount -o subvolid=0 /dev/mapper/LinuxGroup-LinuxSystem /mnt

After that if you do an ls /mnt/ you will see all the subvolume previously created. Now you must delete ONLY the @ subvolume and finally unmount /mnt:

btrfs subvolume delete /mnt/@
umount /mnt

You now have to reinstall Void Linux manually (the script is not programmed to help you this time). For this you can follow the original gist and start again from Mount partitions and create btrfs subvolumes instruction, without creating the @home subvolume.

When the package reconfiguration is finished, you have to create a user with the same name of the one you created before, possibly adding it to the same groups as before, but you can do it later too.
**Don't add the -m flag or your original home folder will be destroyed:

useradd -G wheel <same_user>
passwd <same_user>

This is not necessary because adding the same user will automatically change the home folder permission, but just in case:

chown -R <same_user>:<same_user> /home/<same_user>

Notes


Resources

[1] https://tldp.org/LDP/Bash-Beginners-Guide/html/index.html

[2] https://gist.github.com/tobi-wan-kenobi/bff3af81eac27e210e1dc88ba660596e

[3] https://gist.github.com/gbrlsnchs/9c9dc55cd0beb26e141ee3ea59f26e21

[4] https://unixsheikh.com/tutorials/real-full-disk-encryption-using-grub-on-void-linux-for-bios.html