linuxfromscratch:auto-lfs

문서의 이전 판입니다!


6장 완료후 책의 끝까지 유용하게 사용하는 스크립트

사용법:
auto-lfs s : chroot 실행, 필요한 시스템 디렉토리 마운트
auto-lfs c : chroot 종료후 불필요한 시스템 디렉토리 마운트 해제

LFS, LFS_PART와 /boot, /boot/efi, /home, /sources 등은 상황에 맞게 조정이 필요합니다.

#!/bin/bash
# Begin auto-lfs
#
# For LFS 12.1-systemd
# you can use it after proceeding with <7.2 Changing Owner> 
# Mount and unmount kernel virtual file system and entering to chroot environment

LFS=/mnt/lfs
LFS_PART=/dev/nvme0n1p6
VERSION=0.1.5
# Dedicated partition mount
if mountpoint -q $LFS; then true; else mount $LFS_PART $LFS; fi
if mountpoint -q $LFS/boot; then true; else mount /dev/nvme0n1p3 $LFS/boot; fi
if mountpoint -q $LFS/boot/efi; then true; else  mount /dev/nvme0n1p1 $LFS/boot/efi; fi
if mountpoint -q $LFS/home; then true; else  mount /dev/nvme0n1p4 $LFS/home; fi

# Mount point dirctory check
if [ ! -d $LFS/dev ]; then
        echo "Make necessary directories"
        mkdir -pv $LFS/{dev,proc,sys,run}
else
        echo "All required directories have been verified."
fi

# To prepare for run 'chroot', run 'umount' block if a directory exists, or run 'mount' block
case $1 in
    clean|c|-c)
        if mountpoint -q $LFS/dev/shm; then
            # Unmount Kernel Virtual File System used in previous LFS sessions.
            echo "LFS is now set to '"$LFS"'"
            echo "Now proceed with the unmount of <Kernel Virtual File System> for chroot"
            for kvfs in dev/shm dev/pts sys proc run dev sources; do
                    umount -q $LFS/$kvfs
            done
            findmnt -o FSTYPE,SIZE,USED,AVAIL,USE%,TARGET | grep lfs
            echo "Ok unmount unnecessary devices"
            echo "Good bye"
            exit 0
        else
            echo "Cleanup of Kernel Virtual File System is Complete."
            findmnt -o FSTYPE,SIZE,USED,AVAIL,USE%,TARGET | grep lfs
            exit 0
        fi
    ;;
    start|s|-s)
        # Mount the Kernel Virtual File System to Enter LFS chroot environment.
        echo "Now proceed with the mount of <Kernel Virtual File System> for chroot"
        echo "LFS is now set to '"$LFS"'"
        if mountpoint -q $LFS/dev; then true; else mount --bind /dev $LFS/dev; fi
        if mountpoint -q $LFS/dev/pts; then true; else mount -t devpts devpts -o gid=5,mode=0620 $LFS/dev/pts; fi
        if mountpoint -q $LFS/proc; then true; else mount -t proc proc $LFS/proc; fi
        if mountpoint -q $LFS/sys; then true; else mount -t sysfs sysfs $LFS/sys; fi
        if mountpoint -q $LFS/run; then true; else mount -t tmpfs tmpfs $LFS/run; fi
        if mountpoint -q $LFS/dev/shm; then true; else mount -t tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm; fi
        if mountpoint -q $LFS/sources; then  true; else mount --bind /mnt/sources $LFS/sources; fi
        findmnt -o FSTYPE,SIZE,USED,AVAIL,USE%,TARGET | grep lfs
        # Run 'chroot'
        chroot "$LFS" $(type -p env) -i \
            HOME=/root                  \
            TERM="$TERM"                \
            PS1='<LFS> \u@\h [ \w ] \$ '\
            PATH=/usr/bin:/usr/sbin     \
            MAKEFLAGS="-j$(nproc)"      \
            TESTSUITEFLAGS="-j$(nproc)" \
            NINJAJOBS="$(nproc)"        \
            /bin/bash --login
        exit 0
    ;;
    version|v|-v)
        echo "LFS chroot script $VERSION"
        exit 0
    ;;
    help|h|-h)
        echo "LFS chroot script $VERSION"
        echo "Usage:"
        echo "clean   or c- Unmount Kernel Virtual File System"
        echo "start   or s- Mount and run 'chroot' command with necessary variables"
        echo "version or v- Print script version"
        echo "help    or h - This screen"
        exit 0
    ;;
    *)
        #Guidance on the factors needed to execute script
        echo "sh ./Auto_LFS.sh [ start | clean | help | version ]"
        exit 0
    ;;
esac


#!/bin/bash
# Packages Build prepare (change dircetory, decompress file...)
# 아래 두개의 변수를 상황에 맞게 변경해서 사용.
BuildBase=/workbench
SourceDir=/sources
wget -P $SourceDir $1
TargetFile=$(basename $1)
TargetDir=$(echo "$TargetFile" | sed -e 's/\.tar.*$//' -e 's/\.tgz*$//' -e 's/\.src*$//' -e 's/\.zip*$//' -e 's@^.*/@@')

function chg_dir() {
        cd $1
}

# Move to /workbench
if [ "$PWD" != "$BuildBase" ]; then 
        chg_dir "$BuildBase"
fi

# Prepare Package Build
if file "$TargetFile" | grep -q 'Zip archive data'; then
        mkdir -p "$TargetDir"
        chg_dir "$TargetDir"
        unzip -q "SourceDir"/"$TargetFile"
else
        tar -xf "$SourceDir"/"$TargetFile"
        chg_dir "$TargetDir"
fi

  • linuxfromscratch/auto-lfs.1714509293.txt.gz
  • 마지막으로 수정됨: 2024/04/30 20:34
  • 저자 baecy