Proxmox VE + OpenMediaVault使用lxc
Last updated
Last updated
安裝 debian LXC,並修正原磁碟大小
安裝 OpenMediaVault
修改debian lxc設定
nano /etc/pve/lxc/100.conf
#加入三行設定
lxc.mount.auto: cgroup:rw
lxc.mount.auto: proc:rw
lxc.mount.auto: sys:rw
更新 LXC 並且重新啟動 LXC:
apt update && apt upgrade -y && reboot
https://openmediavault.readthedocs.io/en/latest/installation/on_debian.html
cat <<EOF >> /etc/apt/sources.list.d/openmediavault.list
deb https://packages.openmediavault.org/public usul main
EOF
自動安裝script
export LANG=C.UTF-8
export DEBIAN_FRONTEND=noninteractive
export APT_LISTCHANGES_FRONTEND=none
wget -O "/etc/apt/trusted.gpg.d/openmediavault-archive-keyring.asc" https://packages.openmediavault.org/public/archive.key
apt-key add "/etc/apt/trusted.gpg.d/openmediavault-archive-keyring.asc"
apt-get update
apt-get --yes --auto-remove --show-upgraded \
--allow-downgrades --allow-change-held-packages \
--no-install-recommends \
--option Dpkg::Options::="--force-confdef" \
--option DPkg::Options::="--force-confold" \
install openmediavault-keyring openmediavault
# Populate the database.
omv-confdbadm populate
# Display the login information.
cat /etc/issue
更新套件庫
apt update
apt install openmediavault-keyring -y
apt update
在先前建立的ZFS儲存池,建立使用omv使用的zfs磁碟
zpool list
zfs create -V 10GB local-zpool/omv-disk
透過 ls -al
發現是一個 link位置後發現是一個 link,再用 ls -al
查尋他的真實位置
ls -l /dev/zvol/local-zpool/omv-disk
lrwxrwxrwx 1 root root 9 Oct 4 14:41 /dev/zvol/local-zpool/omv-disk -> ../../zd0
fdisk /dev/zd0
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x05a590f4.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519):
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
ls -al /dev/zd0*
brw-rw---- 1 root disk 230, 0 Oct 4 14:49 /dev/zd0
brw-rw---- 1 root disk 230, 1 Oct 4 14:49 /dev/zd0p1
修改lxc的設定檔
lxc.cgroup.devices.allow: b 230:0 rwm
lxc.cgroup.devices.allow: b 230:1 rwm
lxc.autodev: 1
lxc.hook.autodev: /var/lib/lxc/100/mount-hook.sh
nano /var/lib/lxc/100/mount-hook.sh
#!/bin/sh
mknod -m 777 ${LXC_ROOTFS_MOUNT}/dev/sda b 230 0
mknod -m 777 ${LXC_ROOTFS_MOUNT}/dev/sda1 b 230 1
lxc.aa_profile = unconfined
lxc.mount.auto: cgroup:rw
lxc.mount.auto: proc:rw
lxc.mount.auto: sys:rw
lxc.cgroup.devices.allow: b 230:0 rwm
lxc.cgroup.devices.allow: b 230:1 rwm
lxc.autodev: 1
lxc.hook.autodev: /var/lib/lxc/102/mount-hook.sh
lxc.mount.entry: /dev/zd0p1 /dev/sda1 bind,create=dir,optional 0 0
chmod +x /var/lib/lxc/100/mount-hook.sh