From 08642fe930666058eef6391bcef0794aa5c01594 Mon Sep 17 00:00:00 2001 From: B3rtl Date: Mon, 11 Nov 2024 20:08:57 +0000 Subject: [PATCH] mint/make_swapvol.sh aktualisiert --- mint/make_swapvol.sh | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/mint/make_swapvol.sh b/mint/make_swapvol.sh index 4b26bc2..dca17d0 100644 --- a/mint/make_swapvol.sh +++ b/mint/make_swapvol.sh @@ -1,13 +1,29 @@ -#!/bin/sh +#!/bin/bash -TODO: Das muss noch entwickelt geteset werden +## TODO: Das muss noch entwickelt geteset werden # It is possible to use a swap file on btrfs, but there are some considerations that need taking care of. # btrfs filesystem doesn't let to create snapshots if there is a working swap file on the subvolume. That means that it is highly recommended to place a swap file on a separate subvolume. # Let's assume that the current swap is already off, the / is on /dev/sda1 and Ubuntu is installed with / on @ subvolume and /home is on @home subvolume. # Mount /dev/sda1 to /mnt. - sudo mount /dev/sda1 /mnt +rootdevsrc=$(findmnt -nr -T / -osource) +echo "Mount / ist gebunden auf $rootdevsrc" +if [[ "$rootdevsrc" =~ \[/@]$ ]] +then + echo "Verwendung von btrfs subvol /@" +else + echo "Hier stimmt was nicht. $rootdevsrc enthält kein btrfs-subvol oder subvol ist nicht '/@'" + exit 1 +fi + +rootdev=${rootdevsrc%\[/@]} + +echo "BTRFS-Device ist daher $rootdev" +echo "OK - erzeuge jetzt (etwas umständlich) ein SubVol /@swap, in dem swapfile liegt" + + +sudo mount $rootdev /mnt # If you run ls /mnt, you'll see @, @home and other subvolumes that may be there. @@ -25,7 +41,7 @@ TODO: Das muss noch entwickelt geteset werden # Mount the @swap subvolume to /swap. - sudo mount -o subvol=@swap /dev/sda1 /swap + sudo mount -o subvol=@swap $rootdev /swap # Create the swap file. @@ -36,27 +52,27 @@ TODO: Das muss noch entwickelt geteset werden sudo chmod 600 /swap/swapfile # Disable COW for this file. - - sudo chattr +C /swap/swapfile +sudo chattr +C /swap/swapfile # Set size of the swap file to 8G as an example. - sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=8192 +sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=8192 # Format the swapfile. - sudo mkswap /swap/swapfile +sudo mkswap /swap/swapfile # Turn the swap file on. - sudo swapon /swap/swapfile +sudo swapon /swap/swapfile # Now the new swap should be working. # # You also need to update /etc/fstab to mount all this on boot. Add there two lines: +echo "Update /etc/fstab mit uuid Spezifizierung" # uuid from Dev -uuid=$(lsblk -n -o UUID /dev/sda1) +uuid=$(lsblk -n -o UUID $rootdev) sudo echo "UUID=$uuid /swap btrfs subvol=@swap 0 0 /swap/swapfile none swap sw 0 0" >> /etc/fstab # The UUID is the one of your /dev/sda1. - +echo "Fertig" \ No newline at end of file