Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultaire authored and Vultaire committed May 29, 2011
0 parents commit db26533
Show file tree
Hide file tree
Showing 27 changed files with 829 additions and 0 deletions.
102 changes: 102 additions & 0 deletions 0_prereqs/00_prereqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

# This should be run on the host system to ensure that necessary
# programs are installed.

function install_prereqs () {
# Bash: assign /bin/sh to /bin/bash
ln -sfv /bin/bash /bin/sh

apt-get install -y bison

# Gawk should be installed and set as the default awk.
apt-get install -y gawk
update-alternatives --set awk /usr/bin/gawk

# Patch
apt-get install -y patch

# Texinfo
apt-get install texinfo
}

function modify_system_bashrc () {
# This is outside the scope of the LFS docs. It's a trivial fix
# related to the PS1 environment variable.
#
# /etc/bash.bashrc modifies PS1. This will disable it.

sed -i /etc/bash.bashrc -e 's/^PS1=/#PS1=/'

# Reason: on a login shell in the Ubuntu Live CD, files get read
# in this order:
#
# - /etc/profile
# - /etc/bash.bashrc
# - ~/.bash_profile
# - /etc/bash.bashrc
# - ~/.bashrc
#
# That is, not only are /etc/profile and ~/.bash_profile read, but
# additionally /etc/bash.bashrc and ~/.bashrc are also read.
}

function create_version_check_script () {
# Source of the following script:
# http://www.linuxfromscratch.org/lfs/view/stable/prologue/hostreqs.html
cat > version-check.sh << "EOF"
#!/bin/bash
export LC_ALL=C
# Simple script to list version numbers of critical development tools
bash --version | head -n1 | cut -d" " -f2-4
echo "/bin/sh -> `readlink -f /bin/sh`"
echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
bison --version | head -n1
if [ -e /usr/bin/yacc ];
then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
else echo "yacc not found"; fi
bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
diff --version | head -n1
find --version | head -n1
gawk --version | head -n1
if [ -e /usr/bin/awk ];
then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
else echo "awk not found"; fi
gcc --version | head -n1
/lib/libc.so.6 | head -n1 | cut -d"," -f1
grep --version | head -n1
gzip --version | head -n1
cat /proc/version
m4 --version | head -n1
make --version | head -n1
patch --version | head -n1
echo Perl `perl -V:version`
sed --version | head -n1
tar --version | head -n1
echo "Texinfo: `makeinfo --version | head -n1`"
echo 'main(){}' > dummy.c && gcc -o dummy dummy.c
if [ -x dummy ]; then echo "Compilation OK";
else echo "Compilation failed"; fi
rm -f dummy.c dummy
EOF
}

######################################################################

set -o nounset
set -o errexit

source shared.sh
match_root || die "This script must be run as root."

cd ~/

# For everyone:
install_prereqs
modify_system_bashrc
create_version_check_script
bash version-check.sh
1 change: 1 addition & 0 deletions 0_prereqs/shared.sh
41 changes: 41 additions & 0 deletions 1_as_root/22_partition_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter02/creatingpartition.html

# This script should set up the disk as follows:
# pri /boot 100 MB
# ext swap 2 GB
# ext / 10 GB
# ext /home Remainder

function partition_disk () {
# Partition the disk
# Explanation:
# - c\n: Turn off DOS compat
# - u\n: Switch to sector display
# - o\n: Create new DOS partition table
# - n\np\n1\n\n+100M\n: Create pri part. 1 from start of disk, 100MB
# - n\ne\n2\n\n\n: Create extended partition for remainder of disk.
# - n\nl\n\n+2G\n: Create logical partition (5), from start, 2GB.
# - n\nl\n\n+10G\n: Create logical partition (6), from start, 10 GB.
# - n\nl\n\n\n: Create logical partition (7), from start, use remainder.
# - t\n1\n83\n: Set partition 1 as type "Linux".
# - t\n5\n82\n: Set partition 5 as type "Linux swap".
# - t\n6\n83\n: Set partition 6 as type "Linux".
# - t\n7\n83\n: Set partition 7 as type "Linux".
# - w\n: Write to disk.

echo -ne "c\nu\no\nn\np\n1\n\n+100M\nn\ne\n2\n\n\nn\nl\n\n+2G\nn\nl\n\n+10G\nn\nl\n\n\nt\n1\n83\nt\n5\n82\nt\n6\n83\nt\n7\n83\nw\n" \
| fdisk /dev/sda
}

######################################################################

set -o nounset
set -o errexit

source shared.sh
match_root || die "This script must be run as root."

partition_disk
26 changes: 26 additions & 0 deletions 1_as_root/23_format_disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter02/creatingfilesystem.html

# This depends directly on the disk structure created in
# 22_partition_setup.sh.

function format_disk () {
mke2fs -jv /dev/sda1
mkswap /dev/sda5
mke2fs -jv /dev/sda6
mke2fs -jv /dev/sda7
}

######################################################################

set -o nounset
set -o errexit

source shared.sh
match_root || die "This script must be run as root."

format_disk
# Note: we don't do the feature check on the partitions, but if you're
# using the right Ubuntu host version, it should be okay.
28 changes: 28 additions & 0 deletions 1_as_root/24_mount_partitions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter02/mounting.html

# This depends directly on the disk structure created in the previous
# two scripts.

source shared.sh

function mount_partitions () {
mkdir -pv $LFS
mount -v -t ext3 /dev/sda6 $LFS
mkdir -pv $LFS/boot
mount -v -t ext3 /dev/sda1 $LFS/boot
mkdir -pv $LFS/home
mount -v -t ext3 /dev/sda7 $LFS/home
/sbin/swapon -v /dev/sda5
}

######################################################################

set -o nounset
set -o errexit

match_root || die "This script must be run as root."

mount_partitions
29 changes: 29 additions & 0 deletions 1_as_root/31_download_sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter02/mounting.html

# This depends directly on the disk structure created in the previous
# two scripts.

source shared.sh

function prep_sources_dir () {
mkdir -v $LFS/sources
chmod -v a+wt $LFS/sources
}

function download_sources () {
wget "http://www.linuxfromscratch.org/lfs/view/stable/wget-list"
wget -i wget-list -P $LFS/sources
}

######################################################################

set -o nounset
set -o errexit

match_root || die "This script must be run as root."

prep_sources_dir
download_sources
13 changes: 13 additions & 0 deletions 1_as_root/42_create_tools_dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter04/creatingtoolsdir.html

set -o nounset
set -o errexit

source shared.sh
match_root || die "This script must be run as root."

mkdir -v $LFS/tools
ln -sv $LFS/tools /
25 changes: 25 additions & 0 deletions 1_as_root/43_add_lfs_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter04/addinguser.html

set -o nounset
set -o errexit

source shared.sh
match_root || die "This script must be run as root."

groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs

echo 'Setting password of "lfs" user.'
passwd lfs

chown -v lfs $LFS/tools
chown -v lfs $LFS/sources

echo 'ATTENTION: The next script must be run via the "lfs" user via a' \
'login shell:'
echo
echo -e "\tsu - lfs"
echo
1 change: 1 addition & 0 deletions 1_as_root/shared.sh
27 changes: 27 additions & 0 deletions 2_as_lfs/44_set_up_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter04/settingenvironment.html

set -o nounset
set -o errexit

source shared.sh

match_user "lfs" || die 'This script must be run as the "lfs" user.'

cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF

cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF

echo "ATTENTION: Please run: source ~/.bash_profile"
4 changes: 4 additions & 0 deletions 2_as_lfs/45_notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
There's a note about setting "MAKEFLAGS='-j 2" or using "make -j2".
While I like this on my nice quad-core system, it does seem to cause
intermittent compilation errors. If you want the least headaches,
although it takes time, I suggest *not* using this option.
1 change: 1 addition & 0 deletions 2_as_lfs/shared.sh
29 changes: 29 additions & 0 deletions 3_as_lfs/504_binutils_pass1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/binutils-pass1.html

set -o nounset
set -o errexit

source shared.sh
match_user "lfs" || die 'This script must be run as the "lfs" user.'

cd $LFS/sources
tar -xf binutils-2.21.tar.bz2
cd binutils-2.21

mkdir -v ../binutils-build
cd ../binutils-build

time {
../binutils-2.21/configure \
--target=$LFS_TGT --prefix=/tools \
--disable-nls --disable-werror
make
make install
}

# Cleanup
cd $LFS/sources
rm -rf binutils-2.21 binutils-build
42 changes: 42 additions & 0 deletions 3_as_lfs/505_gcc_pass1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/gcc-pass1.html

set -o nounset
set -o errexit

source shared.sh
match_user "lfs" || die 'This script must be run as the "lfs" user.'

cd $LFS/sources
tar -xf gcc-4.5.2.tar.bz2
cd gcc-4.5.2

tar -jxf ../mpfr-3.0.0.tar.bz2
mv -v mpfr-3.0.0 mpfr
tar -jxf ../gmp-5.0.1.tar.bz2
mv -v gmp-5.0.1 gmp
tar -zxf ../mpc-0.8.2.tar.gz
mv -v mpc-0.8.2 mpc

mkdir -v ../gcc-build
cd ../gcc-build

../gcc-4.5.2/configure \
--target=$LFS_TGT --prefix=/tools \
--disable-nls --disable-shared --disable-multilib \
--disable-decimal-float --disable-threads \
--disable-libmudflap --disable-libssp \
--disable-libgomp --enable-languages=c \
--with-gmp-include=$(pwd)/gmp --with-gmp-lib=$(pwd)/gmp/.libs \
--without-ppl --without-cloog
make
make install

ln -vs libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | \
sed 's/libgcc/&_eh/'`

# Cleanup
cd $LFS/sources
rm -rf gcc-4.5.2 gcc-build
Loading

0 comments on commit db26533

Please sign in to comment.