{"id":13611828,"url":"https://github.com/luisgbm/lfs-scripts","last_synced_at":"2025-04-13T05:33:48.443Z","repository":{"id":45030802,"uuid":"296052981","full_name":"luisgbm/lfs-scripts","owner":"luisgbm","description":"Instructions and scripts to build Linux From Scratch (LFS) as simply as possible","archived":false,"fork":false,"pushed_at":"2023-05-06T17:32:55.000Z","size":6544,"stargazers_count":119,"open_issues_count":0,"forks_count":22,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-07T18:49:09.633Z","etag":null,"topics":["lfs","lfs-10-0","lfs-11-0","lfs-11-2","lfs-book","linux"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luisgbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-09-16T14:12:31.000Z","updated_at":"2024-10-29T22:53:20.000Z","dependencies_parsed_at":"2024-01-14T06:53:00.130Z","dependency_job_id":"364bc472-2c85-41f5-be03-def67ea8e0fe","html_url":"https://github.com/luisgbm/lfs-scripts","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luisgbm%2Flfs-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luisgbm%2Flfs-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luisgbm%2Flfs-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luisgbm%2Flfs-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luisgbm","download_url":"https://codeload.github.com/luisgbm/lfs-scripts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670514,"owners_count":21142896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lfs","lfs-10-0","lfs-11-0","lfs-11-2","lfs-book","linux"],"created_at":"2024-08-01T19:02:12.015Z","updated_at":"2025-04-13T05:33:43.430Z","avatar_url":"https://github.com/luisgbm.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# lfs-scripts :penguin:\nInstructions and scripts to build Linux From Scratch (LFS), version 11.2, as simply as possible (I know, not that simple, but anyway).\n\n![Output of uname -a](https://github.com/luisgbm/lfs-scripts/blob/master/img/uname.png?raw=true)\n\n![vim :smile](https://github.com/luisgbm/lfs-scripts/blob/master/img/vim-smile.png?raw=true)\n\n# Foreword\n\nFirst, this guide does not replace reading the whole LFS book. I highly recommend that you read it at least once. Only then you should use the automated scripts provided here.\n\nThis build will be accomplished inside a virtual machine. I'll be using Oracle VirtualBox, but you can use any tool of your personal preference. I'm running an Arch Linux VM, feel free to use your GNU/Linux distribution of choice. Just be sure to install the development tools available (base-devel package on Arch).\n\nMy VM has two virtual hard disks: one for the host (Arch Linux itself) and another for building LFS. You could also use a single hard disk with two partitions, that's also up to personal taste. I've decided to use two separate hard disks so I can completely isolate LFS from the host after the build. At the end, you'll be able to create a separate VM and boot from it directly.\n\nThe packages needed to build LFS were downloaded from [here](http://ftp.osuosl.org/pub/lfs/lfs-packages/lfs-packages-11.2.tar) (474 MB), other mirrors are available [here](http://linuxfromscratch.org/lfs/download.html) (look for the \"LFS HTTP/FTP Sites\" section at the bottom, the file you need is lfs-packages-11.0.tar).\n\n# Build instructions\n\n:point_right: Run commands below as root.\n\nCreate a partition and a filesystem in the virtual hard disk (/dev/sdb):\n\n```\nfdisk /dev/sdb\n```\n\nUse the following basic options: n- new partition, accept the default values, w- write changes\n\nCreate a filesystem, a mount point, and mount it:\n\n```\nmkfs.ext4 /dev/sdb1\nmkdir /mnt/lfs\nmount /dev/sdb1 /mnt/lfs\n```\n\nAdd the following line to root's .bashrc:\n\n```\nexport LFS=/mnt/lfs\n```\n\nSource the file:\n\n```\nsource .bashrc\n```\n\nDownload all the packages and extract them to $LFS/sources.\n\n```\ncd $LFS\ncp /\u003clocation_of_the_package\u003e/lfs-packages-11.2.tar .\ntar xf lfs-packages-11.2.tar\nmv 11.2-rc1 sources\nchmod -v a+wt $LFS/sources\n```\n\nCopy all the shell scripts from this repository to your $LFS directory:\n\n```\ncp /\u003clocation_of_the_scripts\u003e/*.sh $LFS\n```\n\nCreate the basic filesystem for LFS:\n\n```\nmkdir -pv $LFS/{etc,var} $LFS/usr/{bin,lib,sbin}\n\nfor i in bin lib sbin; do\n  ln -sv usr/$i $LFS/$i\ndone\n\ncase $(uname -m) in\n  x86_64) mkdir -pv $LFS/lib64 ;;\nesac\n\nmkdir -pv $LFS/tools\n```\n\nCreate the lfs user, used during the initial build process (you will have to type a password):\n\n```\ngroupadd lfs\nuseradd -s /bin/bash -g lfs -m -k /dev/null lfs\npasswd lfs\n```\n\nMake lfs own the entire filesystem:\n\n```\nchown -R lfs:lfs $LFS/*\nchown lfs:lfs $LFS\n```\n\nLogin as the lfs user:\n\n```\nsu - lfs\n```\n\n:point_right: Run commands below as lfs.\n\nCreate a .bash_profile file:\n\n```\ncat \u003e ~/.bash_profile \u003c\u003c \"EOF\"\nexec env -i HOME=$HOME TERM=$TERM PS1='\\u:\\w\\$ ' /bin/bash\nEOF\n```\n\nCreate a .bashrc file:\n\n```\ncat \u003e ~/.bashrc \u003c\u003c \"EOF\"\nset +h\numask 022\nLFS=/mnt/lfs\nLC_ALL=POSIX\nLFS_TGT=$(uname -m)-lfs-linux-gnu\nPATH=/usr/bin\nif [ ! -L /bin ]; then PATH=/bin:$PATH; fi\nPATH=$LFS/tools/bin:$PATH\nCONFIG_SITE=$LFS/usr/share/config.site\nexport LFS LC_ALL LFS_TGT PATH CONFIG_SITE\nEOF\n\nsource ~/.bashrc\n```\n\nRun the lfs-cross.sh script, which will build the cross toolchain and cross compiling temporary tools from chapters 5 and 6:\n\n``` \nsh $LFS/lfs-cross.sh | tee $LFS/lfs-cross.log\n```\n\nExit from the lfs user to become root again:\n\n```\nexit\n```\n\n:point_right: Run commands below as root.\n\nMake root own the entire filesystem again:\n\n```\nchown -R root:root $LFS/*\nchown root:root $LFS\n```\n\nPrepare virtual kernel file systems:\n\n```\nmkdir -pv $LFS/{dev,proc,sys,run}\nmount -v --bind /dev $LFS/dev\nmount -v --bind /dev/pts $LFS/dev/pts\nmount -vt proc proc $LFS/proc\nmount -vt sysfs sysfs $LFS/sys\nmount -vt tmpfs tmpfs $LFS/run\nif [ -h $LFS/dev/shm ]; then\n  mkdir -pv $LFS/$(readlink $LFS/dev/shm)\nfi\n```\n\nEnter the chroot environment:\n\n```\nchroot \"$LFS\" /usr/bin/env -i   \\\n    HOME=/root                  \\\n    TERM=\"$TERM\"                \\\n    PS1='(lfs chroot) \\u:\\w\\$ ' \\\n    PATH=/usr/bin:/usr/sbin     \\\n    /bin/bash --login\n```\n\nCreate essential directories, files and symlinks:\n\n```\nmkdir -pv /{boot,home,mnt,opt,srv}\nmkdir -pv /etc/{opt,sysconfig}\nmkdir -pv /lib/firmware\nmkdir -pv /media/{floppy,cdrom}\nmkdir -pv /usr/{,local/}{include,src}\nmkdir -pv /usr/local/{bin,lib,sbin}\nmkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}\nmkdir -pv /usr/{,local/}share/{misc,terminfo,zoneinfo}\nmkdir -pv /usr/{,local/}share/man/man{1..8}\nmkdir -pv /var/{cache,local,log,mail,opt,spool}\nmkdir -pv /var/lib/{color,misc,locate}\nln -sfv /run /var/run\nln -sfv /run/lock /var/lock\ninstall -dv -m 0750 /root\ninstall -dv -m 1777 /tmp /var/tmp\nln -sv /proc/self/mounts /etc/mtab\n\ncat \u003e /etc/hosts \u003c\u003c EOF\n127.0.0.1  localhost $(hostname)\n::1        localhost\nEOF\n\ncat \u003e /etc/passwd \u003c\u003c \"EOF\"\nroot:x:0:0:root:/root:/bin/bash\nbin:x:1:1:bin:/dev/null:/usr/bin/false\ndaemon:x:6:6:Daemon User:/dev/null:/usr/bin/false\nmessagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false\nuuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false\nnobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false\nEOF\n\ncat \u003e /etc/group \u003c\u003c \"EOF\"\nroot:x:0:\nbin:x:1:daemon\nsys:x:2:\nkmem:x:3:\ntape:x:4:\ntty:x:5:\ndaemon:x:6:\nfloppy:x:7:\ndisk:x:8:\nlp:x:9:\ndialout:x:10:\naudio:x:11:\nvideo:x:12:\nutmp:x:13:\nusb:x:14:\ncdrom:x:15:\nadm:x:16:\nmessagebus:x:18:\ninput:x:24:\nmail:x:34:\nkvm:x:61:\nuuidd:x:80:\nwheel:x:97:\nusers:x:999:\nnogroup:x:65534:\nEOF\n\necho \"tester:x:101:101::/home/tester:/bin/bash\" \u003e\u003e /etc/passwd\necho \"tester:x:101:\" \u003e\u003e /etc/group\ninstall -o tester -d /home/tester\ntouch /var/log/{btmp,lastlog,faillog,wtmp}\nchgrp -v utmp /var/log/lastlog\nchmod -v 664  /var/log/lastlog\nchmod -v 600  /var/log/btmp\n\nexec /usr/bin/bash --login\n```\n\nRun the lfs-chroot.sh script, which will build additional temporary tools:\n\n``` \nsh /lfs-chroot.sh | tee /lfs-chroot.log\n```\n\nCleanup before the final build phase:\n\n```\nrm -rf /usr/share/{info,man,doc}/*\nfind /usr/{lib,libexec} -name \\*.la -delete\nrm -rf /tools\n```\n\nFor the final build phase, run the lfs-system.sh script:\n\n``` \nsh /lfs-system.sh | tee /lfs-system.log\n```\n\nYou must now set a password for the root user (you will have to type a password):\n\n```\npasswd root\n```\n\nRun the final script to configure the rest of the system:\n\n```\nsh /lfs-final.sh | tee /lfs-final.log\n```\n\n# The end\n\nYou can now create a new VM using the virtual hard disk with the LFS build. It will be bootable and fully functional. Enjoy!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluisgbm%2Flfs-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluisgbm%2Flfs-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluisgbm%2Flfs-scripts/lists"}