User_commands.bash post-install issues I'd like help on

I’ve been expanding my user_commands.bash to do post-install things, and I’m hitting a curious road bump on one specific issue, and hoping another pair of eyes might help out in this.

#!/bin/bash

if [[ "$1" == "--iso-config" ]]; then
	installMode="$2"
	sed -i /etc/calamares/modules/partition.conf -E \
		-e 's|^defaultFileSystemType:.*|defaultFileSystemType: "btrfs"|' \
		-e 's|^(availableFileSystemTypes:.*)"ext4","btrfs"|\1"btrfs","ext4"|'
	sed -i /etc/calamares/modules/packagechooserq.conf -E \
		-e 's|packageChoice:.*|packageChoice: grub|'
	echo "default: XFCE4-Desktop" >> /etc/calamares/modules/packagechooser.conf
	#sed -i \
	#	-e 's/defaultFileSystemType:.*/defaultFileSystemType: "btrfs"/g' \
	#	-e 's/filesystem: "unknown"/filesystem: "btrfs"/g' \
	#	/etc/calamares/modules/partition.conf
	#sed -i -e 's/filesystem: "unknown"/filesystem: "btrfs"/g'
	#sed -i -e '/^btrfsSubvolumes:$/,/^$/ { r /dev/stdin' -e';d};' /etc/calamares/modules/mount.conf <<EOF
	sed -i /etc/calamares/modules/mount.conf -E \
		-e '/^btrfsSubvolumes:$/,/^$/ { r /dev/stdin' -e';d};' <<EOF
btrfsSubvolumes:
    - mountPoint: /
      subvolume: /@
    - mountPoint: /home
      subvolume: /@home
    - mountPoint: /var/cache
      subvolume: /@cache
    - mountPoint: /var/log
      subvolume: /@log
    - mountPoint: /srv
      subvolume: /@srv
    - mountPoint: /opt
      subvolume: /@opt
    - mountPoint: /usr/local
      subvolume: /@usrlocal
    - mountPoint: /var/lib/crash
      subvolume: /@crash
    - mountPoint: /var/lib/containers
      subvolume: /@containers
    - mountPoint: /var/lib/libvirt/images
      subvolume: /@libvirt
    - mountPoint: /var/lib/machines
      subvolume: /@machines
    - mountPoint: /var/lib/portables
      subvolume: /@portables
    - mountPoint: /var/spool
      subvolume: /@spool
    - mountPoint: /var/tmp
      subvolume: /@tmp
    - mountPoint: /var/www
      subvolume: /@www
    - mountPoint: /root
      subvolume: /@root
    - mountPoint: /.snapshots
      subvolume: /@snapshots

EOF
	sed -i -e '/^.*- filesystem: btrfs$/,/\]$/ { r /dev/stdin' -e';d};' /etc/calamares/modules/mount.conf <<EOF
    - filesystem: btrfs
      options: [ noatime, space_cache=v2, compress=zstd:1, ssd, discard=async ]
EOF
else
	username="$1"

	pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
	pacman-key --lsign-key 3056513887B78AEB
	pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst' 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
	echo -e "\n[chaotic-aur]\nInclude = /etc/pacman.d/chaotic-mirrorlist" >> /etc/pacman.conf
	echo -e "\n[aurto]\nSigLevel = Never\nServer = http://abs.home.ld/" >> /etc/pacman.conf
	pacman -Sy

	pacman -S --noconfirm --needed libreoffice-fresh gnome-software flatseal flatpak htop btop ncdu pwgen \
		vim neovim eza zsh yadm tmux tmuxinator \
		ttf-hack-nerd ttf-ubuntu-nerd ttf-ubuntu-mono-nerd ttf-terminus-nerd ttf-sourcecodepro-nerd ttf-roboto-mono-nerd \
		ttf-nerd-fonts-symbols noto-fonts noto-fonts-emoji noto-fonts-extra ttf-noto-nerd ttf-ms-fonts

	umount /.snapshots && rmdir /.snapshots
	mkdir -p /boot/grub
	pacman -S --noconfirm --needed snapper-support btrfsmaintenance btrfs-assistant btrbk snapper-rollback
	snapper create-config --template garuda /
	if [[ -d "/.snapshots" ]]; then
		btrfs sub delete /.snapshots
	fi
	mkdir /.snapshots && mount /.snapshots

	if dmesg | grep "Hypervisor detected"; then
		if dmesg | grep "Hypervisor detected: KVM"; then
			pacman -S --noconfirm --needed spice-vdagent qemu-guest-agent xf86-video-qxl
		fi
	fi

	flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo

	systemctl enable --now sshd
fi

That’s the script itself. The part that’s specifically giving me trouble is pre-setting up snapper. For whatever reason, the snapper config is never created, and I don’t see any reason why not? The snapper-support package is supposed to be creating the config, I’m manually attempting again, after the package install, and seeing no output… I’m not sure what’s the issue here. Or if I have to create a post-install script to run at first boot or something.

Here’s the log of the last attempt on this code: http://ix.io/4J2d

Thanks!


set BTRFS as default and only option result in this… filesystem option chooser is hidden only swap choice is there and it uses the set BTRFS scheme and indeed using BTRFS

You may need to add the --no-dbus option to your snapper create-config command, see here: https://github.com/openSUSE/snapper/issues/537

3 Likes

I was looking at this after you mentioned it. and this seems to be the snapper create config during the installation process, not the one after the pacman execution to install snapper-support.

I’m going to put in some echo’s in the script, and see if I can capture that a bit better.

I believe snapper create-config --template garuda is being run twice (once from the post-install script for snapper-support) and gets the same error both times. Here is the post install from snapper-support.install (https://gitlab.com/garuda-linux/packages/stable-pkgbuilds/snapper-support/-/blob/main/snapper-support.install?ref_type=heads)

post_install() {
    # Change grub snapshot submenu name
    if [ -e /etc/lsb-release ]; then
       echo "Using default grub snapshot submenu name"
    else
       sed -i /etc/default/grub-btrfs/config \
           -e "s,.*GRUB_BTRFS_SUBMENUNAME=.*,GRUB_BTRFS_SUBMENUNAME=\"$(sed '/^NAME=/!d;s/NAME=//;s/"//gm' /etc/os-release) snapshots\","
       echo "Generating grub snapshot submenu name from /etc/os-release values"
    fi

    if [[ $(/usr/bin/systemctl is-enabled grub-btrfs.path) == "enabled" ]]; then 
        /usr/bin/systemctl disable --now grub-btrfs.path; 
    fi

    echo "Enabling automatic rebuild of grub-btrfs when snapshots are taken"
    /usr/bin/systemctl daemon-reload
    /usr/bin/systemctl enable --now grub-btrfs-snapper.path
    /usr/bin/systemctl enable --now snapper-cleanup.timer
    #/usr/bin/systemctl enable snapper-timeline.timer
    
    echo "Creating snapper config for root"
    /usr/bin/snapper create-config --template garuda /

    if ! mkinitcpio_has_grub_btrfs_overlayfs_hook; then
        sed -re 's/(^HOOKS=[\"|(][^")]+)/\1 grub-btrfs-overlayfs/gi' -i /etc/mkinitcpio.conf
    fi
}

Here is the corresponding part of your journal:

[PYTHON JOB]: "installing snapper-support...\n" 
[PYTHON JOB]: "Using default grub snapshot submenu name\n" 
[PYTHON JOB]: "Enabling automatic rebuild of grub-btrfs when snapshots are taken\n" 
[PYTHON JOB]: "Running in chroot, ignoring command 'daemon-reload'\n" 
[PYTHON JOB]: "Created symlink /etc/systemd/system/multi-user.target.wants/grub-btrfs-snapper.path -> /usr/lib/systemd/system/grub-btrfs-snapper.path.\n" 
[PYTHON JOB]: "System has not been booted with systemd as init system (PID 1). Can't operate.\n" 
[PYTHON JOB]: "Failed to connect to bus: Host is down\n" 
[PYTHON JOB]: "Created symlink /etc/systemd/system/timers.target.wants/snapper-cleanup.timer -> /usr/lib/systemd/system/snapper-cleanup.timer.\n" 
[PYTHON JOB]: "System has not been booted with systemd as init system (PID 1). Can't operate.\n" 
[PYTHON JOB]: "Failed to connect to bus: Host is down\n" 
[PYTHON JOB]: "Creating snapper config for root\n" 
[PYTHON JOB]: "Failure (org.freedesktop.DBus.Error.FileNotFound).\n" 
[PYTHON JOB]: "grep: /etc/mkinitcpio.conf: No such file or directory\n" 
[PYTHON JOB]: "sed: can't read /etc/mkinitcpio.conf: No such file or directory\n" 
[PYTHON JOB]: "error: command failed to execute correctly\n" 

The post install script already runs /usr/bin/snapper create-config --template garuda / and gets Failure (org.freedesktop.DBus.Error.FileNotFound).

The second time this command is run (from your script) there isn’t an echo like in the post-install script, but you can still spot it since it happens after that batch of package installations, but before the hypervisor bit:

[...]
[PYTHON JOB]: "(5/7) Updating the info directory file...\n" 
[PYTHON JOB]: "(6/7) Updating the desktop file MIME type cache...\n" 
[PYTHON JOB]: "(7/7) Performing snapper post snapshots for the following configurations...\n" 
[PYTHON JOB]: "Failure (org.freedesktop.DBus.Error.FileNotFound).\n" 
[PYTHON JOB]: "[    0.000000] Hypervisor detected: KVM\n" 
[PYTHON JOB]: "[    0.000000] Hypervisor detected: KVM\n" 
[...]

Like you mentioned, there is no echo on your script to call it out but it is the same error message and that’s the right place for it.

I still think you should try adding the --no-dbus option to your snapper create-config command.

Confirmed! It was, but it was where to use it. snapper --no-dbus create-config, not snapper create-config --no-dbus. :slight_smile:

Course now I see snapshots after the fact. The eos_bootloader installation I see the pacman calls to install grub, eos-dracut, and os-prober. heh

Does EndeavourOS, or Arch in general, have a means to possibly handle putting this process in the first boot, and never run again, or delete itself, or would I basically need to create a rc.local type thing that runs at boot and disables and deletes itself?

If you are saying you would prefer the bootloader installation stuff be set up before the snapper stuff, one thing you could try would be adding the bootloader installation commands manually into your user_commands.bash script so it could be deployed in whatever part of the sequence you wish, and then switch your EOS installation to the “no bootloader” choice.

I might be misunderstanding your meaning. :sweat_smile:

No you got the meaning perfectly. But, I changed things up a bit, created a simple 1strun.service, and 1strun.sh. and voila! Snapper instantiates during first boot is done, and the scripts are self-deleting, and clean.

https://gist.github.com/erenfro/322fb35de264739edf852fb96499527f updated script, so far. :slight_smile:

2 Likes

Annnnd it woooorks! :slight_smile:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.