Skip to content

Instantly share code, notes, and snippets.

@KFERMercer
Last active May 27, 2024 16:48
Show Gist options
  • Save KFERMercer/1372a10415d6c16972451900eea7e05f to your computer and use it in GitHub Desktop.
Save KFERMercer/1372a10415d6c16972451900eea7e05f to your computer and use it in GitHub Desktop.

make-loongnix-lxc-image

https://loongson-cloud-community.github.io/Loongson-Cloud-Community/%E7%A7%BB%E6%A4%8D%E6%89%8B%E5%86%8C/lxc-loongnixdebian

  1. Install loongnix desktop

  2. Install depends:

    apt update && apt install -y build-essential libcap-dev lxc pkg-config
  3. Build lxc and lxc-templates port by loongson:

    # build lxc
    
    git clone https://github.com/Loongson-Cloud-Community/lxc.git --depth=1 -b loongarch64-lxc-3.1.0
    
    cd lxc
    
    ./autogen.sh
    
    ./configure
    
    make
    
    make install
    # build lxc-templates
    
    git clone https://github.com/Loongson-Cloud-Community/lxc-templates.git --depth=1 -b loongarch64-lxc-templates-3.0.4
    
    cd lxc-templates
    
    ./autogen.sh
    
    ./configure
    
    make install

    You can refer to this patch to further customize the image:

    diff --git a/templates/lxc-loongnixdebian.in b/templates/lxc-loongnixdebian.in
    index 1345dcf..2ee5bcc 100644
    --- a/templates/lxc-loongnixdebian.in
    +++ b/templates/lxc-loongnixdebian.in
    @@ -40,8 +40,8 @@ else
        MIRROR=${MIRROR:-http://deb.debian.org/debian}
    fi
    SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.debian.org/}
    -LOCALSTATEDIR="@LOCALSTATEDIR@"
    -LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
    +LOCALSTATEDIR="/usr/local/var"
    +LXC_TEMPLATE_CONFIG="/usr/local/share/lxc/config"
    # Allows the lxc-cache directory to be set by environment variable
    LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"}
    
    @@ -176,6 +176,15 @@ EOF
            rm -f "$rootfs/usr/sbin/policy-rc.d"
        fi
    
    +    # more configures
    +    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' "$rootfs/etc/ssh/sshd_config"
    +
    +    chroot "$rootfs" /usr/sbin/update-rc.d -f ssh enable
    +
    +    chroot "$rootfs" apt autopurge -y
    +
    +    chroot "$rootfs" apt clean -y
    +
        # set initial timezone as on host
        if [ -f /etc/timezone ]; then
            cat /etc/timezone > "$rootfs/etc/timezone" 
  4. Fix filename shit:

    ln -s /usr/share/debootstrap/scripts/DaoXiangHu /usr/share/debootstrap/scripts/DaoXiangHu-stable
  5. Make lxc image:

    lxc-create -n <image name> -t loongnixdebian --dir=/path/to/rootfssave # <--use absolute path here!
  6. Clean-up lxc rootfs and more custom:

    cd /path/to/rootfssave
    
    # clean up:
    
    rm -rf ./var/cache/* ./tmp/* ./var/log/* ./var/tmp/* ./var/lib/apt/lists/*
  7. Export to lxc tarball:

    cd /path/to/rootfssave
    
    tar czvf ../loongnix.tar.gz ./*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment