Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: btrfs assistant & grub-btrfs #789

Merged
merged 30 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
84551e2
Btrfs Assistant(+snapper), grub-btrfs Setup added
leventbesli Oct 3, 2024
62ab209
updated doc, ta_data and sh
leventbesli Oct 3, 2024
f97639e
enable grub-btrfsd service added
leventbesli Oct 3, 2024
3e0672c
Merge branch 'FedoraBTRFS' of https://github.com/leventbesli/linutil …
leventbesli Oct 4, 2024
64b8a4f
updated some wording in notices.
leventbesli Oct 4, 2024
6c1572d
updated wording and add prompts for actions
leventbesli Oct 5, 2024
8403042
added fix for a possible grub error
leventbesli Oct 5, 2024
38088f1
user action removed
leventbesli Oct 5, 2024
34e38ad
firs snapshot order changed
leventbesli Oct 5, 2024
7ef34b6
better explanations in user prompts
leventbesli Oct 6, 2024
7cb3bdc
improved y/n loop
leventbesli Oct 6, 2024
6425a4a
formatting improvements
leventbesli Oct 6, 2024
050f5b4
formatting improvement
leventbesli Oct 6, 2024
7b77a92
formatting improvement
leventbesli Oct 6, 2024
8b6ff21
Update task list
leventbesli Oct 6, 2024
eb3881b
removed a inline comment
leventbesli Oct 6, 2024
2dce55a
removed an unnececary inline comment
leventbesli Oct 6, 2024
4f88719
removed an unnececary inline comment
leventbesli Oct 6, 2024
fc82525
improved sed -i
leventbesli Oct 6, 2024
346e760
improved sed -i
leventbesli Oct 6, 2024
09c1efb
improved sed -i
leventbesli Oct 6, 2024
067dd54
newlines removed from tab_data.toml
leventbesli Oct 6, 2024
85588c6
btrfs detection moved to toml
leventbesli Oct 6, 2024
7e09b49
data.preconditions added - escalation tool used
leventbesli Oct 6, 2024
ec4080f
$PACKAGER replaced with dnf
leventbesli Oct 6, 2024
75d56e7
re-added packager
leventbesli Oct 6, 2024
fed5afc
re-added packager
leventbesli Oct 6, 2024
504bde9
Merge branch 'FedoraBTRFS' of https://github.com/leventbesli/linutil …
leventbesli Oct 9, 2024
1b4fb60
usergide updated with docgen
leventbesli Oct 9, 2024
4939861
typo fix
leventbesli Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions core/tabs/system-setup/fedora/fedora-btrfs-assistant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/bin/sh -e

. ../../common-script.sh

# This script automates the installation and root and home snapshot configuration of Snapper and installs Grub-Btrfs on Fedora.
# Also installs python3-dnf-plugin-snapper package for automatic snapshots after dnf commands.

# Install Btrfs-Assistant/snapper and dependencies
installBtrfsStack() {
if ! command_exists btrfs-assistant; then
printf "%b\n" "${YELLOW}==========================================${RC}"
printf "%b\n" "${YELLOW}Installing Btrfs Assistant with snapper...${RC}"
printf "%b\n" "${YELLOW}==========================================${RC}"
case "$PACKAGER" in
dnf)
"$ESCALATION_TOOL" "$PACKAGER" install -y btrfs-assistant python3-dnf-plugin-snapper
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
exit 1
;;
esac
else
printf "%b\n" "${GREEN}Btrfs Assistant is already installed.${RC}"
fi
}

# Create first snapper config for root and home and create new manual snapshots
configureSnapper() {
printf "%b\n" "${YELLOW}===========================================================================${RC}"
printf "%b\n" "${YELLOW}Creating snapper root(/) and /home config and taking the first snapshots...${RC}"
printf "%b\n" "${YELLOW}===========================================================================${RC}"
"$ESCALATION_TOOL" snapper -c home create-config /home && "$ESCALATION_TOOL" snapper -c home create --description "First home Snapshot"
"$ESCALATION_TOOL" snapper -c root create-config / && "$ESCALATION_TOOL" snapper -c root create --description "First root Snapshot"
printf "%b\n" "${YELLOW}Updating timeline settings...${RC}"
# Modifyling default timeline root config
"$ESCALATION_TOOL" sed -i'' '
s/^TIMELINE_LIMIT_HOURLY="[^"]*"/TIMELINE_LIMIT_HOURLY="1"/;
s/^TIMELINE_LIMIT_DAILY="[^"]*"/TIMELINE_LIMIT_DAILY="2"/;
s/^TIMELINE_LIMIT_WEEKLY="[^"]*"/TIMELINE_LIMIT_WEEKLY="1"/;
s/^TIMELINE_LIMIT_MONTHLY="[^"]*"/TIMELINE_LIMIT_MONTHLY="0"/;
s/^TIMELINE_LIMIT_YEARLY="[^"]*"/TIMELINE_LIMIT_YEARLY="0"/
' /etc/snapper/configs/root
# Modifyling default timeline for home config
"$ESCALATION_TOOL" sed -i'' '
s/^TIMELINE_LIMIT_HOURLY="[^"]*"/TIMELINE_LIMIT_HOURLY="2"/;
s/^TIMELINE_LIMIT_DAILY="[^"]*"/TIMELINE_LIMIT_DAILY="1"/;
s/^TIMELINE_LIMIT_WEEKLY="[^"]*"/TIMELINE_LIMIT_WEEKLY="0"/;
s/^TIMELINE_LIMIT_MONTHLY="[^"]*"/TIMELINE_LIMIT_MONTHLY="1"/;
s/^TIMELINE_LIMIT_YEARLY="[^"]*"/TIMELINE_LIMIT_YEARLY="0"/
' /etc/snapper/configs/home
printf "%b\n" "${GREEN}Snapper configs and first snapshots created.${RC}"
}

# Starting services
serviceStartEnable() {
printf "%b\n" "${YELLOW}==================================================================================${RC}"
printf "%b\n" "${YELLOW}Starting and enabling snapper-timeline.timer and snapper-cleanup.timer services...${RC}"
printf "%b\n" "${YELLOW}==================================================================================${RC}"
"$ESCALATION_TOOL" systemctl enable --now snapper-timeline.timer
"$ESCALATION_TOOL" systemctl enable --now snapper-cleanup.timer
printf "%b\n" "${GREEN}Snapper services started and enabled.${RC}"
}

# Ask user if they want to install grub-btrfs
askInstallGrubBtrfs() {
printf "%b\n" "${YELLOW}=====================================${RC}"
printf "%b\n" "${YELLOW}(optional) grub-btrfs installation...${RC}"
printf "%b\n" "${YELLOW}=====================================${RC}"
printf "%b\n" "${YELLOW}You can skip installing grub-btrfs and use only Btrfs Assistant GUI or snapper CLI.${RC}"
printf "%b\n" "${CYAN}Notice: grub-btrfs may cause problems with booting into snapshots and other OSes on systems with secure boot/tpm. You will be asked to apply mitigation for this issue in next step.${RC}"

while true; do
printf "%b" "${YELLOW}Do you want to install grub-btrfs? Press (y) for yes, (n) for no, (f) to apply tpm mitigation to already installed grub-btrfs: ${RC}"
read -r response
case "$response" in
[yY]*)
installGrubBtrfs
break
;;
[nN]*)
printf "%b\n" "${GREEN}Skipping grub-btrfs installation.${RC}"
break
;;
[fF]*)
mitigateTpmError
break
;;
*)
printf "%b\n" "${RED}Invalid input. Please enter 'y' for yes, 'n' for no, or (f) to apply tpm mitigation to already installed grub-btrfs.${RC}"
;;
esac
done
}

# Install grub-btrfs
installGrubBtrfs() {
# Check if the grub-btrfs dir exists before attempting to clone into it.
printf "%b\n" "${YELLOW}Downloading grub-btrfs and installing dependencies...${RC}"
if [ -d "$HOME/grub-btrfs" ]; then
rm -rf "$HOME/grub-btrfs"
fi
"$ESCALATION_TOOL" "$PACKAGER" install -y make git inotify-tools
cd "$HOME" && git clone https://github.com/Antynea/grub-btrfs
printf "%b\n" "${YELLOW}Installing grub-btrfs...${RC}"
cd "$HOME/grub-btrfs"
printf "%b\n" "${YELLOW}Modifying grub-btrfs configuration for Fedora...${RC}"
sed -i'' '/#GRUB_BTRFS_SNAPSHOT_KERNEL/a GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="systemd.volatile=state"' config
sed -i'' '/#GRUB_BTRFS_GRUB_DIRNAME/a GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"' config
sed -i'' '/#GRUB_BTRFS_MKCONFIG=/a GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig' config
sed -i'' '/#GRUB_BTRFS_SCRIPT_CHECK=/a GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check' config
"$ESCALATION_TOOL" make install
printf "%b\n" "${YELLOW}Updating grub configuration and enabling grub-btrfsd service...${RC}"
"$ESCALATION_TOOL" grub2-mkconfig -o /boot/grub2/grub.cfg && "$ESCALATION_TOOL" systemctl enable --now grub-btrfsd.service
printf "%b\n" "${YELLOW}Cleaning up installation files...${RC}"
cd .. && rm -rf "$HOME/grub-btrfs"
printf "%b\n" "${GREEN}Grub-btrfs installed and service enabled.${RC}"
printf "%b\n" "${CYAN}Notice: To perform a system recovery via grub-btrfs, perform a restore operation with Btrfs Assistant GUI after booting into the snapshot.${RC}"
mitigateTpmError
}

mitigateTpmError() {
printf "%b\n" "${YELLOW}===============================================${RC}"
printf "%b\n" "${YELLOW}Mitigation for 'tpm.c:150:unknown TPM error'...${RC}"
printf "%b\n" "${YELLOW}===============================================${RC}"
printf "%b\n" "${YELLOW}Some systems with secure boot/tpm may encounter 'tpm.c:150:unknown TPM error' when booting into snapshots.${RC}"
printf "%b\n" "${YELLOW}If you encounter this issue, you can come back later and apply this mitigation or you can apply it now.${RC}"
while true; do
printf "%b\n" "${YELLOW}Do you want to apply the TPM error mitigation? (y/n): ${RC}"
read -r response
case "$response" in
[yY]*)
printf "%b\n" "${YELLOW}Creating /etc/grub.d/02_tpm file...${RC}"
echo '#!/bin/sh' | "$ESCALATION_TOOL" tee /etc/grub.d/02_tpm > /dev/null
echo 'echo "rmmod tpm"' | "$ESCALATION_TOOL" tee -a /etc/grub.d/02_tpm > /dev/null
"$ESCALATION_TOOL" chmod +x /etc/grub.d/02_tpm # makes the file executable
"$ESCALATION_TOOL" grub2-mkconfig -o /boot/grub2/grub.cfg # updates grub config
printf "%b\n" "${GREEN}Mitigation applied and grub config updated.${RC}"
break
;;
[nN]*)
printf "%b\n" "${GREEN}Skipping TPM error mitigation.${RC}"
break
;;
*)
printf "%b\n" "${RED}Invalid input. Please enter 'y' for yes or 'n' for no.${RC}"
;;
esac
done
}

# Post install information
someNotices() {
printf "%b\n" "${YELLOW}================================NOTICES================================${RC}"
printf "%b\n" "${YELLOW}Notice: You can manage snapshots from GUI with Btrfs Assistant or CLI with snapper.${RC}"
printf "%b\n" "${YELLOW}Notice: You may change (Hourly, daily, weekly, monthly, yearly) timeline settings with Btrfs Assistant GUI.${RC}"
printf "%b\n" "${RED}Notice: If you used the default Fedora disk partitioning during OS installation, the /boot configured as an separate EXT4 partition. Therefore, it cannot be included in root snapshots. Backup separately...${RC}"
printf "%b\n" "${YELLOW}================================NOTICES================================${RC}"
printf "%b\n" "${GREEN}Setup process completed.${RC}"
}

checkEnv
checkEscalationTool
installBtrfsStack
configureSnapper
serviceStartEnable
askInstallGrubBtrfs
someNotices
11 changes: 11 additions & 0 deletions core/tabs/system-setup/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ description = "Enables Virtualization through dnf"
script = "fedora/virtualization.sh"
task_list = "I"

[[data.entries]]
name = "Btrfs Assistant, Snapper Config, grub-btrfs"
description = "Installs Btrfs Assistant, Snapper, dnf snapper plugin and takes the first root(/) and /home snapshots. Enables snapper-timeline and snapper-cleanup services. Installs Grub-Btrfs. Notice: To perform a system recovery via grub-btrfs, perform a restore operation with Btrfs Assistant GUI after booting into the snapshot. Notice: If you used the default Fedora disk partitioning during OS installation, the /boot configured as an separate EXT4 partition. Therefore, it cannot be included in root snapshots. Backup separately."
script = "fedora/fedora-btrfs-assistant.sh"
task_list = "I PFM SS"

[[data.preconditions]]
matches = true
data = "command_exists"
values = [ "btrfs" ]

[[data]]
name = "Build Prerequisites"
description = "This script is designed to handle the installation of various software dependencies across different Linux distributions"
Expand Down
1 change: 1 addition & 0 deletions docs/userguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ To know more about AUR helpers visit: https://wiki.archlinux.org/title/AUR_helpe
That software is provided as precompiled RPMs for all current Fedora versions and current Red Hat Enterprise Linux or clones versions; you can use the RPM Fusion repositories with tools like yum and PackageKit.
For more information visit: https://rpmfusion.org/
- **Virtualization**: Enables Virtualization through dnf
- **Btrfs Assistant, Snapper Config, grub-btrfs**: Installs Btrfs Assistant, Snapper, dnf snapper plugin and takes the first root(/) and /home snapshots. Enables snapper-timeline and snapper-cleanup services. Installs Grub-Btrfs. Notice: To perform a system recovery via grub-btrfs, perform a restore operation with Btrfs Assistant GUI after booting into the snapshot. Notice: If you used the default Fedora disk partitioning during OS installation, the /boot configured as an separate EXT4 partition. Therefore, it cannot be included in root snapshots. Backup separately.
- **Build Prerequisites**: This script is designed to handle the installation of various software dependencies across different Linux distributions
- **Full System Cleanup**: This script is designed to remove unnecessary packages, clean old cache files, remove temporary files, and to empty the trash.
- **Full System Update**: This command updates your system to the latest packages available for your distro
Expand Down