Skip to content

Commit

Permalink
docker desktop with macos apfs case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Oct 11, 2023
1 parent af4f04c commit cc678cf
Show file tree
Hide file tree
Showing 29 changed files with 368 additions and 17 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

请访问 [readthedocs平台上的云图](https://cloud-atlas.readthedocs.io/zh_CN/latest/index.html) 以便获得最佳阅读体验。

由于工作原因,目前重点撰写容器技术相关章节,预计将首先撰写:

* [Docker Atlas](https://cloud-atlas.readthedocs.io/zh_CN/latest/docker/index.html)
* [Kubernetes Atlas](https://cloud-atlas.readthedocs.io/zh_CN/latest/kubernetes/index.html)

## 这本书的目标

大概在两年前,萌生了以开源技术构建自动化部署和交付数据中心的想法。
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions source/apple/macos/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ macOS
restore_launchpad.rst
macos_ftdi_serial.rst
macos_vnc.rst
macos_filesystem.rst
macos_apfs_case-sensitive.rst
extfs.rst
vlc_play_bluray.rst

Expand Down
42 changes: 42 additions & 0 deletions source/apple/macos/macos_apfs_case-sensitive.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. _macos_apfs_case-sensitive:

====================
macOS区分大小写APFS
====================

当我在 :ref:`ubuntu_tini_image` 的容器中 :ref:`install_anaconda` ,遇到了一个和底层文件系统 ``区分大小写`` 兼容性问题:

- macOS的 APFS 在操作系统安装时,默认配置了 ``case insensitive`` ,也就是不区分大小写
- 当使用 :ref:`docker_volume` 将macOS上的文件系统目录映射到容器内部时,由于Linux文件系统是区分大小写的,所以在一些情况下会出现错乱,例如 :ref:`install_anaconda` 安装报错,类似找不到文件等情况

验证方法可以采用类似如下:

.. literalinclude:: macos_apfs_case-sensitive/check_filesystem_case_sensitive
:caption: 检查文件系统是否区分大小写,在 ``case insensitive`` 的APFS文件系统上现象

创建新的 ``case sensitive`` 文件系统
=======================================

:ref:`apfs` 使用了 Containter 容器来分隔文件系统,类似于 :ref:`zfs` 和 :ref:`btrfs` 的子卷

.. note::

虽然 macOS 内置的 ``Disk Utility`` 也能够创建分区,但是APFS并不推荐使用分区:

- 类似 :ref:`zfs` ,整个磁盘都是一个大的存储池,只需要通过子卷来分隔系统,可以充分使用磁盘
- 只有在同一个Mac上安装其他操作系统,如Linux时候,才需要使用分区创建

- 在APFS上添加子卷:

.. figure:: ../../_static/apple/macos/apfs_add_subvolume.png

添加子卷

注意创建子卷要选择 ``APFS (Case-sensitive)`` 格式:

.. figure:: ../../_static/apple/macos/apfs_add_subvolume_case_sensitive.png

添加区分字符大小写的子卷

现在,就可以重新创建 :ref:`ubuntu_tini_image` 的运行容器,映射新创建的区分大小写文件系统到容器内部,就不会导致Linux文件的问题

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ cd /home2/testing/anaconda3
$ echo A > A
$ echo a > a
$ cat a
a
$ cat A
a
49 changes: 49 additions & 0 deletions source/apple/macos/macos_filesystem.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. _macos_filesystem:

=====================
macOS 文件系统
=====================

.. _apfs:

APFS
========

现代macOS 从 10.14 版本开始,默认使用 ``APFS`` (Apple File System)。这个现代文件系统是从 macOS High Sierra 10.13 (2017年) 阿开始引入,现在已经广泛用于Apple的产品,包括 Macs, iPhone, iPad, Apple Watches 和 Apple TV。

APFS是针对闪存和固态驱动器设计的文件系统,并针对 ``HFS+`` 文件系统做了改进,提供了很多数据一致性和存储空间节约的功能:

- 使用了 Copy-on-Write(CoW, 写时复制)技术,极大降低了数据损坏的风险
- APFS使用 ``容器`` (Container) 作为存储数据的关键要素(principal element):

- 一个单一容器可以保存多个卷(文件系统)并共享存储空间
- 有关容器的块数量,块大小等信息被保存在Container Superblock,也就是作为每个卷的入口点
- 通过一个公共的位图(Bitmap)来帮助跟踪整个容器中块的分配

- 与此同时,卷也有自己的卷超级块(Volume Superblocks)以及存储数据和元数据的独立结构:

- 所有文件和目录都被一个二进制搜索树结构所管理,也就是文件和目录的 ``B-Trees`` (类似 :ref:`btrfs` ?)
- 树的节点(nodes)存储键和值(keys and values)

.. _hfs+:

HFS+
=========

HFS+ (Hierarchical File System Plus) 也称为 Mac OS 扩展文件系统,是Mac OS 8.1 发布的默认文件系统。不过从 macOS High Sierra 10.13开始被APFS取代。

HFS+文件系统采用了日志机制来防止结构损坏:

- 所有文件系统修改都记录在日志区域,这样在发生意外(如断电)时可以立即恢复
- HFS+的核心结构式卷标头(Volume Header),也就是在HFS+卷开头,包含了一般FS参数以及其他关键元素的位置

- 大多数服务信息被组织成特殊文件
- 这些特殊文件可以在卷的不同部分找到,摒弃主要由B树表示

- HFS+的整个存储空间被分成相等的分配块,每个分配块的状态都记录在类似位图的分配文件中
- 文件的块会分配到连续的组以降低碎片

参考
=====

- `The file systems of macOS <https://www.ufsexplorer.com/articles/macos-file-systems/>`_
2 changes: 1 addition & 1 deletion source/apple/vmware/vmware_fusion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Fusion 12
VMware Fusion克隆虚拟机
=========================

:ref:`clone_vm` 类似,在VMware Fusion中,不仅支持快速clone虚拟机,而且借助macOS的 `APFS <https://github.com/huataihuang/cloud-atlas-draft/blob/master/develop/mac/apfs.md>`_ 可以实现秒速复制,即 ``copy-on-write`` ,可以极大节约磁盘空间消耗。
:ref:`clone_vm` 类似,在VMware Fusion中,不仅支持快速clone虚拟机,而且借助macOS的 :ref:`apfs` 可以实现秒速复制,即 ``copy-on-write`` ,可以极大节约磁盘空间消耗。

.. note::

Expand Down
27 changes: 23 additions & 4 deletions source/linux/admin/cron.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Unix/Linux系统的cron服务是一个非常重要的系统服务,提供了定

``cron`` 作为定时任务配置服务,可以通过 ``crontab`` 进行交互式编辑,或者通过 ``/etc/cron.d/`` 目录下配置文件设置,此外 cron 服务还会检查 ``/var/spool/cron`` 目录下配置文件和 ``/etc/anacrontab`` 配置文件。

独立用户的 ``cron`` 文件位于 ``/var/spool/cron`` 目录下配置文件;而系统服务和应用程序通常把cron任务配置存放在 ``/etc/cron.d`` 目录。至于 ``/etc/anacrontab`` 是一个特殊配置。
独立用户的 ``cron`` 文件位于 ``/var/spool/cron`` 目录下配置文件,例如 ``root`` 用户的独立配置文件就是 ``/var/spool/cron/crontabs/root``

而系统服务和应用程序通常把cron任务配置存放在 ``/etc/cron.d`` 目录。至于 ``/etc/anacrontab`` 是一个特殊配置。

使用crontab
===========
Expand Down Expand Up @@ -58,6 +60,10 @@ cron配置定时的案例
# | | | | |
# * * * * * user-name command to be executed

.. note::

只有 ``/etc/crontab`` 和 ``/etc/cron.d/`` 目录下的配置文件有一个 ``user-name`` 字段,可以用来配置执行命令的属主

- 每天凌晨 ``01:01`` 运行一次脚本

.. code:: bash
Expand Down Expand Up @@ -111,6 +117,18 @@ cron运行脚本
...
在 ``cron`` 中切换用户身份运行脚本
=====================================

在上文中,我们已经看到了 ``/etc/crontab`` 和 ``/etc/cron.d/`` 目录下的配置文件有一个 ``user-name`` 字段,可以用来配置执行命令的属主

可以结合 :ref:`sudo` 来实现整个命令管道中不同命令执行身份的切换,例如 :ref:`node_exporter_smartctl_text_plugin` 采用了配置 ``/etc/cron.d/node_exporter_textfile_collector`` 通过 ``|`` 管道连接命令,且不同命令采用了不同用户身份:

.. literalinclude:: ../../kubernetes/monitor/prometheus/prometheus_exporters/node_exporter_textfile-collector/node_exporter_textfile_collector
:language: bash
:caption: 配置定时执行 ``node_exporter`` 的 ``textfile`` Collectors
:emphasize-lines: 5

限制cron访问
============

Expand Down Expand Up @@ -247,6 +265,7 @@ anacron快捷方式
参考
====

- `How to use cron in Linux <https://opensource.com/article/17/11/how-use-cron-linux>`_
- `What is the difference between cron.d (as in /etc/cron.d/) and crontab? <https://unix.stackexchange.com/questions/417323/what-is-the-difference-between-cron-d-as-in-etc-cron-d-and-crontab>`_
- `CronHowto <https://help.ubuntu.com/community/CronHowto>`_
- `How to use cron in Linux <https://opensource.com/article/17/11/how-use-cron-linux>`_
- `What is the difference between cron.d (as in /etc/cron.d/) and crontab? <https://unix.stackexchange.com/questions/417323/what-is-the-difference-between-cron-d-as-in-etc-cron-d-and-crontab>`_
- `CronHowto <https://help.ubuntu.com/community/CronHowto>`_
- `crontab running as a specific user <https://serverfault.com/questions/352835/crontab-running-as-a-specific-user>`_
2 changes: 1 addition & 1 deletion source/linux/redhat_linux/systemd/systemd-nspawn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ systemd-nspawn
参考
======

- `archlinxu: systemd-nspawn <https://wiki.archlinux.org/title/Systemd-nspawn>`_
- `archlinux: systemd-nspawn <https://wiki.archlinux.org/title/Systemd-nspawn>`_
- `On Running systemd-nspawn Containers <https://benjamintoll.com/2022/02/04/on-running-systemd-nspawn-containers/>`_
- `systemd-nspawn — Spawn a command or OS in a light-weight container <https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html>`_
- `How to build LineageOS inside a container <https://dzx.fr/blog/how-to-build-lineageos-inside-a-container/>`_
5 changes: 5 additions & 0 deletions source/machine_learning/deep_learning/dl_basics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _dl_basics:

=================
深度学习基础知识
=================
28 changes: 28 additions & 0 deletions source/machine_learning/deep_learning/dl_learn_tips.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _dl_learn_tips:

===================
深度学习的学习Tips
===================

.. note::

实际上网上能够找到大量的学习线路指南,我这里综合对比记录一些可能有用的资料,以备后续参考学习

入门
======

- 深度学习入门: 以 **斋藤康义** 的 「深度学习入门: 基于Python的理论与实现」 来起步,同时参考学习

- `CS230 Deep Learning <https://cs230.stanford.edu/>`_ (吴恩达教授)
- `CS231n: Deep Learning for Computer Vision <http://cs231n.stanford.edu/>`_ (李飞飞教授)

网友整理资料汇总
=================

- `ML system 入坑指南 <https://fazzie-key.cool/2023/02/21/MLsys/>`_ 关于机器学习和深度学习资料,太多

自然语言处理(NLP)
====================

- `斯坦福 XCS224U:自然语言理解 (2023)课程(YouTube) <https://www.youtube.com/playlist?list=PLoROMvodv4rOwvldxftJTmoR3kRcWkJBp>`_
- `斯坦福 Stanford CS224N NLP with Deep Learning |Spring 2022(YouTube) <https://www.youtube.com/watch?v=4ynrGLIuPv4>`_
22 changes: 22 additions & 0 deletions source/machine_learning/deep_learning/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _deep_learning:

=================================
深度学习
=================================

「不闻不若闻之,闻之不若见之,见之不若知之,知之不若行之」 -- 荀子「儒效篇」

.. toctree::
:maxdepth: 1

dl_basics.rst
../startup/install_anaconda.rst
../startup/ml_python.rst
dl_learn_tips.rst

.. only:: subproject and html

Indices
=======

* :ref:`genindex`
4 changes: 3 additions & 1 deletion source/machine_learning/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Machine Learning Atlas
.. toctree::
:maxdepth: 1

gpt/index
startup/index
deep_learning/index
gpt/index
llm/index
studio/index
hardware/index
jetson/index
Expand Down
15 changes: 15 additions & 0 deletions source/machine_learning/llm/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. _llm:

=================================
LLM 大型语言模型
=================================

.. toctree::
:maxdepth: 1

.. only:: subproject and html

Indices
=======

* :ref:`genindex`
77 changes: 73 additions & 4 deletions source/machine_learning/startup/install_anaconda.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,95 @@
安装Anaconda
====================

Linux
=========

.. note::

安装运行环境是 :ref:`fedora` ,我在本文实践基础上,构建 :ref:`fedora_tini_image` 包含Anaconda
安装运行环境是 :ref:`fedora` 和 :ref:`ubuntu_linux`

我在本文实践基础上,构建 :ref:`fedora_tini_image` 和 :ref:`ubuntu_tini_image` 部署Anaconda

- 下载Anaconda Installer并执行安装:

.. literalinclude:: install_anaconda/anaconda.sh
:language: bash
:caption: 下载和运行Anaconda Installer

按照提示接受license并且按照默认执行 ``init`` 即可
按照提示接受license并且按照默认执行 ``init`` 即可。默认安装在 ``$HOME/anaconda3`` 目录下:

.. literalinclude:: install_anaconda/anaconda_init
:caption: Anaconda安装最后的init步骤,自动更新shell profile以便自动初始化conda
:emphasize-lines: 12

- 再次登陆系统,或者直接执行::

source ~/.bashrc

此时就进入了Anaconda的 :ref:`virtualenv` 就可以使用 ``conda`` 命令,例如 ``conda list`` 可以查看安装好的Anaconda包
此时就进入了Anaconda的 :ref:`virtualenv` 就可以使用 ``conda`` 命令,例如 ``conda list`` 可以查看安装好的Anaconda包:

.. literalinclude:: install_anaconda/conda_list
:caption: 再次登陆到anaconda环境中可以看到 :ref:`virtualenv` 环境下可以使用 ``conda list`` 这样的命令
:emphasize-lines: 1

安装错误处理
--------------

我在 :ref:`ubuntu_tini_image` 环境部署 anaconda 时遇到报错:

.. literalinclude:: install_anaconda/ubuntu_install_anaconda_err
:caption: :ref:`ubuntu_tini_image` 环境部署 Anaconda 报错
:emphasize-lines: 24

这个问题在 `Error related to ncurses-6.2 when installing conda on an Ubuntu server (16.04.7 LTS) #12089 <https://github.com/ContinuumIO/anaconda-issues/issues/12089>`_ 有人已经指出了: 当在Docker中运行时,需要确保底层文件系统是和Linux一致的 ``区分大小写`` 文件系统。

我在 :ref:`docker_desktop` for :ref:`macos` 上部署 :ref:`ubuntu_tini_image` ,恰好就是将共享卷建立在 ``case insensitive`` 的 :ref:`apfs` 上导致上述问题。解决方法是 :ref:`macos_apfs_case-sensitive` (通过新增APFS Container可以实现无需重装系统就隔离出一个区分大小写的卷)

GUI包
------

Anaconda的GUI软件包依赖Qt,在各大Linux发行版需要安装以下软件包:

- Debian:

.. literalinclude:: install_anaconda/debian_anaconda_gui_prerequisites
:caption: Debian发行版安装Anaconda的GUI依赖软件包

- RedHat:

.. literalinclude:: install_anaconda/redhat_anaconda_gui_prerequisites
:caption: RedHat发行版安装Anaconda的GUI依赖软件包

- ArchLinux:

.. literalinclude:: install_anaconda/arch_anaconda_gui_prerequisites
:caption: ArchLinux发行版安装Anaconda的GUI依赖软件包

- OpenSuse/SLES:

.. literalinclude:: install_anaconda/suse_anaconda_gui_prerequisites
:caption: OpenSuse/SLES发行版安装Anaconda的GUI依赖软件包

- Gentoo:

.. literalinclude:: install_anaconda/gentoo_anaconda_gui_prerequisites
:caption: Gentoo发行版安装Anaconda的GUI依赖软件包

macOS
========

Anaconda官方提供了 :ref:`macos` 的 Intel 和 M1/M2 安装包( ``.pkg`` ) ,安装提供了 ``仅在当前用户下安装`` 和 ``系统级别安装`` 两种方式。

更新
=======

- 在Anaconda环境中,可以对整个Anaconda系统更新:

.. literalinclude:: install_anaconda/conda_update
:caption: 更新Anaconda

参考
=======

- `Anaconda Documentation: Installing on Linux <https://docs.anaconda.com/anaconda/install/linux/>`_ 官方文档
- `How To Install Anaconda on Fedora 37/36/35 <https://tecadmin.net/how-to-install-anaconda-on-fedora/>`_
- `Anaconda Documentation: Installing on Linux <https://docs.anaconda.com/anaconda/install/linux/>`_
5 changes: 4 additions & 1 deletion source/machine_learning/startup/install_anaconda/anaconda.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh
curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.09-Linux-x86_64.sh

#curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-aarch64.sh

chmod +x anaconda.sh
bash anaconda.sh

Expand Down

0 comments on commit cc678cf

Please sign in to comment.