Sofian Brabez
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Recovering personal data from ZFS after FreeBSD kernel panic ## Faulty kernel upgrade After a kernel upgrade that went very bad, the boot loader couldn't load the default kernel `/boot/kernel`. ![](https://i.imgur.com/b7ALPke.jpg) ## What about kernel.old? Of course, when something like that happens, we could rely on `/boot/kernel.old` to load the previous kernel from the boot loader, but in this case loading the previous kernel allow to boot but directly ends up with the following Kernel panic. ![](https://i.imgur.com/MS7Cfeu.jpg) ## Why a crash? Somehow, ZFS seems wrongly assume `3.5TB (35184375549952B)` of `range tree` space according the panic message. cf. [VERIFY3U macro](https://github.com/freebsd/freebsd-src/blob/master/sys/contrib/openzfs/include/os/freebsd/spl/sys/debug.h#L98) and [the rt->rt_space size test](https://github.com/freebsd/freebsd-src/blob/master/sys/contrib/openzfs/module/zfs/range_tree.c#L438) inside *range\_tree\_remove\_impl()*. Unfortunately from here nothing is possible to do except `reboot`. I didn't investigate further the root cause. ## Here comes the Live CD! [FreeSBD releases](https://www.freebsd.org/releases/12.2R/announce/) `memstick.img` images contains a running `kernel` and could be used to access the ZFS data from the `Live CD` shell. Let's prepare a USB bootable key with the image and boot from it. ``` $ fetch https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.2/FreeBSD-12.2-RELEASE-amd64-memstick.img $ dd if=FreeBSD-12.2-RELEASE-amd64-memstick.img of=/dev/da0 bs=1m conv=sync ``` ## Prepare USB boot Boot from the USB as `Multi user` (Press enter or 1), at the FreeBSD installer prompt select `Live CD` and login as as root ``` # uname -a FreeBSD 12.2-RELEASE FreeBSD 12.2-RELEASE r366954 GENERIC amd64 ``` ## Where is my data? We are looking for the partition `freebsd-zfs` ``` # gpart list ada0 # gpart show /dev/ada0 | grep zfs ``` In my case it showed as `ada0p3`. ## ZFS import ``` # kldlstat | grep -q zfs || kldload zfs # zpool list no pools available # zfs list no datasets available ``` The Live CD has a tmpfs partition mounted under `/tmp` that we could use to *write in* as mountpoint and mount our zfs datasets as `readonly` . ``` # mkdir -p /tmp/zroot # zpool import -f -o readonly=on -R /tmp/zroot zroot ``` Now our pool `zroot` is online, we could explore our datasets ``` # zpool list # zfs list -ro mounted,canmount,mountpoint,name ``` Our Personal data should be inside the user home directory referenced with the name `zroot/usr/home` and mounted in the folder `/tmp/zroot/usr/home/sbz` for me ``` # cd /tmp/zroot/user/home/sbz/ # ls .*src .bashrc .cshrc .shrc .xinitrc .mailrc .vimrc ... # dh -sh . 5.7G . ``` Great looks like all the previous files are accessible and I could start thinking about how to retrieve them and do my backup before re-installing from scratch. ## Setup Wi-Fi on the Live CD I want to use my Wi-Fi home network in order to be able to access and copy data either via SSH. For that, I need to configure the Wi-Fi and `wpa_supplicant(8)` to connect on my Access point. * Prepare and create WLAN interface ``` # kldload iwn # ifconfig wlan0 create wlandev iwn0 # ifconfig wlan0 up # load firmware # ifconfig wlan0 list scan |grep sbzAP sbzAP 04:f1:69:86:25:cb 11 54M -67:-95 100 EPS RSN WME BSSLOAD HTCAP VHTCAP VHTOPMODE ``` * Configure WPA Wireless and connect ``` # mkdir -p /tmp/etc/ # cat > /tmp/etc/wpa_supplicant.conf network={ ssid="sbzAP" psk="<key>" } ^D # wpa_supplicant -i wlan0 -c /tmp/etc/wpa_supplicant.conf -D bsd -B # dhclient wlan0 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7 DHCPOFFER from 192.168.43.1 DHCPREQUEST on wlan0 255.255.255.255 port 67 DHCPHACK from 192.168.43.1 bound to 192.168.43.211 -- renewal in 18000 seconds # ping -c 1 8.8.8.8 ``` I'm now connected on my access point `sbzAP` and I have network and can have access to Internet. ## Access the Data ### via SSH In order to access via SSH, we need to configure manually the daemon `sshd(8)` on the `Live CD` to use SSH to backup the data. * Generate Host Keys ``` # mkdir -p /tmp/etc/ssh # /usr/sbin/ssh-keygen -q -t rsa -f /tmp/etc/ssh/ssh_host_rsa_key -N '' ``` * Launch the daemon We start the SSH daemon to be able to accept connections with root user and passwordless on the local network. *We don't really need security for this case.* ``` # /usr/sbin/sshd -h /tmp/etc/ssh/ssh_host_rsa_key \ -o PermitEmptyPasswords=yes -o PermitRootLogin=yes \ -o PasswordAuthentication=yes -o UsePAM=no -D -d ``` Then with `ssh(1)` `ssh root@192.168.43.211` to connect and `scp(1)` to transfer files we could recover our data. *n.b.: I could have use zfs send but I wanted to use something simple and straight forward* **Finally, Data recovery was done successfully**

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully