diff options
author | William Harrington <kb0iic@berzerkula.org> | 2021-03-22 13:37:06 -0500 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2021-03-22 13:37:06 -0500 |
commit | 70308eb464da52d1571f06eb1d739ccebd940006 (patch) | |
tree | ebcf4028850bf1c930d1326b62d3a395ba7bf111 /preparechroot.sh | |
parent | 5ad8b99e3ab66e675836c89bb6e3b935f8506cf8 (diff) |
Add prepare chroot script.
Diffstat (limited to 'preparechroot.sh')
-rw-r--r-- | preparechroot.sh | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/preparechroot.sh b/preparechroot.sh new file mode 100644 index 0000000..07b3cb3 --- /dev/null +++ b/preparechroot.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +source colors.sh + +export LFS="$1" + +if [ -z "${LFS}" ]; then + echo -e "${RED}Require first argument as path to LFS build!${RST}" + exit 1 +fi + +if [ "${USER}" == "root" ]; then + echo -e "${GRN}Changing ownership to root...${RST}" + chown -R root:root ${LFS}/bin + chown -R root:root ${LFS}/etc + chown -R root:root ${LFS}/lib + chown -R root:root ${LFS}/sbin + chown -R root:root ${LFS}/tools + chown -R root:root ${LFS}/usr + chown -R root:root ${LFS}/var + + case $(uname -m) in + x86_64) chown -R root:root ${LFS}/lib64 ;; + esac + + echo -e "${GRN}Creating virtual kernel filesystem mountpoints...${RST}" + mkdir -p ${LFS}/dev + mkdir -p ${LFS}/proc + mkdir -p ${LFS}/run + mkdir -p ${LFS}/sys + + echo -e "${GRN}Creating initial device nodes...${RST}" + mknod -m 600 ${LFS}/dev/console c 5 1 >/dev/null 2>&1 + mknod -m 666 ${LFS}/dev/null c 1 3 >/dev/null 2>&1 + + echo -e "${GRN}Mounting virtual kernel filesystems...${RST}" + mountpoint ${LFS}/dev >/dev/null 2>&1 + retval=$? + if [ "$retval" -ne 0 ]; then + mount -v --bind /dev ${LFS}/dev + else + echo -e " ${YLW}${LFS}/dev${GRN} is already mounted${RST}" + fi + mountpoint ${LFS}/dev/pts >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + mount -v --bind /dev/pts ${LFS}/dev/pts + else + echo -e " ${YLW}${LFS}/dev/pts${GRN} is already mounted${RST}" + fi + mountpoint ${LFS}/proc >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + mount -v --bind /proc ${LFS}/proc + else + echo -e " ${YLW}${LFS}/proc${GRN} is already mounted${RST}" + fi + mountpoint ${LFS}/sys >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + mount -v --bind /sys ${LFS}/sys + else + echo -e " ${YLW}${LFS}/sys${GRN} is already mounted${RST}" + fi + mountpoint ${LFS}/run >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + mount -v --bind /run ${LFS}/run + else + echo -e " ${YLW}${LFS}/run${GRN} is already mounted${RST}" + fi + + if [ -h ${LFS}/dev/shm ]; then + mkdir -pv ${LFS}/$(readlink ${LFS}/dev/shm) + fi + +else + echo -e "${RED}preparechroot.sh must be ran as ${YLW}root${RED} user!${RST}" +fi |