LVMで管理しているボリュームをXFSからJFSに変更したときのメモです。
変更対象にrootfsが含まれているのでCDブートして新しいLVを作りデータを移行します。
こんな感じでrootfs含めてXFSでフォーマットされたLVを使っていたのですが、LXCを使うにあたりJFSに変えたくなりました。
localhost ~ # mount | grep mapper
/dev/mapper/VG00-Gentoo on / type xfs (rw,noatime,attr2,inode64,noquota)
/dev/mapper/VG00-Var on /var type xfs (rw,noatime)
/dev/mapper/VG00-Portage on /usr/portage type xfs (rw,noatime)
3.12より前のkernelではXFSとUser Namespaceを両方とも有効にすることができないからです。
(まぁ色々やりようはあると思いますが)
参考情報
rootfsのファイルシステムを変える必要があるのでCDから起動します。
CDブート時のオプションで dolvm
を指定します。
VGとLVを確認します。
livecd ~ # vgdisplay
--- Volume group ---
VG Name VG00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 18
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 148.55 GiB
PE Size 4.00 MiB
Total PE 38028
Alloc PE / Size 5376 / 21.00 GiB
Free PE / Size 32652 / 127.55 GiB
VG UUID FwMMaK-zMYd-ZL0H-HWSj-fo6w-X8uf-JJv6zl
livecd ~ # lvdisplay -c
/dev/VG00/Portage:VG00:3:1:-1:0:16777216:2048:-1:0:-1:253:0
/dev/VG00/Gentoo:VG00:3:1:-1:0:16777216:2048:-1:0:-1:253:1
/dev/VG00/SWAP00:VG00:3:1:-1:0:2097152:256:-1:0:-1:253:2
/dev/VG00/Var:VG00:3:1:-1:0:8388608:1024:-1:0:-1:253:3
空き容量は問題なさそうなので、今あるXFSでフォーマットされたLVをリネームします。
livecd ~ # lvrename VG00 Gentoo Gentoo.XFS
Renamed "Gentoo" to "Gentoo.XFS" in volume group "VG00"
livecd ~ # lvrename VG00 Var Var.XFS
Renamed "Var" to "Var.XFS" in volume group "VG00"
livecd ~ # lvrename VG00 Portage Portage.XFS
Renamed "Portage" to "Portage.XFS" in volume group "VG00"
新しくJFSでフォーマットするLVを作ります。
livecd ~ # lvcreate -n Gentoo -L8G VG00
Logical volume "Gentoo" created
livecd ~ # lvcreate -n Var -L8G VG00
Logical volume "Var" created
livecd ~ # lvcreate -n Portage -L8G VG00
Logical volume "Portage" created
JFSでフォーマットします。
livecd ~ # mkfs.jfs /dev/VG00/Gentoo
mkfs.jfs version 1.1.15, 04-Mar-2011
Warning! All data on device /dev/VG00/Gentoo will be lost!
Continue? (Y/N) y
\
Format completed successfully.
8388608 kilobytes total disk space.
livecd ~ # mkfs.jfs /dev/VG00/Var
mkfs.jfs version 1.1.15, 04-Mar-2011
Warning! All data on device /dev/VG00/Var will be lost!
Continue? (Y/N) y
\
Format completed successfully.
8388608 kilobytes total disk space.
livecd ~ # mkfs.jfs /dev/VG00/Portage
mkfs.jfs version 1.1.15, 04-Mar-2011
Warning! All data on device /dev/VG00/Portage will be lost!
Continue? (Y/N) y
\
Format completed successfully.
8388608 kilobytes total disk space.
新旧両方のrootfsをmountします。
新rootfsは /mnt/gentoo
に、旧rootfsは /mnt/gentoo.old
にmountしました。
移行対象である /var
と /usr/portage
もそれぞれmountします。
livecd ~ # mount /dev/VG00/Gentoo /mnt/gentoo/
livecd ~ # mkdir -p /mnt/gentoo.old
livecd ~ # mount /dev/VG00/Gentoo.XFS /mnt/gentoo.old/
livecd ~ # mkdir -p /mnt/gentoo/var /mnt/gentoo/usr/portage /mnt/gentoo/boot
livecd ~ # mount /dev/VG00/Var.XFS /mnt/gentoo.old/var/
livecd ~ # mount /dev/VG00/Portage.XFS /mnt/gentoo.old/usr/portage/
livecd ~ # mount /dev/VG00/Var /mnt/gentoo/var/
livecd ~ # mount /dev/VG00/Portage /mnt/gentoo/usr/portage/
mountした結果はこのようになりました。
livecd ~ # mount
rootfs on / type rootfs (rw)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=255261,mode=755)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on / type tmpfs (rw,relatime)
/dev/sr0 on /mnt/cdrom type iso9660 (ro,relatime)
/dev/loop0 on /mnt/livecd type squashfs (ro,relatime)
/dev/sr0 on /mnt/cdrom type iso9660 (ro,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,size=204936k,mode=755)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
tmpfs on /mnt/livecd/lib64/firmware type tmpfs (rw)
tmpfs on /mnt/livecd/usr/portage type tmpfs (rw)
/dev/mapper/VG00-Gentoo on /mnt/gentoo type jfs (rw)
/dev/mapper/VG00-Gentoo.XFS on /mnt/gentoo.old type xfs (rw)
/dev/mapper/VG00-Var.XFS on /mnt/gentoo.old/var type xfs (rw)
/dev/mapper/VG00-Portage.XFS on /mnt/gentoo.old/usr/portage type xfs (rw)
/dev/mapper/VG00-Var on /mnt/gentoo/var type jfs (rw)
/dev/mapper/VG00-Portage on /mnt/gentoo/usr/portage type jfs (rw)
tar
で旧rootfs以下を新rootfsに複製します。
なお、パーミッションを保持するため展開時に p
オプションを指定します。
livecd ~ # cd /mnt/gentoo
livecd gentoo # tar cf - -C /mnt/gentoo.old . | tar xfp -
livecd gentoo # ls -al
total 226964
drwxr-xr-x 20 root root 4096 Dec 12 04:29 .
drwxr-xr-x 7 root root 160 Jan 11 15:29 ..
drwxr-xr-x 2 root root 4096 Dec 26 00:20 bin
drwxr-xr-x 2 root root 1 Dec 15 15:48 boot
drwxr-xr-x 3 root root 4096 Dec 12 01:31 dev
drwxr-xr-x 36 root root 4096 Jan 11 13:15 etc
drwxr-xr-x 2 root root 8 Dec 12 01:31 home
lrwxrwxrwx 1 root root 5 Dec 12 04:29 lib -> lib64
drwxr-xr-x 3 root root 4096 Dec 15 16:07 lib32
drwxr-xr-x 13 root root 4096 Dec 26 01:10 lib64
drwxr-xr-x 2 root root 8 Dec 12 01:31 media
drwxr-xr-x 2 root root 8 Dec 12 01:31 mnt
drwxr-xr-x 2 root root 8 Dec 12 01:31 opt
-rw-r--r-- 1 root root 59183700 Dec 15 15:56 portage-latest.tar.xz
drwxr-xr-x 2 root root 1 Dec 12 01:24 proc
drwx------ 3 root root 32 Dec 29 10:40 root
drwxr-xr-x 2 root root 8 Dec 16 02:54 run
drwxr-xr-x 2 root root 4096 Dec 26 00:12 sbin
-rw-r--r-- 1 root root 173132242 Dec 15 15:53 stage3-amd64-20131212.tar.bz2
drwxr-xr-x 2 root root 8 Dec 12 01:31 sys
drwxrwxrwt 4 root root 16 Jan 11 13:12 tmp
drwxr-xr-x 13 root root 4096 Dec 12 04:48 usr
drwxr-xr-x 9 root root 88 Dec 12 01:31 var
ファイルシステムによって微妙に使用領域が変わるようです。
livecd gentoo # df -k
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 1024672 291872 732800 29% /
udev 10240 4 10236 1% /dev
tmpfs 1024672 291872 732800 29% /
/dev/sr0 264176 264176 0 100% /mnt/cdrom
/dev/loop0 236672 236672 0 100% /mnt/livecd
tmpfs 204936 492 204444 1% /run
shm 1024672 0 1024672 0% /dev/shm
tmpfs 1024672 0 1024672 0% /mnt/livecd/lib64/firmware
tmpfs 1024672 0 1024672 0% /mnt/livecd/usr/portage
/dev/mapper/VG00-Gentoo 8355380 2444984 5910396 30% /mnt/gentoo
/dev/mapper/VG00-Gentoo.XFS 8378368 2404780 5973588 29% /mnt/gentoo.old
/dev/mapper/VG00-Var.XFS 4184064 92592 4091472 3% /mnt/gentoo.old/var
/dev/mapper/VG00-Portage.XFS 8378368 1257756 7120612 16% /mnt/gentoo.old/usr/portage
/dev/mapper/VG00-Var 8355380 64152 8291228 1% /mnt/gentoo/var
/dev/mapper/VG00-Portage 8355380 1311752 7043628 16% /mnt/gentoo/usr/portage
新rootfsの /etc/fstab
を編集します。
livecd gentoo # busybox diff /mnt/gentoo.old/etc/fstab /mnt/gentoo/etc/fstab
--- /mnt/gentoo.old/etc/fstab
+++ /mnt/gentoo/etc/fstab
@@ -15,9 +15,9 @@
# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/sda1 /boot ext2 noatime 1 2
-/dev/VG00/Gentoo / xfs noatime 0 1
-/dev/VG00/Var /var xfs noatime 0 1
-/dev/VG00/Portage /usr/portage xfs noatime 0 1
+/dev/VG00/Gentoo / jfs noatime 0 1
+/dev/VG00/Var /var jfs noatime 0 1
+/dev/VG00/Portage /usr/portage jfs noatime 0 1
/dev/VG00/SWAP00 none swap sw 0 0
/dev/cdrom /mnt/cdrom auto noauto,ro 0 0
/dev/fd0 /mnt/floppy auto noauto 0 0
再起動して、
livecd gentoo # reboot && exit
logout
無事mountされていることが確認できました!
localhost ~ # mount | grep mapper
/dev/mapper/VG00-Gentoo on / type jfs (rw,noatime)
/dev/mapper/VG00-Var on /var type jfs (rw,noatime)
/dev/mapper/VG00-Portage on /usr/portage type jfs (rw,noatime)