Ubuntu10.04(lucid)でnilfsをルートパーティションにする | うろ覚えのブログ

Ubuntu10.04(lucid)でnilfsをルートパーティションにする

方針としては、

  1. システムにlvmとnilfsをインストール

  2. データをバックアップ

  3. live CDで起動して、lvm, nilfsでパーティションフォーマット

  4. データリカバリー

  5. 起動できるように設定




元システムでの作業



initrdにnilfs moduleを入れておく

$ echo nilfs2 | sudo tee -a /etc/initramfs/modules
$ sudo update-initramfs -u



Grubの設定

/boot/grub/grub.cfgを見て、menuentryを探して40_customへコピー・編集。
root=UUID=xxxxxxx となっているのをLogicalVolume指定にする。

set root, searchは触らなくてよい。
(ちなみに、この2行は同じことをしているので、どちらがなくても動く)


$ cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

menuentry 'Ubuntu, with Linux 2.6.32-24-generic-pae NILFS' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,6)'
search --no-floppy --fs-uuid --set aees8dd4-c40f-49c6-a09c-1b55550a5d2d
linux /vmlinuz-2.6.32-24-generic-pae root=/dev/mapper/storage-ubuntu10root ro quiet splash
initrd /initrd.img-2.6.32-24-generic-pae
}
$ sudo update-grub2




データをバックアップ


LiveCDで起動し、パーティションサイズ(セクタ数)が全く同じパーティションを用意して、

dd if=/dev/sda7 of=/dev/sda8



lvm,nilfsフォーマット



LiveCDで起動するとlvmはそのままインストールできるが、nilfがインストールできない。

nilfs2-toolsがuniverseに含まれるため、/etc/apt/source.listのuniverseをアンコメントして、aptitudeupdate, aptitude install nilfs2-tools


$ cd /etc/apt/
$ sudo cp sources.list sources.list.orig
$ sudo vi sources.list
$ diff sources.list.orig sources.list
18c18
< # deb http://archive.ubuntu.com/ubuntu lucid universe
---
> deb http://archive.ubuntu.com/ubuntu lucid universe
$ sudo aptitude update
$ sudo aptitude install lvm2 nilfs2-tools



データリカバリー



前回のテストのようにLVM+NILFSを構築して、


$ sudo mkdir /mnt/oldsys
$ sudo mkdir /mnt/newsys
$ sudo mount -o ro /dev/sda8 /mnt/oldsys
$ sudo lvscan
inactive '/dev/storage/ubuntu10root' [18.63 GiB] inherit
$ sudo lvchange -ay /dev/storage/ubuntu10root
$ sudo mount -t nilfs2 /dev/storage/ubuntu10root /mnt/newsys
$ cd /mnt
$ sudo tar c -C oldsys . | sudo tar x -C newsys


nilfsの方がディスク使用量が一割ほど多い。(ファイルの数に差があるのはソケットがコピーされなかったため。別に問題はない。)

ubuntu@ubuntu:~$ (cd /mnt/newsys/; sudo find . ) | sort > /tmp/new.list
ubuntu@ubuntu:~$ (cd /mnt/oldsys/; sudo find . ) | sort > /tmp/old.list
ubuntu@ubuntu:~$ diff /tmp/old.list /tmp/new.list
1a2
> ./.nilfs
2954d2954
< ./home/xxx/.config/google-chrome/SingletonSocket
8321d8320
< ./tmp/orbit-gdm/linc-5a5-0-28a52d83e2324
8323,8326d8321
< ./tmp/orbit-xxx/linc-61b-0-2bed2be62072
< ./tmp/orbit-xxx/linc-682-0-5a3b708262fc6
< ./tmp/orbit-xxx/linc-693-0-281bc3aeaab8e
< ./tmp/orbit-xxx/linc-697-0-301446e3c0b6a
ubuntu@ubuntu:~$ df -h
ファイルシステム サイズ 使用 残り 使用% マウント位置
aufs 1.6G 128M 1.5G 8% /
none 1.6G 408K 1.6G 1% /dev
/dev/sr1 3.8G 3.8G 0 100% /cdrom
/dev/loop0 673M 673M 0 100% /rofs
none 1.6G 188K 1.6G 1% /dev/shm
tmpfs 1.6G 15M 1.6G 1% /tmp
none 1.6G 92K 1.6G 1% /var/run
none 1.6G 0 1.6G 0% /var/lock
none 1.6G 0 1.6G 0% /lib/init/rw
/dev/sda8 19G 3.0G 15G 17% /mnt/oldsys
/dev/mapper/storage-ubuntu10root
19G 3.3G 15G 19% /mnt/newsys



ここまでやって気づいたが、実はパーティションイメージをそのままコピーしているので、起動時に何もしなくても勝手にsda8から問題なく起動する。
考えてみればたしかにそうかも。

  • MBRから/bootの入っているパーティションをchain load

  • そこにはGRUBがある

  • GRUBではUUIDで/boot、/の含まれるパーティションを指定している

  • /bootには手を加えてないので、(当然)UUIDは変わらない

  • パーティションごとコピーしたので、/のUUIDは変わらない

  • sda7を(lvmを作るときに)破壊したので、UUIDの競合も起きない

  • /etc/fstabでは、UUIDで/, /boot, swapを指定している

  • swapも手を加えてないので、(当然)UUIDは変わらない



起動するように設定




fstab

vi /mnt/oldsys/etc/fstab

デバイス名をlvmのLogicalVolumeにする
fstypeをext4からnilfs2にする
fscheckのフラグを0にする

#
/dev/mapper/storage-ubuntu10root / nilfs2 errors=remount-ro 0 0





このぐらいやれば起動するんじゃないかと思ったが、起動しない。
やけに時間がかかったあと、Xは起動するが、The disk drive for / is not ready yet or not presentとエラーが出る。
Mを押すと修復モードに入れると出ていたのでCLIに入る
Root filesystem check failed
とエラーが出ている。

/をreadonlyでマウントしたままで終わっている模様。
そもそもnilfsにはfsckがまだ実装されていないので、fsckしようにもできないしなぁ。


このへんとかこのへんを読んでいると、バグなのか?

どちらも最近の記事なので、しばらく様子見が必要そう。


修復モードではmount -o remountrw / や mount -aを実行可能。
本意ではないが、/etc/init/mountall.confを修正した。
mount -oを追記した。


script
. /etc/default/rcS
[ -f /forcefsck ] && force_fsck="--force-fsck"
[ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix"

mount -o remount,rw /
exec mountall --daemon $force_fsck $fsck_fix
end script


これで一応Ubuntu10.04 on NILFS on LVMで起動する環境が出来上がった。
が、実は起動中に50秒ほどブランクスクリーンのまま固まったように見える時間がある。おそらくmountallあたりの処理で問題がある模様。せっかくの高速起動がウリのUbuntu10.04だけど、起動に時間がかかってしまう...