如果需要从第二块硬盘拷贝文件,该硬盘格式化为UFS 2文件系统,如何mount 由FreeBSD创建的UFS 2文件系统到Ubuntu系统上呢?
UFS文件系统广泛的使用在不同的操作系统(例如:HP-UX,Sun Solaris)中,包括FreeBSD。下面的语法用于挂载mount UFS 2文件系统:
mount -t ufs -o ufstype=ufs2,ro /dev/sdXY/path/to/mnt/point
每个分区包含一个文件系统存在FreeBSD中,称为一个Slice。Slice是FreeBSD中的一个术语,通常称为分区。这是因为FreeBSD具有UNIX的背景,Slice是编号的,从1开始到4。因此你需要使用等同的Linux分区名称。
为了检查你的Linux内核是否支持UFS文件系统,你可以执行下面的命令:
$ cat /proc/filesystems
输出示例:
nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev cpuset
nodev binfmt_misc
nodev debugfs
nodev securityfs
nodev sockfs
nodev usbfs
nodev pipefs
nodev anon_inodefs
nodev futexfs
nodev tmpfs
nodev inotifyfs
nodev eventpollfs
nodev devpts
ext2
nodev ramfs
nodev hugetlbfs
iso9660
nodev mqueue
ext3
nodev rpc_pipefs
nodev autofs
第一行的关键字nodev含义是文件系统不需要挂载一个块设备,这是为什么也称为虚拟文件系统的原因。支持也被编译到内核中或者作为一个单独的模块。
检查是否安装ufs驱动的方法:
方法1:# cat /proc/filesystems | grep ufs
方法2:ls -l /lib/modules/`uname -r`/kernel/fs/ufs/ufs.ko
第1中方法无输出且第2种方法文件不存在表示UFS驱动没有编译到内核或作为模块安装。
root@ubuntu:~# modprobe ufs
root@ubuntu:~# cat /proc/filesystems| grep ufs
ufs
# modinfo ufs
filename: /lib/modules/3.11.0-14-generic/kernel/fs/ufs/ufs.ko
license: GPL
alias: fs-ufs
srcversion: 961388D4E5A5AA94C372D19
depends:
intree: Y
vermagic: 3.11.0-14-generic SMP mod_unloadmodversions
root@ubuntu:~# uname -r
3.11.0-14-generic
root@ubuntu:~# ll/lib/modules/3.11.0-14-generic/kernel/fs/ufs/ufs.ko
# lsmod | grep ufs
# grep BSD_DISKLABEL /boot/config-`uname -r`
CONFIG_BSD_DISKLABEL=y
# grep UFS /boot/config-`uname-r`
CONFIG_UFS_FS=m
# dmesg |grep bsd
mount -t ufs -oufstype=sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...
依赖于你的FreeBSD的分区类型是UFS1还是UFS2,你需要引用不同的挂载选项。UFS1使用ufstype=44bsd,UFS2使用ufstype=ufs2.
为了发现FFS分区所对应的设备,运行:
# fdisk -l
# sfdisk -l
Disk /dev/hda: 155061 cylinders, 16 heads,63 sectors/track
Warning: extended partition does not startat a cylinder boundary.
DOS and Linux will interpret the contentsdifferently.
Units = cylinders of 516096 bytes, blocksof 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/hda1 * 0+ 34536- 34537- 17406396 7 HPFS/NTFS
end: (c,h,s) expected(1023,15,63) found (1023,254,63)
/dev/hda2 34536+ 134767- 100231- 50516392+ f W95 Ext‘d (LBA)
start: (c,h,s) expected(1023,15,63) found (1023,255,63)
end: (c,h,s) expected(1023,15,63) found (1023,254,63)
/dev/hda3 134767+144935- 10169- 5124735 a5 FreeBSD
start:(c,h,s) expected (1023,15,63) found (1023,255,63)
end: (c,h,s) expected (1023,15,63)found (1023,254,63)
/dev/hda4 144935+ 155060 10126- 5103189 a9 NetBSD
start: (c,h,s) expected (1023,15,63) found (1023,255,63)
end:(c,h,s) expected (1023,15,63) found (1023,80,63)
/dev/hda5 34536+ 102366- 67830- 34186288+ 83 Linux
start: (c,h,s) expected(1023,15,63) found (0,1,1)
end: (c,h,s) expected(1023,15,63) found (1023,254,63)
/dev/hda6 102366+ 104294 1929- 971901 82 Linux swap / Solaris
start: (c,h,s) expected(1023,15,63) found (0,1,1)
end: (c,h,s) expected(1023,15,63) found (120,254,63)
/dev/hda7 104295+ 134767- 30473- 15358108+ 83 Linux
start: (c,h,s) expected(1023,15,63) found (0,1,1)
end: (c,h,s) expected(1023,15,63) found (1023,254,63)
/dev/hda8 134767+143910- 9143- 4608000
/dev/hda9 143910+144935- 1026- 516735
/dev/hda10 144935+ 154078- 9143 4608072
/dev/hda11 154078+ 155060 983- 495117
/dev/hda12 0+ 34536- 34537- 17406396
/dev/hda13 34536+ 102366- 67830- 34186288+
/dev/hda14 102366+ 104294 1929- 971901
/dev/hda15 104295+ 144935- 40641- 20482843+
因此,对于FreeBSD(FFSv2),/dev/hda3等价于/dev/ad0s3
NetBSD(FFSv1),/dev/hda4等价于/dev/wd0c。
但是这些设备是整个BSD的Slice(BOIS分区),不是BSD分区。
通过仔细检查sfdisk的输出结果,我们发现/dev/hda3包含/dev/hda8和/dev/hda9,/dev/hda4包含/dev/hda10和/dev/hda11。
我们可以推出,对于FreeBSD/dev/hda8等价于/dev/ad0s3a(FreeBSD的根分区),/dev/hda9等价于/dev/ad0s3b(FreeBSD的Swap分区)。
对于NetBSD,/dev/had10等价于/dev/wd0a(NetBSD根分区),/dev/hda11等价于/dev/wd0b(NetBSD的Swap分区)。
因此FreeBSD的根分区位于/dev/hda8,首先创建一个目录用于mountFFS分区,然后挂载它。
# mkdir/mnt/freebsd
# mount -t ufs-o ro,ufstype=ufs2 /dev/hda8 /mnt/freebsd/
NetBSD的根分区位于/dev/hda10上,首先创建一个挂载FFS分区的目录,然后挂载它。
# mkdir/mnt/netbsd
# mount -t ufs-o ro,ufstype=44bsd /dev/hda10 /mnt/netbsd/
让我们浏览挂载的目录:
# ls /mnt/*bsd
/mnt/freebsd:
bin cdrom COPYRIGHT dist etc lib media proc root sys usr
boot compat dev entropy home libexec mnt rescue sbin tmp var
/mnt/netbsd:
altroot etc gnome-screensave.core mnt root var
bin GENERIC kern netbsd sbin
boot GENERIC-DIAGNOSTIC lib onetbsd stand
CUSTOM GENERIC-LAPTOP libdata proc tmp
dev GENERIC-NOACPI libexec rescue usr
为了开机自动挂载,需要添加下面两行到/etc/fstab文件中:
/dev/hda8 /mnt/freebsd ufs ufstype=ufs2,ro 0 2
/dev/hda10 /mnt/netbsd ufs ufstype=44bsd,ro 0 2
现在你能挂载FFS分区,输入:
# mount/mnt/freebsd
# mount/mnt/netbsd
并且使用下面命令验证:
$ mount
[...]
/dev/hda8 on/mnt/freebsd type ufs (ro,ufstype=ufs2)
/dev/hda10 on/mnt/netbsd type ufs (ro,ufstype=44bsd)
[...]
满足几个条件下可以支持写:
- 在Linux内核中编译选项支持写入,缺省禁用的(CONFIG_UFS_FS_WRITE=y)
- FFSV1文件系统(FFSv1)(FFSV2不支持)
请注意:一般情况下你不需要在NetBSD分区上写入,因此不要重新编译内核和测试该特性。
1.如果你忘记ro选项,你可能在dmesg中获得如下消息:
$ dmesg | grep ufs
ufs was compiled with read-only support,can‘t be mounted as read-write
2.如果你忘记设置ufstype选项,你可能在dmesg中获得下面的消息:
$ dmesg | grep ufstype
mount -t ufs -oufstype=sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...
WARNING<<< Wrong ufstype maycorrupt your filesystem, default is ufstype=old
3.卸载分区的命令:umount /mnt
# mount -t ufs-r -o ufstype=ufs2 /dev/sdb3 /mnt/sdb3
mount: wrong fstype, bad option, bad superblock on /dev/sdb3,
missing codepage or helper program, orother error
In some cases useful info is found insyslog - try
dmesg | tail or so
#dmesg | tail
[1279.960537] ufs_read_super: bad magic number
#mount -t ufs -r -o ufstype=44bsd /dev/sdb2 /mnt/sdb3
4. 查看各个磁盘的分区信息:
root@ubuntu:~# file -Ls /dev/sdb1
/dev/sdb1: x86 boot sector; partition 4:ID=0xa5, active, starthead 0, startsector 0, 50000 sectors, code offset 0x3c,BSD disklabel 无法挂载
root@ubuntu:~# file -Ls /dev/sdb2
/dev/sdb2: x86 bootsector; partition 4: ID=0xa5, active, starthead 0,startsector 0, 50000 sectors, code offset 0x3c, BSD disklabel 无法挂载
root@ubuntu:~# file -Ls /dev/sdb3 mount -o ufstype=44bsd -r -t ufs
/dev/sdb3: Unix Fast File system [v1](little-endian), last mounted on /cf, last written at Tue Nov 18 19:16:31 2014,clean flag 1, number of blocks 2104515, number of data blocks 2069056, numberof cylinder groups 82, block size 4096, fragment size 512, minimum percentageof free blocks 8, rotational delay 0ms, disk rotational speed 60rps, TIMEoptimization
root@ubuntu:~# file -Ls /dev/sdb4 mount-o ufstype=ufs2 -r -t ufs
/dev/sdb4: Unix Fast File system [v2](little-endian) last mounted on /var/log, last written at Tue Nov 18 11:16:432014, clean flag 1, readonly flag 0, number of blocks 4909865, number of datablocks 4753848, number of cylinder groups 31, block size 32768, fragment size4096, average file size 16384, average number of files in dir 64, pendingblocks to free 0, pending inodes to free 0, system-wide uuid 0, minimumpercentage of free blocks 8, TIME optimization
原文地址:http://blog.csdn.net/fan_hai_ping/article/details/41276725