classy-giraffe / easy-arch

Script for boostrapping Arch Linux with BTRFS, snapshots and LUKS encryption (UEFI only).
https://classy-giraffe.github.io/easy-arch
Apache License 2.0
237 stars 54 forks source link

Consider switching to encrypted swap or zram #2

Closed TommyTran732 closed 3 years ago

TommyTran732 commented 3 years ago

I don't think the way it sets up unencrypted swap right now is a good idea. I think its better to encrypt it using dmcrypt or just to switch to zram and use the same configuration as Fedora does.

classy-giraffe commented 3 years ago

All right, looking to implement it. :D

wbob commented 3 years ago

added a btrfs swapfile the other day, for a suggestion:

# optional: retroactively add a swap subvolume on an existing btrfs disk
mkdir -p /mnt/btrfs
mount /dev/mapper/cryptroot  /mnt/btrfs
cd /mnt/btrfs
btrfs subvol create @swap
umount /mnt/btrfs

mkdir -p /swap

# /etc/fstab
/dev/mapper/cryptroot /swap   btrfs   subvol=@swap,noatime,compress=no,nodatasum,nodatacow 0 0

mount -a

# man 5 btrfs
truncate -s 0 file
chattr +C file
# man mkswap
dd if=/dev/zero of=file bs=1MiB count=$((8*1024))
chmod 0600 file
mkswap file
swapon file

# /etc/fstab
/swap/file        none    swap    sw 0 0

Edit: as /swap is mounted with nodatacow and cow disabled by chattr, the use of fallocate instead of dd is fine, as initially suggested in man 5 btrfs. For a recent discussion of "swap on btrfs" see https://old.reddit.com/r/btrfs/comments/mtg3ll/swapfile_on_btrfs/

iSparsh commented 3 years ago

I am in favor of ZRAM since its reported to be better for SSDs. The Fedora implementation looks to be good.

classy-giraffe commented 3 years ago

There used to be a swapfile but the way I implemented it was kind of inefficient. @wbob

classy-giraffe commented 3 years ago

@iSparsh I'm in favor of ZRAM as well, currently I'm reading about how to implement it. Looks like there's a systemd unit for that but AUR has a package for it too.

iSparsh commented 3 years ago

I'm not sure how helpful this is but this has implementation of Zram. You can take a look at this at 24:00 minute mark roughly

iSparsh commented 3 years ago

Ok from some research i've found that zram-generator from the official repositories is the way to go. However, the script would need to leave a note (post-install) telling the user to adjust the values of zram in the config file. Is that okay @classy-giraffe

TommyTran732 commented 3 years ago

Done in https://github.com/classy-giraffe/easy-arch/pull/19

TommyTran732 commented 3 years ago

And nope, we don't need systemd-zram-generator :P

That package is nice and all, but we don't need it. I just followed the Arch wiki for this instead ;)

TommyTran732 commented 3 years ago

Okay the PR is merged so I am closing this