Linux Emulatorを動かす

投稿者: | 2026年5月17日

今更ながら改めてLinux Emulatorに注目してみます。

前提

  • FreeBSD 15 amd64
  • RockyLinux 9.7(RHEL 9.7互換)

基本設定

roles/freebsd/tasks/linux_emulation.yaml

ファイルシステムのマウント

---
- name: Add Linux procfs
  lineinfile:
    path: /etc/fstab
    regexp: '^linproc'
    line: linproc               /compat/linux/proc      linprocfs       rw      0       0

- name: Add Linux sysfs
  lineinfile:
    path: /etc/fstab
    regexp: '^linsysfs'
    line: linsysfs      /compat/linux/sys       linsysfs        rw      0       0

- name: Add Linux devfs
  lineinfile:
    path: /etc/fstab
    regexp: '^devfs'
    line: devfs         /compat/linux/dev       devfs   rw      0       0

- name: Add Linux fdescfs
  lineinfile:
    path: /etc/fstab
    regexp: '^fdescfs'
    line: fdescfs               /compat/linux/dev/fd    fdescfs rw,linrdlnk     0       0

- name: Add Linux tmpfs
  lineinfile:
    path: /etc/fstab
    regexp: '^tmpfs'
    line: tmpfs         /compat/linux/dev/shm   tmpfs   rw,mode=1777    0       0

Linux Emulatorの有効化

- name: Enable Linux emulation
  community.general.sysrc:
    name: linux_enable
    value: "YES"

- name: Enable Linux filesystem mount
  community.general.sysrc:
    name: linux_mounts_enable
    value: "YES"

- name: Activate Linux emulation
  service:
    name: linux
    state: started
  changed_when: false

RockyLinux9ベースパッケージのインストール

- name: Ensure linux base binary installed
  community.general.pkgng:
    name: linux_base-rl9
    state: present

諸設定

roles/freebsd/tasks/linux_emulation_etc.yaml

---
- name: Ensure /tmp directory exists
  file:
    path: /compat/linux/tmp
    mode: "1777"
    state: directory

- name: Ensure /etc directory exists
  file:
    path: /compat/linux/etc
    state: directory

- name: Deploy /etc/passwd
  copy:
    dest: /compat/linux/etc/passwd
    mode: "0644"
    content: |
      root:x:0:0:root:/root:/bin/bash
      bin:x:1:1:bin:/bin:/sbin/nologin
      daemon:x:2:2:daemon:/sbin:/sbin/nologin
      adm:x:3:4:adm:/var/adm:/sbin/nologin
      lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
      sync:x:5:0:sync:/sbin:/bin/sync
      shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
      halt:x:7:0:halt:/sbin:/sbin/halt
      mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
      operator:x:11:0:operator:/root:/sbin/nologin
      games:x:12:100:games:/usr/games:/sbin/nologin
      ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
      nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
      tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin

# generated by pwconv
- name: Deploy /etc/shadow
  copy:
    dest: /compat/linux/etc/shadow
    mode: "0600"
    content: |
      root:!locked::0:99999:7:::
      bin:*:19469:0:99999:7:::
      daemon:*:19469:0:99999:7:::
      adm:*:19469:0:99999:7:::
      lp:*:19469:0:99999:7:::
      sync:*:19469:0:99999:7:::
      shutdown:*:19469:0:99999:7:::
      halt:*:19469:0:99999:7:::
      mail:*:19469:0:99999:7:::
      operator:*:19469:0:99999:7:::
      games:*:19469:0:99999:7:::
      ftp:*:19469:0:99999:7:::
      nobody:*:19469:0:99999:7:::
      tss:!!:19680::::::

- name: Deploy /etc/group
  copy:
    dest: /compat/linux/etc/group
    mode: "0644"
    content: |
      root:x:0:
      bin:x:1:
      daemon:x:2:
      sys:x:3:
      adm:x:4:
      tty:x:5:
      disk:x:6:
      lp:x:7:
      mem:x:8:
      kmem:x:9:
      wheel:x:10:
      cdrom:x:11:
      mail:x:12:
      man:x:15:
      dialout:x:18:
      floppy:x:19:
      games:x:20:
      tape:x:33:
      video:x:39:
      ftp:x:50:
      lock:x:54:
      audio:x:63:
      users:x:100:
      nobody:x:65534:
      utmp:x:22:
      utempter:x:35:
      tss:x:59:

# generated by grpconv
- name: Deploy /etc/gshadow
  copy:
    dest: /compat/linux/etc/gshadow
    mode: "0600"
    content: |
      root:::
      bin:::
      daemon:::
      sys:::
      adm:::
      tty:::
      disk:::
      lp:::
      mem:::
      kmem:::
      wheel:::
      cdrom:::
      mail:::
      man:::
      dialout:::
      floppy:::
      games:::
      tape:::
      video:::
      ftp:::
      lock:::
      audio:::
      users:::
      nobody:::
      utmp:!::
      utempter:!::
      tss:!::

- name: Deploy /etc/resolv.conf
  copy:
    dest: /compat/linux/etc/resolv.conf
    mode: "0644"
    content: |
      search {{ dns.domain | default([]) | join(' ') }}
      {% for server in dns.nameserver %}
      nameserver {{ server }}
      {% endfor %}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です