Skip to main content

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.
code:
sudo apt-get install btrfs-tools
the conversion, thankfully, elementary.
code:
sudo btrfs-convert /dev/sda5
the not elementary bit reconfiguring boot process play nice file system.

first though, re-mount file systems expect them if booted it.
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
now chroot file system.
code:
sudo chroot /mnt
from here on - until reboot - run commands inside chroot.

update fstab
conversion process creates new uuid partition, such requires updating.

obtain new uuid, run:
code:
blkid /dev/sda5
make note, edit /etc/fstab
code:
nano /etc/fstab
i've highlighted areas of interest require changing - don't forget update file system type too.
before:
code:
# / on /dev/sda5 during installation  uuid=e03cb3cc-8470-4ee6-a18a-b49da45c6f21 /             ext4    error=remount-ro 0      1
after:
code:
# / on /dev/sda5 during installation  uuid=4be84d08-94cb-4013-ae0b-ce1d72d96db1 /             btrfs   defaults         0      1
hack grub2
@ 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.
code:
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
then open patch editing
code:
nano legacy_detection.patch
and search , replace 2 lines specified below in file seen highlighted in red, ignoring rest of file.
before:
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
after:
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
once saved, can apply patch.
code:
patch -p0 < legacy_detection.patch
it may give feedback on "hunk succeeded", ok. if "hunk failed", you'd know patch didn't apply expected.

update initramfs
next, hook btrfs boot process. helps if btrfs-tools installed first.
code:
apt-get install btrfs-tools
now start creating our files.

first, hook
code:
nano /usr/share/initramfs-tools/hooks/btrfs
paste in following contents , save.
code:
#!/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
second modules
code:
nano /usr/share/initramfs-tools/modules.d/btrfs
paste in following contents , save.
code:
# initramfs modules btrfs  libcrc32c  crc32c  zlib_deflate  btrfs
last premount script.
code:
nano /usr/share/initramfs-tools/scripts/local-premount/btrfs
paste in following contents , save.
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
then make following files executable.
code:
chmod +x /usr/share/initramfs-tools/scripts/local-premount/btrfs  chmod +x /usr/share/initramfs-tools/hooks/btrfs
and round entire process, rebuild ramdisk , update grub.
code:
update-initramfs -u -k  update-grub
et voila! can reboot our system.

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.
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
once rebooted, recommend running:
code:
sudo btrfs-vol -b /
before doing else. does, balance operation reads in of fs data , metadata , rewrites across file system. such, may take time.

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.
code:
cd /  sudo btrfsctl -s snapshot.root /  ls /snapshot.root
the first argument snapshot name, second subvolume wish snapshot. snapshot created in directory residing in.

, exercise can try deleting , recovering files on desktop.
recover, simple 'cp -a' should trick, rsync better option.
code:
sudo cp -a /snapshot.root/home/iain/desktop ~/
snapshots writeable, meaning can instead change data in snapshot without affecting live system also.

can useful example, when want have chroot compiling, or running applications in own environment.
code:
sudo chroot /snapshot.root
if not behaviour wish have, can chmod directory prevent normal users tampering it.
code:
sudo chmod 700 /snapshot.root
lastly, delete snapshots:
code:
sudo btrfsctl -d snapshot.root /
the first argument snapshot name, second path of directory snapshot resides in.

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:
code:
cd /  mv /home /home.old  btrfsctl -s home /
then set correct permission subvolume (default 700), , move our data in.
code:
chmod 755 /home  mv /home.old/* /home  rmdir /home.old
then create snapshot:
code:
btrfsctl -s snapshot.home /home  ls /snapshot.home
compression , other mount options
wouldn't recommend trying yet (although i'm pretty saw speed increase after enabling it), feel free add compress fstab file.
code:
uuid=4be84d08-94cb-4013-ae0b-ce1d72d96db1 /             btrfs   defaults,compress 0      1
and remount using:
code:
sudo mount -o remount /
note: compress option type of smart compression, in compress highly compressible files, off , blacklist incompressible content.
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 /
code:
df -h /  sudo mkfs.btrfs /dev/sdb  sudo btrfs-vol -a /dev/sdb /  df -h /
and should have increased!

balance load between devices:
code:
sudo btrfs-vol -b /
by default, meta data mirrored across 2 devices , file system data striped across of devices present.

removing devices uses same logic.
code:
sudo btrfs-vol -r /dev/sdb /  df -h /
and notice size of / has shrunk again.
more detailed it, see here.

offline file system check
self explanitory, really.
code:
sudo btrfsck /dev/sda5
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).

online file system defragmentation
lastly, feature has been waiting for...
code:
sudo btrfsctl -d /
the argument being location of subvolume wish defragment.
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:
udevadm trigger not permitted while udev unconfigured.
udevadm settle not permitted while udev unconfigured.
gave waiting root device.
if fix reinstall udev. boot livecd, open terminal , mount file systems:
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
chroot file system
code:
sudo chroot /mnt
and reinstall.
code:
aptitude reinstall udev  update-initramfs -u -k all
then reboot, , should resolved again.


symlinks missing in /dev
again, cause of unknown, it's effect crop time time various applications complaining.

workaround edit /etc/rc.local
code:
sudo nano /etc/rc.local
and put in following before exit 0
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:
[ 1 157.189485] xorg[2309] general protection ip:4f6e1b sp:bfd1b32c error:0 in libc-2.10.1.so[413000+142000]
the workaround reinstall affected library, in case, ran:
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:
code:
sudo gconftool-schemas --register-all
and logout / login.


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.
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
and mounted separate partition every time on boot.

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.
attached images attached images

thanks awesome writeup. using similar setup, had downgrade grub-legacy before, patch fixed me i'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

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts