Thread: HowTO: Btrfs Root Installation
howto: btrfs root installation
foreword
btrfs new copy on write file system linux aimed @ implementing advanced features while focusing on fault tolerance, repair , easy administration. developed oracle, btrfs licensed under gpl , open contribution anyone.
linux has wealth of file systems choose from, facing number of challenges scaling large storage subsystems becoming common in today's data centers. file systems need scale in ability address , manage large storage, , in ability detect, repair , tolerate errors in data stored on disk.
source: http://btrfs.wiki.kernel.org
the steps , procedures in guide have been tested on , work ubuntu 9.10 - karmic koala, , ubuntu 10.04 - lucid lynx. other release not guaranteed work @ all.
please bear in mind btrfs development file system, such, experience crashes, glitches, , possible loss of data. not use production use
ok, think has scared away users. crazy people remain. (you lucid users know are).
updates maverick users:
- booting btrfs system no longer requires patching of grub. long have separate partition boot (recommended format ext2), things said go smoothly.
- as of 2.6.34, btrfs has new , enhanced utility tool control , show statistics of btrfs partition. it's usage not covered in guide.
updates natty users:
- the ubuntu installer seamlessly allows use btrfs now, , grub has full support, meaning no longer necessary have separate /boot anymore.
part 1: installation
, far, simplest method convert existing installation ext3/ext4 btrfs. although installation scratch produces better behaviour , give option choosing between how file system setup - options cannot change after creation - ie: raid level.
setting base install
so, go through installation process normal, , when reach partition stage, select "advanced" option specify manually.
separate /boot
first, create /boot partition formatted ext2 - important if want boot os!
500mb in size should sufficient enough.
how go business after doesn't matter, may end afterwards.
ensure make note of file system mounted /, need info when convert it.
post installation
rest usual, , once installation complete, congratulations, easy bit done! select "continue testing" can traverse onto hard bit.
firstly, edit sources universe included in them. can done via "system -> administration -> software sources"
reload sources after closing, , next, open terminal. can begin on dirty work.
converting ext4 btrfs
the physical conversion
system installed on /dev/sda5, 1 i'll specifying in guide. if yours different, change path needed.
in order convert file system, require btrfs-tools installed.
the conversion, thankfully, elementary.code:sudo apt-get install btrfs-tools
the not elementary bit reconfiguring boot process play nice file system.code:sudo btrfs-convert /dev/sda5
first though, re-mount file systems expect them if booted it.
now chroot file system.code:sudo mount /dev/sda5 /mnt sudo mount /dev/sda1 /mnt/boot fs in proc sys dev dev/pts; sudo mount --bind /$fs /mnt/$fs; done
from here on - until reboot - run commands inside chroot.code:sudo chroot /mnt
update fstab
conversion process creates new uuid partition, such requires updating.
obtain new uuid, run:
make note, edit /etc/fstabcode:blkid /dev/sda5
i've highlighted areas of interest require changing - don't forget update file system type too.code:nano /etc/fstab
before:
after:code:# / on /dev/sda5 during installation uuid=e03cb3cc-8470-4ee6-a18a-b49da45c6f21 / ext4 error=remount-ro 0 1
hack grub2code:# / on /dev/sda5 during installation uuid=4be84d08-94cb-4013-ae0b-ce1d72d96db1 / btrfs defaults 0 1
@ current time of writing, grub2's detection method of using stat() cannot detect btrfs file system - see here why - need make grub2 detects every time run update-grub.
turns out grub0.97 can detect fine, if downgrading out of question, i've written nice little patch backports old grub detection method.
need install patch, download , setup correct diversions - don't overwritten if upgrade occur.
then open patch editingcode:apt-get install patch wget http://launchpadlibrarian.net/36483885/legacy_detection.patch dpkg-divert --local --add /usr/sbin/grub-mkconfig dpkg-divert --local --add /usr/lib/grub/grub-mkconfig_lib
and search , replace 2 lines specified below in file seen highlighted in red, ignoring rest of file.code:nano legacy_detection.patch
before:
after:code:+++ grub2-1.97~beta4/util/grub-mkconfig.in 2009-12-05 21:42:51.908543561 +0000 ... +++ grub2-1.97~beta4/util/grub-mkconfig_lib.in 2009-12-05 21:42:18.876544591 +0000
once saved, can apply patch.code:+++ /usr/sbin/grub-mkconfig 2009-12-05 21:42:51.908543561 +0000 ... +++ /usr/lib/grub/grub-mkconfig_lib 2009-12-05 21:42:18.876544591 +0000
it may give feedback on "hunk succeeded", ok. if "hunk failed", you'd know patch didn't apply expected.code:patch -p0 < legacy_detection.patch
update initramfs
next, hook btrfs boot process. helps if btrfs-tools installed first.
now start creating our files.code:apt-get install btrfs-tools
first, hook
paste in following contents , save.code:nano /usr/share/initramfs-tools/hooks/btrfs
second modulescode:#!/bin/sh -e # initramfs hook btrfs if [ "$1" = "prereqs" ]; exit 0 fi . /usr/share/initramfs-tools/hook-functions if [ -x "`which btrfsctl`" ]; copy_exec "`which btrfsctl`" /sbin fi
paste in following contents , save.code:nano /usr/share/initramfs-tools/modules.d/btrfs
last premount script.code:# initramfs modules btrfs libcrc32c crc32c zlib_deflate btrfs
paste in following contents , save.code:nano /usr/share/initramfs-tools/scripts/local-premount/btrfs
then make following files executable.code:#!/bin/sh -e # initramfs script btrfs if [ "$1" = "prereqs" ]; exit 0 fi modprobe btrfs if [ -x /sbin/btrfsctl ]; /sbin/btrfsctl -a 2>/dev/null fi
and round entire process, rebuild ramdisk , update grub.code:chmod +x /usr/share/initramfs-tools/scripts/local-premount/btrfs chmod +x /usr/share/initramfs-tools/hooks/btrfs
et voila! can reboot our system.code:update-initramfs -u -k update-grub
when boot up, can see proof of new btrfs system per below!
part 2: usage
note: if running on karmic
use of commands in section, it's recommend acquire latest release.
, if isn't enough of excuse, it's recommended because of bug fixes - see here.
have repository setup karmic correct packages inside, feel free add , install via following method.
once rebooted, recommend running:code:sudo add-apt-repository ppa:ibuclaw/ppa sudo apt-get update sudo apt-get install btrfs-tools btrfs-kernel-source sudo update-initramfs -u -k sudo reboot
before doing else. does, balance operation reads in of fs data , metadata , rewrites across file system. such, may take time.code:sudo btrfs-vol -b /
ok, done, time try out of cool things can do.
features list
incremental backup , writable snapshots
snapshots integrated file system no work done. means don't need wait around hours image created, snapshot acts more baseline, , changes live system written elsewhere on disk whilst snapshot stays static.
create snapshot of root subvolume.
the first argument snapshot name, second subvolume wish snapshot. snapshot created in directory residing in.code:cd / sudo btrfsctl -s snapshot.root / ls /snapshot.root
, exercise can try deleting , recovering files on desktop.
recover, simple 'cp -a' should trick, rsync better option.
snapshots writeable, meaning can instead change data in snapshot without affecting live system also.code:sudo cp -a /snapshot.root/home/iain/desktop ~/
can useful example, when want have chroot compiling, or running applications in own environment.
if not behaviour wish have, can chmod directory prevent normal users tampering it.code:sudo chroot /snapshot.root
lastly, delete snapshots:code:sudo chmod 700 /snapshot.root
the first argument snapshot name, second path of directory snapshot resides in.code:sudo btrfsctl -d snapshot.root /
subvolumes (separate internal file system roots)
unlike snapshots, subvolumes immutable, meaning once create one, can't removed unless reformat volume.
best use i've found subvolumes apply finer grain snapshots throughout file system, rather 1 great 1 /.
1 example can /home directory.
in recovery mode, can implemented following:
then set correct permission subvolume (default 700), , move our data in.code:cd / mv /home /home.old btrfsctl -s home /
then create snapshot:code:chmod 755 /home mv /home.old/* /home rmdir /home.old
compression , other mount optionscode:btrfsctl -s snapshot.home /home ls /snapshot.home
wouldn't recommend trying yet (although i'm pretty saw speed increase after enabling it), feel free add compress fstab file.
and remount using:code:uuid=4be84d08-94cb-4013-ae0b-ce1d72d96db1 / btrfs defaults,compress 0 1
note: compress option type of smart compression, in compress highly compressible files, off , blacklist incompressible content.code:sudo mount -o remount /
also, please bare in mind following caveats:
- if compression given set of pages fails make them smaller, file flagged avoid future compression attempts later. around this, there 'compress_force' - force compression, @ horrendous cost performance (thank-you jdong).
- the looking of actual size of compressed file unimplemented.
- with compression enabled, system may deadlock io operations if under heavy read/write duty.
see here more supported options: http://btrfs.wiki.kernel.org/index.p...#mount_options
integrated multiple device support
cool feature ability have file system spans two, or more partitions or devices.
if possible, try nice exercise see before , after of size of /
and should have increased!code:df -h / sudo mkfs.btrfs /dev/sdb sudo btrfs-vol -a /dev/sdb / df -h /
balance load between devices:
by default, meta data mirrored across 2 devices , file system data striped across of devices present.code:sudo btrfs-vol -b /
removing devices uses same logic.
and notice size of / has shrunk again.code:sudo btrfs-vol -r /dev/sdb / df -h /
more detailed it, see here.
offline file system check
self explanitory, really.
note: btrfsck not online checker. it offline only, contrary documentation said @ 1 point. running btrfsck online can lead filesystem corruption! (thank-you pointing out jdong).code:sudo btrfsck /dev/sda5
online file system defragmentation
lastly, feature has been waiting for...
the argument being location of subvolume wish defragment.code:sudo btrfsctl -d /
quite boring, really. there not progress bar.
more small hints have not included, see btrfs wiki @ http://btrfs.wiki.kernel.org/
part 3: common errors , howtos
pitfalls can avoided if treat system stable one.
ie: set system scans security updates, , checks once every fortnight.
udev failing configure
if upgrade udev, @ all, will run this.
@ point in time, have no explanation why happens, know when see it:
if fix reinstall udev. boot livecd, open terminal , mount file systems:udevadm trigger not permitted while udev unconfigured.
udevadm settle not permitted while udev unconfigured.
gave waiting root device.
chroot file systemcode:sudo mount /dev/sda5 /mnt sudo mount /dev/sda1 /mnt/boot fs in proc sys dev dev/pts; sudo mount --bind /$fs /mnt/$fs; done
and reinstall.code:sudo chroot /mnt
then reboot, , should resolved again.code:aptitude reinstall udev update-initramfs -u -k all
symlinks missing in /dev
again, cause of unknown, it's effect crop time time various applications complaining.
workaround edit /etc/rc.local
and put in following before exit 0code:sudo nano /etc/rc.local
code:find /lib/udev/devices -type l -exec cp -a "{}" /dev/ \;
general protection faults
happens when libraries have mysteriously become corrupt/altered.
see below output when x refused start @ 1 point:
the workaround reinstall affected library, in case, ran:[ 1 157.189485] xorg[2309] general protection ip:4f6e1b sp:bfd1b32c error:0 in libc-2.10.1.so[413000+142000]
code:sudo aptitude reinstall libc6 libc6-i686
gtk themes change after system update
not sure why happens, gconf database goes corrupt after big system update.
rectified running:
and logout / login.code:sudo gconftool-schemas --register-all
separate btrfs /home subvolume
covered creation of subvolumes in guide earlier. didn't cover can use them actual partitions.
going on creating subvolume /home, can go on create entry in /etc/fstab new subvolume.
and mounted separate partition every time on boot.code:# / on /dev/sda5 during installation uuid=4be84d08-94cb-4013-ae0b-ce1d72d96db1 / btrfs defaults 0 1 # /home uuid=4be84d08-94cb-4013-ae0b-ce1d72d96db1 /home btrfs defaults,subvol=home 0 1
useful when, say, need boot recovery snapshot doesn't include /home or other need partition directories.
epilogue
type this, sitting @ workstation btrfs / installation of ubuntu, compromised of 2 250gb hard drives file system spanning across both in raid0 style format. never use workstation often, downloaded 20gbs worth of native linux games odd occasions require action stimulate myself focus.
interesting idea conjured whilst writing (but haven't gotten round testing yet), may possible have separate installations of linux inside own snapshots/subvolumes.
cool - not quite amazing yet, cool. have find enjoyment in using fringe , bleeding edge technology, it's looking @ mirror reflects vision of world time in future. using btrfs on past 3 months has convinced me enough convert workstations - exception of netbook. kind of see ext4 file system on, whereas btrfs tool work done on. , while occasional fun hiccup occurs, shall regard file system glimpse of come...
tips , suggestions welcome.
thanks awesome writeup. using similar setup, had downgrade grub-legacy before, patch fixed mei'm using on laptop ssd compress option, on lucid seems faster ext4 now.
Forum The Ubuntu Forum Community Other Discussion and Support Tutorials HowTO: Btrfs Root Installation
Ubuntu
Comments
Post a Comment