gentoo 用 btrfs zram 記

本帖最後由 cal22cal 於 2015-8-27 09:32 編輯

唔好話我空手套白狼, 都吹吓水咁啦,
以下有啲係 gentoo 嘢, 唔知噏乜就 skip 算, 唔好嘥時間睇

話說部ok垃圾機 up 咗去 8G ram,
又行得順咗好多,
free 返啲 hdd 位, 又起多個 vm 玩吓

btrfs pros & cons 唔吹, 不過有啲嘢又可以噏吓
有啲 distro, 都叫人 set 個 default root sysvolume
嚟 boot / , 如果要 boot old snapshot sysvolume 又要 set 過,

亦都有好多方法, e.g. 改 fstab, set 個 default root sysvolume ...
大多數都要 boot 多一次機, 先可以用個 old snapshot sysvolume
咁樣有乜方法, 可以唔洗改 fstab, 轉 boot sysvolume ...
嚟 boot 個 snapshot
好懶嘅我, 經 google 大神指示係咁, 改 fstab
  1. LABEL=XXX        /        btrfs  rw,noatime,compress=lzo,autodefrag 0 0
複製代碼
冇咗 subvol=root_subvol_name 呢個 option
注意 fstab btrfs fsck flags 係全 0

grub2 唔識, 仲係用緊 grub lagecy
冇 set 過 default subvolume
用 kernel command 嚟指定個 / sysvolume, e.g.
root filesystem 個 sysvolume 係 ROOT-FS
  1. title ROOT-FS  4.1.6-gentoo
  2. root (hd0,1)
  3. kernel /kernel-genkernel-x86_64-4.1.6-gentoo  root=UUID=xxx-xxx-xxx-xxx [color=Blue]rootflags=subvol=ROOT-FS[/color]
  4. initrd /initramfs-genkernel-x86_64-4.1.6-gentoo
複製代碼
响 /boot dir 道, 係
  1. ln -snf kernel-genkernel-x86_64-4.1.6-gentoo snap-kernel
  2. ln -snf initramfs-genkernel-x86_64-4.1.6-gentoo snap-initramfs
複製代碼
每一次 upgrade kernel 都 update 條 link 一次,
當然, menu.lst 要加 entry for new kernel

咁樣造 / snapshot 嗰時, 就造多幾個, 冇壞,
1. snapshot--time.stamp
2. snapshot--ROOT_FS_0
3. snapshot--ROOT_FS_1
play safe, 3 個完全一樣

再响 grub.conf add 多條 entry
  1. title snapshot-ROOT-FS_1
  2. root (hd0,1)
  3. kernel /snap-kernel  root=UUID=xxx-xxx-xxx-xxx [color=Blue]rootflags=subvol=snapshot-ROOT-FS_1[/color]
  4. initrd /snap-initramfs
複製代碼
咁樣就可以直 boot latest backup/snapshot root fs

小心, boot 完 backup sanpshot, 如果頭先個 ROOT-FS sysvolume
要 rollback to latest snapshot, wiki 話,
要 del 咗, 先好整 snapshot, i.e.
响 reboot 之前,
mv /path/ROOT-FS /path/problem
or
btrfs subvol delete -C /path/ROOT-FS && \
btrfs subvolume snapshot /path/snapshot-ROOT-FS_1 /path/ROOT-FS
唔好直接 overwrite

希望冇吹錯嘢啦

原本仲想吹 swap under zram, 不過太長, 下一次先算

edit:-
zram added.

btrfs 原來仲有嘢未講完,

snapshot / 個 file time stamp 唔夾 ls -lQrtHh
要 touch / 咗先做 snapshot
  1. fstab
  2. # BTRFS btrfs disk top
  3. LABEL=XXX /mnt/TOP btrfs  defaults,noauto,subvolid=0   0 0
複製代碼
  1. #!/bin/bash
  2.   mkdir -p /boot.bak.for.snapshot
  3.   mount /boot
  4. # backup /boot
  5.   echo "backup /boot  to  /boot.bak.for.snapshot"
  6.   rsync -avc --delete --exclude 'lost+found' /boot/ /boot.bak.for.snapshot
  7.   umount /boot && echo "umount /boot ... ok"

  8.   mount /mnt/TOP
  9.   btrfs subvol delete -C  /mnt/TOP/snapshot-ROOT-FS_0 && \
  10.   btrfs subvol delete -C  /mnt/TOP/snapshot-ROOT-FS_1 && \
  11.   touch /mnt/TOP/ROOT-FS && \
  12.   btrfs subvolume snapshot /mnt/TOP/ROOT-FS   /mnt/TOP/snapshot-ROOT-FS_0 && \
  13.   btrfs subvolume snapshot /mnt/TOP/ROOT-FS   /mnt/TOP/snapshot-ROOT-FS_1 && \
  14.   btrfs subvolume snapshot /mnt/TOP/ROOT-FS   /mnt/TOP/snapshot-ROOT-FS--`date +\%Y-\%m-\%d_\%H.\%M.\%S`
複製代碼
又試過用 aoe 過 file 去 vm btrfs portage,
fs 炒咗粉, 要 restore backup from external usb hdd

TOP

2. zram
  1. config ZRAM
  2.   tristate "Compressed RAM block device support"
  3.   depends on BLOCK && SYSFS && ZSMALLOC
複製代碼
响 gentoo zram wiki kernel options 少咗嘢
https://wiki.gentoo.org/wiki/Zram#Kernel_configuration
要加
  1. Processor type and features  --->
  2.   <M> Memory allocator for compressed pages
  3.   [*]   Use page table mapping to access object in zsmalloc
  4.   [*]   Export zsmalloc statistics
複製代碼
如果要 compile 大 pkg under ram disk, 可以將 /tmp 加到好大,
要 swap 就去咗 zram 嘅 swap
  1. fstab
  2. # RAM disks
  3. /dev/shm /tmp  tmpfs  size=8G,nosuid,nodev,relatime 0 0
複製代碼
當然要睇情況, 唔可以夾硬嚟
  1. cat /etc/conf.d/zram-init

  2. load_on_start="yes"
  3. unload_on_stop="yes"
  4. num_devices="1"

  5. type0="swap"
  6. flag0="" # The default "16383" is fine for us
  7. size0="1024"
  8. maxs0="4" # maximum number of parallel processes for this device
  9. algo0="lz4" # lz4 is faster than lzo
複製代碼

TOP