ZFS How to mount external linux (ext4) sata disk on FreeBSD with ZFS, so the files can be accessed and copied.

Hi,

FreeBSD newbie here. My linux laptop got fatal crash after blackout that happened during system update :). Happily, I have my FreeBSD machine still operating.

What is the proper way to access and copy such data? I attached this disk to external usb dock, and confirmed with
geom disk list that it is seen by system.


Code:
Geom name: da0
Providers:
1. Name: da0
   Mediasize: 128035676160 (119G)
   Sectorsize: 512
   Mode: r0w0e0
   descr: (null)
   lunname: DB98765432534       0000
   lunid: 5031333331323758
   ident: DB98765432534
   rotationrate: unknown
   fwsectors: 63
   fwheads: 255

I can see the device in /media folder. Disk contains a whole linux distro, but i only need to copy some files. How it can be done freebsd way?
 
You have shown the disk, but you need to know what the ext4 partition is if it is partitioned:

gpart show da0

You should see the partition number under the column that refers to the device, FreeBSD incorporates a module ext2fs for ext* formats, I have never tried it since I have never had the need to access an ext* from FreeBSD.

As the manual indicates, you have to load the module, keep in mind that if you have an active security policy you will not be able to load the module in userlan "kern.secure"

kldload ext2fs

And then try to mount with the following command I assume that my partition is 4, mounted in read mode:

mount -t ext2fs -r /dev/da0p4 /mnt
 
freejlr just said what I was about to say. My post was to be finished with:

Having said all that, rescues using native tools are likely to present the least surprises. If that were my broken Linux system, I'd boot Linux from a thumb drive into rescue mode, and do the recovery using Linux, saving my files to a second thumb drive.
 
You have shown the disk, but you need to know what the ext4 partition is if it is partitioned:

gpart show da0

You should see the partition number under the column that refers to the device, FreeBSD incorporates a module ext2fs for ext* formats, I have never tried it since I have never had the need to access an ext* from FreeBSD.

As the manual indicates, you have to load the module, keep in mind that if you have an active security policy you will not be able to load the module in userlan "kern.secure"

kldload ext2fs

And then try to mount with the following command I assume that my partition is 4, mounted in read mode:

mount -t ext2fs -r /dev/da0p4 /mnt
Ok, after using your suggestions:

I used kldload ext2fs and it loaded module successfully
Code:
Id Refs Address                Size Name
 1   97 0xffffffff80200000  1d34598 kernel
 2    1 0xffffffff81f35000   5d51c8 zfs.ko
 3    1 0xffffffff8250b000     7718 cryptodev.ko
 4    1 0xffffffff82e20000   1b3920 i915kms.ko
 5    2 0xffffffff82fd4000    7c050 drm.ko
 6    1 0xffffffff83051000     22b8 iic.ko
 7    3 0xffffffff83054000     3080 linuxkpi_hdmi.ko
 8    3 0xffffffff83058000     6350 dmabuf.ko
 9    3 0xffffffff8305f000     3378 lindebugfs.ko
10    1 0xffffffff83063000     b360 ttm.ko
11    1 0xffffffff8306f000     2200 acpi_dock.ko
12    1 0xffffffff83072000     3390 acpi_wmi.ko
13    1 0xffffffff83076000     3250 ichsmb.ko
14    1 0xffffffff8307a000     2178 smbus.ko
15    1 0xffffffff8307d000     9217 if_rtwn_pci.ko
16    1 0xffffffff83087000    19140 rtwn.ko
17    1 0xffffffff830a1000     3360 uhid.ko
18    1 0xffffffff830a5000     4364 ums.ko
19    1 0xffffffff830aa000     33c0 usbhid.ko
20    1 0xffffffff830ae000     3380 hidbus.ko
21    1 0xffffffff830b2000     4d20 ng_ubt.ko
22    6 0xffffffff830b7000     abb8 netgraph.ko
23    2 0xffffffff830c2000     a250 ng_hci.ko
24    4 0xffffffff830cd000     2670 ng_bluetooth.ko
25    1 0xffffffff830d0000     e268 ng_l2cap.ko
26    1 0xffffffff830df000    1bf68 ng_btsocket.ko
27    1 0xffffffff830fb000     38f8 ng_socket.ko
28    1 0xffffffff830ff000    1aeb0 ext2fs.ko

later

gpart show da0
Code:
=>       63  250069617  da0  MBR  (119G)
         63       1985       - free -  (993K)
       2048  250065742    1  linux-data  [active]  (119G)
  250067790       1890       - free -  (945K)

Indeed in /dev/ there is a da0s1 device.

I mounted it using:
mount -t ext2fs -r /dev/da0s1 /mnt/mountfolder

the
mount command shows that it is mounted
Code:
zroot/ROOT/base on / (zfs, local, noatime, nfsv4acls)
devfs on /dev (devfs)
procfs on /proc (procfs, local)
zroot/usr/home on /usr/home (zfs, local, noatime, nfsv4acls)
zroot/tmp on /tmp (zfs, local, noatime, nosuid, nfsv4acls)
zroot/var/log on /var/log (zfs, local, noatime, noexec, nosuid, nfsv4acls)
zroot on /zroot (zfs, local, noatime, nfsv4acls)
zroot/var/audit on /var/audit (zfs, local, noatime, noexec, nosuid, nfsv4acls)
zroot/usr/ports on /usr/ports (zfs, local, noatime, nosuid, nfsv4acls)
zroot/usr/src on /usr/src (zfs, local, noatime, nfsv4acls)
zroot/var/tmp on /var/tmp (zfs, local, noatime, nosuid, nfsv4acls)
zroot/var/mail on /var/mail (zfs, local, nfsv4acls)
zroot/var/crash on /var/crash (zfs, local, noatime, noexec, nosuid, nfsv4acls)
/dev/da0s1 on /mnt/mountfolder (ext2fs, local, read-only)

However i cannot see the files. Both in thunar and in command line. Any idea what is the reason?
 
The mount looks like it worked. Are you saying that ls -la /mnt/mountfolder produces nothing?

[It's read-only at the moment, so you can't really damage it.]
 
gpart show da0
Code:
=> 63 250069617 da0 MBR (119G)
63 1985 - free - (993K)
2048 250065742 1 linux-data [active] (119G)
250067790 1890 - free - (945K)
Indeed in /dev/ there is a da0s1 device.

I mounted it using:
mount -t ext2fs -r /dev/da0s1 /mnt/mountfolder

the
mount command shows that it is mounted
Yes, you have the right idea and good commands put to use.
I am learning also, My question with the MBR partition is it /dev/da0s1 ? Okay, maybe so. I am use to GPT partitions and it would have been /dev/da0p1.

To be complete and add more confusion ( well more specific complete data )
To learn all about the disks on your computer system here is an order to use 4 commands. I added extra variations you may elect to use for a different display. The '#' and ';' are just put there in writing to make a visual separate text comment:
Code:
camcontrol devlist
geom disk list
gpart status          ;  gpart status da0
gpart show -lp     ;  gpart show -rp  ; gpart show -l  ; gpart show -r


gpart recover da0  ; # if the 2nd GPT table is missing at the end of the disk da0
df -h      #   What disks are mounted and what file space is used and available
mount   #  Which disks are mounted and what file system paths they use
ls -lh  /mnt/mountfolder
du -hs  /mnt/mountfolder
I mounted it using:
Code:
mount -t ext2fs -r  /dev/da0s1 /mnt/mountfolder
Point Thunar to root directory /mnt/mountfolder

Code:
cp -pR  /mnt/mountfolder/*   /my/new_save/directory_path/
man cp to read the details. -p keep same time and ids -R repeat through subdirectories
Glad you are here testing out and learning FreeBSD. Enjoy this great journey with rewards for learning.
 
wb7odyfred thanks!

I manged to see the files on the disk. Adding loading module to start on boot and restarting helped also.

after executing:
Code:
        cp -pR  /mnt/mountfolder/*   /my/new_save/directory_path/

I got two types of errors:
Code:
Documents/games/414011929_343302175113907_7440342185301114095_n.jpg: Input/output error

cp: Documents/games/424617192_389383887055049_5082697596475556312_n.jpg: Device not configured

Any idea why they occur? (data do not copy properly)
 
gpatrick I don't think that is the problem, the module would have to accept that type of operations, although it could be, I never used this module.

But guys, in the initial comment szelmi said that the system turned off abruptly:

My linux laptop got fatal crash after blackout that happened during system update

I may have to verify and repair the ext4 partition with fsck. I have searched the ports and it seems that FreeBSD supports this type of operation with the port sysutils/e2fsprogs you should have the fsck.ext4 binary with that port.

On the other hand I also refer to what he said gpw928 use Linux rescue if you don't want to use the ports. It also occurs to me that some sector of the disk could have been damaged, I could check it with smartctl(8)
 
Right now the file system is mounted read only, and thus quite hard to damage.

If you unmount it and run fsck, the potential for damage is significant.

The ext[24] code on FreeBSD is not particularly well regarded. There are lots of complaints about glitches. The executive summary would be "mostly OK for reading". I would never use the FreeBSD e2fsck on a Linux ext4 file system unless I was completely willing to lose the lot.

Again, I suggest that you use Linux native tools for anything other than reading from this disk (in read-only mode). It's not difficult. Just download a copy of Linux meant to boot from a thumb drive, dd it onto a thumb drive and boot it into rescue mode. Google, and the various distro docs, have plenty of advice on how to do that.
 
wb7odyfred
I got two types of errors:
Code:
Documents/games/414011929_343302175113907_7440342185301114095_n.jpg: Input/output error

cp: Documents/games/424617192_389383887055049_5082697596475556312_n.jpg: Device not configured

Any idea why they occur? (data do not copy properly)

There will be better error messages in `dmesg`.
 
Right now the file system is mounted read only, and thus quite hard to damage.

If you unmount it and run fsck, the potential for damage is significant.

The ext[24] code on FreeBSD is not particularly well regarded. There are lots of complaints about glitches. The executive summary would be "mostly OK for reading". I would never use the FreeBSD e2fsck on a Linux ext4 file system unless I was completely willing to lose the lot.

Again, I suggest that you use Linux native tools for anything other than reading from this disk (in read-only mode). It's not difficult. Just download a copy of Linux meant to boot from a thumb drive, dd it onto a thumb drive and boot it into rescue mode. Google, and the various distro docs, have plenty of advice on how to do that.
To do it in a more secure way, wouldn't it be advisable to create an image of the partition and try it or reserve it in case the disk breaks due to attempts? Example:

Code:
dd if=/dev/da0s1 bs=4096 status=progress > da0s1.img
mdconfig -a -t vnode -f da0s1.img -u md0
fsck.ext4 /dev/md0
........

I could use the disk to use a Linux distro, and have the image as a backup, or I could try to use the FreeBSD tools in a safe way.

EDIT:

In case of damaged sectors "I doubt it" dd would throw writing errors.
 
You should definitely image the disk before running anything read-write. Especially before a `fsck -y`.

There are various tools that can insert zeros instead of failed reads. dd is one of them,, but I am not quite sure whether FreeBSD's has it.

But again, first look at `dmesg`.
 
You should definitely image the disk before running anything read-write. Especially before a `fsck -y`.

There are various tools that can insert zeros instead of failed reads. dd is one of them,, but I am not quite sure whether FreeBSD's has it.

But again, first look at `dmesg`.

Yes, the options are sync and noerror, but in case of errors the block size would have to be lowered to 512 to avoid losing more sectors of the account.

Code:
dd if=/dev/da0s1 bs=512 conv=noerror,sync status=progress > da0s1.img

EDIT:

noerror would be if reading errors were found, continue with the process, sync would fill that sector with null values.

I set the block size to 4096 to increase speed, and to avoid truncation but dd apparently also has options for truncation
 
Back
Top