美文网首页
lfs-3 创建临时系统

lfs-3 创建临时系统

作者: 苏wisdom | 来源:发表于2022-07-23 01:52 被阅读0次

    https://www.linuxfromscratch.org/lfs/view/11.1/chapter04/introduction.html

    创建目录

    在$LFS环境中创建一系列目录

    [root@ecs-341537 sources]# mkdir -pv $LFS/{etc,var} $LFS/usr/{bin,lib,sbin}
    mkdir: 已创建目录 "/mnt/lfs/etc"
    mkdir: 已创建目录 "/mnt/lfs/var"
    mkdir: 已创建目录 "/mnt/lfs/usr"
    mkdir: 已创建目录 "/mnt/lfs/usr/bin"
    mkdir: 已创建目录 "/mnt/lfs/usr/lib"
    mkdir: 已创建目录 "/mnt/lfs/usr/sbin"
    
    [root@ecs-341537 sources]# for i in bin lib sbin; do
    >   ln -sv usr/$i $LFS/$i
    > done
    "/mnt/lfs/bin" -> "usr/bin"
    "/mnt/lfs/lib" -> "usr/lib"
    "/mnt/lfs/sbin" -> "usr/sbin"
    
    [root@ecs-341537 sources]# case $(uname -m) in
    >   x86_64) mkdir -pv $LFS/lib64 ;;
    > esac
    mkdir: 已创建目录 "/mnt/lfs/lib64"
    

    查看目录结构

    [root@ecs-341537 lfs]# mkdir -pv $LFS/tools
    mkdir: 已创建目录 "/mnt/lfs/tools"
    
    
    [root@ecs-341537 lfs]# ll
    总用量 40
    lrwxrwxrwx 1 root root     7 7月  23 02:17 bin -> usr/bin
    drwxr-xr-x 2 root root  4096 7月  23 02:17 etc
    lrwxrwxrwx 1 root root     7 7月  23 02:17 lib -> usr/lib
    drwxr-xr-x 2 root root  4096 7月  23 02:17 lib64
    drwx------ 2 root root 16384 7月  23 01:29 lost+found
    lrwxrwxrwx 1 root root     8 7月  23 02:17 sbin -> usr/sbin
    drwxrwxrwt 2 root root  4096 7月  23 02:18 sources
    drwxr-xr-x 2 root root  4096 7月  23 02:20 tools
    drwxr-xr-x 5 root root  4096 7月  23 02:17 usr
    drwxr-xr-x 2 root root  4096 7月  23 02:17 var
    

    创建无特权的账号

    [root@ecs-341537 lfs]# groupadd lfs
    [root@ecs-341537 lfs]# useradd -s /bin/bash -g lfs -m -k /dev/null lfs
    

    -s /bin/bash   指定用户登入后所使用的shell。
    -g lfs 指定用户所属的群组。
    -m 自动建立用户的登入home目录
    -k /dev/null
    lfs 用户名

    设置lfs用户的密码

    [root@ecs-341537 lfs]# passwd lfs
    

    设置权限

    [root@ecs-341537 lfs]# chown -v lfs $LFS/{usr{,/*},lib,var,etc,bin,sbin,tools}
    changed ownership of "/mnt/lfs/usr" from root to lfs
    changed ownership of "/mnt/lfs/usr/bin" from root to lfs
    changed ownership of "/mnt/lfs/usr/lib" from root to lfs
    changed ownership of "/mnt/lfs/usr/sbin" from root to lfs
    "/mnt/lfs/lib" 的所有者已保留为lfs
    changed ownership of "/mnt/lfs/var" from root to lfs
    changed ownership of "/mnt/lfs/etc" from root to lfs
    "/mnt/lfs/bin" 的所有者已保留为lfs
    "/mnt/lfs/sbin" 的所有者已保留为lfs
    changed ownership of "/mnt/lfs/tools" from root to lfs
    [root@ecs-341537 lfs]# case $(uname -m) in
    >   x86_64) chown -v lfs $LFS/lib64 ;;
    > esac
    changed ownership of "/mnt/lfs/lib64" from root to lfs
    
    [root@ecs-341537 lfs]# chown -v lfs $LFS/sources
    changed ownership of "/mnt/lfs/sources" from root to lfs
    

    接下来以lfs的身份登录

    [root@ecs-341537 lfs]# su - lfs
    -bash-4.2$
    
    -bash-4.2$ whoami
    lfs
    

    设置环境

    -bash-4.2$ cat > ~/.bash_profile << "EOF"
    > exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
    > EOF
    
    -bash-4.2$ echo $HOME
    /home/lfs
    -bash-4.2$ echo $TERM
    xterm-256color
    -bash-4.2$ echo PS1
    PS1
    
    -bash-4.2$ cat > ~/.bashrc << "EOF"
    > set +h
    > umask 022
    > LFS=/mnt/lfs
    > LC_ALL=POSIX
    > LFS_TGT=$(uname -m)-lfs-linux-gnu
    > PATH=/usr/bin
    > if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
    > PATH=$LFS/tools/bin:$PATH
    > CONFIG_SITE=$LFS/usr/share/config.site
    > export LFS LC_ALL LFS_TGT PATH CONFIG_SITE
    > EOF
    

    切换到root用户

    -bash-4.2$ exit
    logout
    [root@ecs-341537 lfs]# whoami
    root
    
    [root@ecs-341537 lfs]# [ ! -e /etc/bash.bashrc ] || mv -v /etc/bash.bashrc /etc/bash.bashrc.NOUSE
    

    切换回lfs用户

    [root@ecs-341537 etc]# su - lfs
    lfs:~$ source ~/.bash_profile
    lfs:~$ echo $LFS
    /mnt/lfs
    lfs:~$ echo $PATH
    /mnt/lfs/tools/bin:/usr/bin
    

    查看当前.bashrc

    lfs:~$ ls -a
    .  ..  .bash_history  .bash_profile  .bashrc
    
    lfs:~$ cat .bashrc
    set +h
    umask 022
    LFS=/mnt/lfs
    LC_ALL=POSIX
    LFS_TGT=$(uname -m)-lfs-linux-gnu
    PATH=/usr/bin
    if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
    PATH=$LFS/tools/bin:$PATH
    CONFIG_SITE=$LFS/usr/share/config.site
    export LFS LC_ALL LFS_TGT PATH CONFIG_SITE
    

    设置多线程处理make
    其实这里设置以后多半有坑,我的机器cpu和内存有限,在后面编译gcc的时候就反复遇到瓶颈。
    直接用-j1可能还少点麻烦

    set +h
    umask 022
    LFS=/mnt/lfs
    LC_ALL=POSIX
    LFS_TGT=$(uname -m)-lfs-linux-gnu
    PATH=/usr/bin
    if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
    PATH=$LFS/tools/bin:$PATH
    CONFIG_SITE=$LFS/usr/share/config.site
    MAKEFLAGS='-j4'
    export LFS LC_ALL LFS_TGT PATH CONFIG_SITE MAKEFLAGS
    

    使设置生效

    lfs:~$ source .bashrc
    lfs:~$ set | grep MAKEFLAGS
    MAKEFLAGS=-j4
    

    相关文章

      网友评论

          本文标题:lfs-3 创建临时系统

          本文链接:https://www.haomeiwen.com/subject/gvwvirtx.html