==== Create a Swap File ====
_size=4g
_location=/
fallocate -l $_size $_location/$_size.swap
chmod 600 $_location/$_size.swap
mkswap $_location/$_size.swap
echo "$_location/$_size.swap none swap defaults 0 0" >> /etc/fstab
swapon -a
btrfs:
btrfs filesystem mkswapfile -s $_size $_location/$_size.swap
==== Mount Target System For Chroot ====
_target=/mnt
mount -t proc proc $_target/proc
mount -t sysfs sys $_target/sys
mount -o bind /dev $_target/dev
mount -t devpts pts $_target/dev/pts/
chroot $_target
==== ZSWAP ====
Configuration:
grep -r . /sys/module/zswap/parameters/
Stats:
grep -r . /sys/kernel/debug/zswap/
==== Backup/Restore ====
Refer to `df` or `mount -l`, my excludes:
/proc/*
/dev/*
/sys/*
/tmp/*
/mnt/*
/media/*
/run/*
/var/lock/*
/var/run/*
/var/log/*.gz
/var/log/**/*.gz
/var/cache/pacman/pkg/*
/home/**/.cache/chromium/*
/home/**/.ccache/*
/home/**/.avfs
/home/**/.gvfs
/lost+found
Then just `tar cf` as root(-X the excludes rule file).
Restore:
Boot livecd/liveusd, `cfdisk` and `mkfs`, then mount it(see instructions above) to /target. Then:
tar xf /path/to/your/backup.tar -C /target
or get backup and extract in pipe:
ssh user@host cat /path/to/your/backup.tar |tar x -C /target
Rsync:
# rsync -aAXvzP --delete / /target/ --exclude-from=/path/to/backup.excludes
Get UUID using `blkid` and change `/etc/fstab` of target accordingly.
If newly-installed, `chroot` into it, run `grub-install` and `update-grub`, give it a `reboot` and it would work!
Else, just update UUIDs in /boot/grub/menu.lst for grub-legacy.
==== update-grub For Grub2 ====
For those who doesn't have this:
grub-mkconfig -o /boot/grub/grub.cfg
==== Don't Stop at Grub Screen FOREVER (WTF Ubuntu) ====
echo "GRUB_RECORDFAIL_TIMEOUT=5" >> /etc/default/grub
==== Specify I/O Scheduler For Drive Specified By Partition UUID ====
echo "noop" > /sys/block/`readlink /dev/disk/by-uuid/$UUID|sed "s/.*\(sd[a-z]\).*/\1/"`/queue/scheduler
==== Install Artful Kernel (4.13) on Xenial ====
echo 'deb http://archive.ubuntu.com/ubuntu/ artful main' >> /etc/apt/sources.list.d/artful.list
echo -e 'Package: *\nPin: release a=artful\nPin-Priority: 100\n' >> /etc/apt/preferences.d/artful.pref
apt-get update
apt-get install -t artful linux-image-generic linux-generic linux-headers-generic linux-libc-dev
References:
* http://apt-blog.net/backup_or_migrate_linux_system_using_tar
* http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/
* https://axebase.net/blog/2016/12/27/zesty-kernel-in-yakkety-und-xenial/