1. 程式人生 > >Linux下mount FreeBSD分區

Linux下mount FreeBSD分區

分區 mfs 含義 contents 1.0 mpat pre ret fragment

假設須要從第二塊硬盤復制文件。該硬盤格式化為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分區名稱。

驗證UFS分區支持

為了檢查你的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

第一行的keywordnodev含義是文件系統不須要掛載一個塊設備,這是為什麽也稱為虛擬文件系統的原因。支持也被編譯到內核中或者作為一個單獨的模塊。

檢查是否安裝ufs驅動的方法:

方法1:# cat /proc/filesystems | grep ufs

方法2:ls -l /lib/modules/`uname -r`/kernel/fs/ufs/ufs.ko

第1中方法無輸出且第2種方法文件不存在表示UFS驅動沒有編譯到內核或作為模塊安裝。

安裝UFS驅動

[email protected]:~# modprobe ufs

[email protected]:~# 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

[email protected]:~# uname -r

3.11.0-14-generic

[email protected]:~# 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 ...

掛載UFS硬盤

依賴於你的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

為了開機自己主動掛載。須要加入以下兩行到/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. 查看各個磁盤的分區信息:

[email protected]:~# 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 無法掛載

[email protected]:~# file -Ls /dev/sdb2

/dev/sdb2: x86 bootsector; partition 4: ID=0xa5, active, starthead 0,startsector 0, 50000 sectors, code offset 0x3c, BSD disklabel 無法掛載

[email protected]:~# 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

[email protected]:~# 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

Linux下mount FreeBSD分區