非攻飞攻,夜尽天明!
分类: LINUX
2014-03-02 09:16:26
通常默认的,如果linux内核更新到 kernel 2.6.29, 就已经支持 UFS 文件系统的 写操作了。但是考虑到 危险性操作,一般不会直接就支持写操作。
所以,linux 系统 通常只可以 "只读 " 来挂载 UFS文件系统。
$ sudo mount -t ufs -o ufstype=ufs2 /dev/sdb5 /mnt/ mount: wrong fs type, bad option, bad superblock on /dev/sdb5, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so $ dmesg | tail -n 1 [ 871.777769] ufs was compiled with read-only support, can't be mounted as read-write 为了实现挂载上它,需要专门的 只读 标识:
$ sudo mount -t ufs -o ro,ufstype=ufs2 /dev/sdb2 /mnt/ 首先,需要下载当前系统的内核源码,然后复制当前的内核为 .config
$ sudo -s # apt-get install linux-source-2.6.27 # cd /usr/src # bzip2 -dc linux-source-2.6.27.tar.bz2 | tar xf - # cp /boot/config-2.6.27-2-686 .config
为了增加UFS 写支持到内核,去掉/增加 CONFIG_UFS_WRITE 标识在内核config ,然后从新编译它。
$ grep CONFIG_UFS_FS_WRITE /usr/src/linux-source-2.6.27/.config CONFIG_UFS_FS_WRITE=y
To compile my kernel, I followed the instruction here_ . I just added CONCURRENCY_LEVEL=2 to use the 2 cores of my CPU.
编译内核时,可是查看介绍 (followed the instruction here_) ,这里 只是添加 CONCURRENCY_LEVEL=2 来使用 双核 cpu
$ sudo -s # CONCURRENCY_LEVEL=2 make-kpkg --initrd --append-to-version=-2-686-ufs kernel-image kernel-headers 一旦编译完成,安装刚刚建立的 内核.(可以在 /usr/src 找到 .deb 文件),然后重启。
$ sudo dpkg -i /usr/src/linux-image-2.6.27-1-686-ufs_2.6.27-1-686-ufs-10.00.Custom_i386.deb
注意到一些用户:当booting 时有错误,可能时因为忘记了把 initrd 结合到内核中。这时,如果使用的时内核 kernel-package-12.009 (或者更高),确保 来使得 initrd 也同时安装(如果卸载它,删除就可) :
cp /usr/share/kernel-package/examples/etc/kernel/postinst.d/initramfs /etc/kernel/postinst.d/ cp /usr/share/kernel-package/examples/etc/kernel/postrm.d/initramfs /etc/kernel/postrm.d/
一旦启动了 “UFS-writable”内核,
$ sudo fdisk -l /dev/sdb Disk /dev/sdb: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x8f8000b1 Device Boot Start End Blocks Id System /dev/sdb1 1 1958 15727603+ 83 Linux /dev/sdb2 * 1959 4569 20972857+ a5 FreeBSD /dev/sdb3 4570 4830 2096482+ 82 Linux swap / Solaris /dev/sdb4 4831 60801 449587057+ 83 Linux 这里,/dev/sdb2 包含了 UFS 文件系统。 如果详细的查看 /dev ,就可以看到所有的信息(当然这里已经执行了"可写")
$ ls -l /dev/sdb* brw-rw---- 1 root disk 8, 16 2009-04-04 16:20 /dev/sdb brw-rw---- 1 root disk 8, 17 2009-04-04 14:20 /dev/sdb1 brw-rw---- 1 root disk 8, 18 2009-04-04 16:20 /dev/sdb2 <--- FreeBSD paartition brw-rw---- 1 root disk 8, 19 2009-04-04 16:20 /dev/sdb3 brw-rw---- 1 root disk 8, 20 2009-04-04 14:20 /dev/sdb4 brw-rw---- 1 root disk 8, 21 2009-04-04 16:20 /dev/sdb5 <--- FreeBSD / slice brw-rw---- 1 root disk 8, 22 2009-04-04 16:20 /dev/sdb6 <--- FreeBSD swap brw-rw---- 1 root disk 8, 23 2009-04-04 16:20 /dev/sdb7 <--- FreeBSD /var slice brw-rw---- 1 root disk 8, 24 2009-04-04 16:20 /dev/sdb8 <--- FreeBSD /tmp slice brw-rw---- 1 root disk 8, 25 2009-04-04 16:20 /dev/sdb9 <--- FreeBSD /usr slice
Then, I mounted the slices in the right order and to the right mount points (in /mnt/) to have my FreeBSD exact filesystem environment. Then I copied back all the data using the old and nice tar technique, as root:
# ( cd /path/to/backup && tar cpf - . ) | ( cd /mnt/ && tar xvfp - )
Once the "un"-tar was done, I rebooted on my FreeBSD system (from which I am writing this post), forced the fsck of all my slices: everything seems to be OK!
The CONFIG_UFS_FS_WRITE kernel flag is still set as experimental, but it did work like charm for me (using kernel 2.6.27).
If you do use it, and you find a bug, please report it :)
Hope this was helpful.
Cheers,
Ignace M -ghantoos-