Thursday, October 12, 2023

How to Read ext4 in Mac OS Ventura

Accessing ext4 filesystems on macOS can be tricky due to a lack of built-in support for this Linux filesystem. But for Mac OS Ventura users, there's a neat workaround to achieve this via ext4fuse, even if the installation throws up an error like: "ext4fuse: Linux is required for this software." 

Prerequisites

Ensure you have Homebrew installed and updated on your system to facilitate the installation of other necessary tools. If not, you can install it using the following terminal command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

First, create a custom ext4fuse formula that you'll use for Homebrew. Open a text editor and save the following script as `ext4fuse.rb`:

class MacFuseRequirement < Requirement

  fatal true

  satisfy(build_env: false) { self.class.binary_mac_fuse_installed? }

  def self.binary_mac_fuse_installed?

    File.exist?("/usr/local/include/fuse/fuse.h") &&

      !File.symlink?("/usr/local/include/fuse")

  end

  env do

    ENV.append_path "PKG_CONFIG_PATH", HOMEBREW_LIBRARY/"Homebrew/os/mac/pkgconfig/fuse"

    unless HOMEBREW_PREFIX.to_s == "/usr/local"

      ENV.append_path "HOMEBREW_LIBRARY_PATHS", "/usr/local/lib"

      ENV.append_path "HOMEBREW_INCLUDE_PATHS", "/usr/local/include/fuse"

    end

  end

  def message

    "macFUSE is required. Please run `brew install --cask macfuse` first."

  end

end

class Ext4fuse < Formula

  desc "Read-only implementation of ext4 for FUSE"

  homepage "https://github.com/gerard/ext4fuse"

  url "https://github.com/gerard/ext4fuse/archive/v0.1.3.tar.gz"

  sha256 "550f1e152c4de7d4ea517ee1c708f57bfebb0856281c508511419db45aa3ca9f"

  license "GPL-2.0"

  head "https://github.com/gerard/ext4fuse.git"

  bottle do

    sha256 cellar: :any, catalina:    "446dde5e84b058966ead0cde5e38e9411f465732527f6decfa1c0dcdbd4abbef"

    sha256 cellar: :any, mojave:      "88c4918bf5218f99295e539fe4499152edb3b60b6659e44ddd68b22359f512ae"

    sha256 cellar: :any, high_sierra: "fc69c8993afd0ffc16a73c9c036ca8f83c77ac2a19b3237f76f9ccee8b30bbc9"

    sha256 cellar: :any, sierra:      "fe8bbe7cd5362f00ff06ef750926bf349d60563c20b0ecf212778631c8912ba2"

    sha256 cellar: :any, el_capitan:  "291047c821b7b205d85be853fb005510c6ab01bd4c2a2193c192299b6f049d35"

    sha256 cellar: :any, yosemite:    "b11f564b7e7c08af0b0a3e9854973d39809bf2d8a56014f4882772b2f7307ac1"

  end

  depends_on "pkg-config" => :build

  on_macos do

    depends_on MacFuseRequirement => :build

  end

  on_linux do

    depends_on "libfuse"

  end

  def install

    system "make"

    bin.install "ext4fuse"

  end

end

Steps to Install ext4fuse on Mac OS Ventura 13.6

1. Install macFUSE:

MacFUSE is essential for ext4fuse, run the following command to install it:

   brew install --cask macfuse

2. Install ext4fuse:

Use the custom formula created earlier to install ext4fuse:

 brew install --formula --build-from-source ./ext4fuse.rb

Note: Ensure you run this command from the directory where `ext4fuse.rb` is located.

3. Remove osxfuse (if applicable):

If you have osxfuse installed, it might be prudent to remove it since it has been renamed and superseded by macFUSE:

brew rm --cask osxfuse

4. Read Disk

 If you've successfully installed `ext4fuse` by following the previous instructions and you want to mount an ext4 filesystem, you would generally use a command like what you've provided. However, ensure that `/dev/disk2s1` represents the correct path to your ext4 partition. Also, remember that to mount filesystems, you might need the appropriate permissions.

Here’s a breakdown of your commands and what they do:

mkdir ext4_mount

This command creates a directory named `ext4_mount` in your current working directory. This directory will act as a mount point for the ext4 filesystem.

sudo ./ext4fuse /dev/disk2s1 ~/ext4_mount -o allow_other

This command tries to mount the ext4 filesystem found at `/dev/disk2s1` to the `ext4_mount` directory you created. The `-o allow_other` option allows other users to access the filesystem.

Note:

  1. Ensure `/dev/disk2s1` is correct for your system. You can use the `diskutil list` command to check all available drives and partitions.
  2. The `sudo` command is used to grant administrative permissions and will ask for your password.
  3. Ensure that your user has the necessary permissions to access the mount point. The `-o allow_other` flag should allow this, but ensuring the user has the right permissions on the mount point itself is also prudent.
  4. Keep in mind that `ext4fuse` is read-only, meaning you will be able to read files but not write to the ext4 filesystem.

Always remember to unmount the filesystem once you’re done using it to prevent any data corruption:

sudo umount ext4_mount

Or, if you mounted it using `FUSE`, you might need to use:

sudo diskutil umount ext4_mount

Using ext4 filesystems on macOS via `ext4fuse` allows for cross-platform data access, which can be quite handy for those using macOS and Linux environments simultaneously. Always remember to interact with filesystems and disks with caution to prevent any data loss.

Wrapping Up

Once you've gone through these steps, your macOS should be equipped to read ext4 filesystems via ext4fuse. The ability to access ext4 filesystems can be quite invaluable for cross-platform work or in scenarios where you have Linux data that you want to access on your macOS system. Ensure to check the mounted volume, and you should be able to access your ext4 data transparently on Mac OS Ventura.

For those consistently working with Linux filesystems, consider exploring additional GUI-based tools for a smoother workflow when interacting with ext4 volumes on macOS.

Source:

https://github.com/gerard/ext4fuse/issues/66

Monday, July 10, 2023

Proxmox 7 LXC Backup Failed (exit code 23)

One of my Proxmox CT backup has been unable to be saved for several days, and I'm unsure about the reason. Based on my testing, the Stop-mode backup operates effectively, while the Suspend mode does not function as intended.

Here is the log of attempted vzdump:

INFO: starting final sync /proc/180682/root/ to /mnt/storage/dump/vzdumptmp209244_1006/

INFO: resume vm

INFO: guest is online again after 3 seconds

ERROR: Backup of VM 1006 failed - command 'rsync --stats -h -X -A --numeric-ids -aH --delete --no-whole-file --inplace --one-file-system --relative '--exclude=/var/lib/php/sessions/?*' '--exclude=/tmp/?*' '--exclude=/var/tmp/?*' '--exclude=/var/run/?*.pid' /proc/180682/root//./ /mnt/storage/dump/vzdumptmp209244_1006/' failed: exit code 23

INFO: Failed at 2023-07-10 22:10:06

INFO: Backup job finished with errors

job errors

By default, for systems based on Bullseye, the 'fs.protected_regular' sysctl is set to '2' instead of the previous value of '0'. This change poses a problem for rsync's `--inplace` mode when dealing with protected files, as even the root user cannot open them with O_CREAT.

An example of this issue can be observed in Debian (or Debian-based) containers that use PHP. In these containers, the session directory '/var/lib/php/sessions' has sticky permissions, is world-writable, owned by root, and contains session files typically owned by www-data. If any of these session files are modified between the first and second rsync runs, the second run and consequently the backup operation will fail.

The solution is set fs.protected_regular in Proxmox before backup LXC (or make it permanent in /etc/sysctl.conf):

# sysctl fs.protected_regular=0

Saturday, July 1, 2023

How to Change and Move a User's Home Directory in Linux

Linux offers a robust command-line interface (CLI) with powerful tools for managing user accounts. One such command is `usermod`, which we'll focus on today. We will specifically explore how you can use it to change and move a user's home directory, ensuring a seamless transition of files.

Understanding the `usermod` Command

The `usermod` command in Linux is a utility for modifying existing user accounts. It allows you to alter various user details, including home directories, login names, and more.

Steps to Change and Move a User's Home Directory

Here's how to change a user's home directory and move its contents to the new location.

  1. Open the Terminal: This can be done by searching for 'Terminal' in your applications menu or by using the keyboard shortcut `Ctrl + Alt + T`.
  2. Switch to the root user: Type `su -` and enter your root password when prompted. Alternatively, you can prepend `sudo` to the `usermod` command if your user account is in the sudoers file.
  3. Use the `usermod` command: You can change the user's home directory and move the contents to the new directory using the following command:

usermod -m -d /newhome/username username

Here:

  • `usermod` is the command we use to modify an existing user's information.
  • `-m` (or `--move-home`) is an option that moves the contents of the user's current home directory to the new home directory.
  • `-d` (or `--home`) is the option that changes the home directory.
  • `/newhome/username` is the path to the new home directory.
  • `username` is the name of the user whose home directory you want to modify.

Remember:

  • You need to have superuser (root) permissions to use the `usermod` command.
  • Always exercise caution when making changes to system settings.
  • Also, be aware that any absolute path references in scripts or configuration files will not be updated automatically, so these may need to be changed manually.

With this knowledge, you can efficiently change and move a user's home directory in Linux, ensuring data consistency.