Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit db2653303a0c4367f557961e07f030c9d0f70877 @Vultaire committed with Vultaire May 29, 2011
102 0_prereqs/00_prereqs.sh
@@ -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 0_prereqs/shared.sh
41 1_as_root/22_partition_setup.sh
@@ -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 1_as_root/23_format_disk.sh
@@ -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 1_as_root/24_mount_partitions.sh
@@ -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 1_as_root/31_download_sources.sh
@@ -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 1_as_root/42_create_tools_dir.sh
@@ -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 1_as_root/43_add_lfs_user.sh
@@ -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 1_as_root/shared.sh
27 2_as_lfs/44_set_up_environment.sh
@@ -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 2_as_lfs/45_notes.txt
@@ -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 2_as_lfs/shared.sh
29 3_as_lfs/504_binutils_pass1.sh
@@ -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 3_as_lfs/505_gcc_pass1.sh
@@ -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
24 3_as_lfs/506_linux_headers.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/linux-headers.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 linux-2.6.37.tar.bz2
+cd linux-2.6.37
+
+make mrproper
+
+make headers_check
+make INSTALL_HDR_PATH=dest headers_install
+cp -rv dest/include/* /tools/include
+
+# Cleanup
+cd $LFS/sources
+rm -rf linux-2.6.37
35 3_as_lfs/507_glibc.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.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 glibc-2.13.tar.bz2
+cd glibc-2.13
+
+patch -Np1 -i ../glibc-2.13-gcc_fix-1.patch
+
+mkdir -v ../glibc-build
+cd ../glibc-build
+
+case `uname -m` in
+ i?86) echo "CFLAGS += -march=i486 -mtune=native" > configparms ;;
+esac
+
+../glibc-2.13/configure --prefix=/tools \
+ --host=$LFS_TGT --build=$(../glibc-2.13/scripts/config.guess) \
+ --disable-profile --enable-add-ons \
+ --enable-kernel=2.6.22.5 --with-headers=/tools/include \
+ libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes
+make
+make install
+
+# Cleanup
+cd $LFS/sources
+rm -rf glibc-2.13 glibc-build
29 3_as_lfs/508_adjust_toolchain.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/adjusting.html
+
+set -o nounset
+set -o errexit
+
+source shared.sh
+match_user "lfs" || die 'This script must be run as the "lfs" user.'
+
+SPECS=`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/specs
+$LFS_TGT-gcc -dumpspecs | sed \
+ -e 's@/lib\(64\)\?/ld@/tools&@g' \
+ -e "/^\*cpp:$/{n;s,$, -isystem /tools/include,}" > $SPECS
+echo "New specs file is: $SPECS"
+unset SPECS
+
+# From here is simply some sanity checks.
+
+cd ~/
+
+echo "EXPECTING OUTPUT: [Requesting program interpreter: /tools/lib/ld-linux.so.2]"
+echo -n "Real output: "
+echo 'main(){}' > dummy.c
+$LFS_TGT-gcc -B/tools/lib dummy.c
+readelf -l a.out | grep ': /tools'
+
+rm -v dummy.c a.out
32 3_as_lfs/509_binutils_pass2.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/binutils-pass2.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
+
+CC="$LFS_TGT-gcc -B/tools/lib/" \
+ AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \
+ ../binutils-2.21/configure --prefix=/tools \
+ --disable-nls --with-lib-path=/tools/lib
+make
+make install
+
+make -C ld clean
+make -C ld LIB_PATH=/usr/lib:/lib
+cp -v ld/ld-new /tools/bin
+
+# Cleanup
+cd $LFS/sources
+rm -rf binutils-2.21 binutils-build
78 3_as_lfs/510_gcc_pass2.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/gcc-pass2.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
+
+patch -Np1 -i ../gcc-4.5.2-startfiles_fix-1.patch
+
+cp -v gcc/Makefile.in{,.orig}
+sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
+
+cp -v gcc/Makefile.in{,.tmp}
+sed 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
+ > gcc/Makefile.in
+
+for file in \
+ $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
+do
+ cp -uv $file{,.orig}
+ sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
+ -e 's@/usr@/tools@g' $file.orig > $file
+ echo '
+#undef STANDARD_INCLUDE_DIR
+#define STANDARD_INCLUDE_DIR 0
+#define STANDARD_STARTFILE_PREFIX_1 ""
+#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
+ touch $file.orig
+done
+
+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
+
+CC="$LFS_TGT-gcc -B/tools/lib/" \
+ AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \
+ ../gcc-4.5.2/configure --prefix=/tools \
+ --with-local-prefix=/tools --enable-clocale=gnu \
+ --enable-shared --enable-threads=posix \
+ --enable-__cxa_atexit --enable-languages=c,c++ \
+ --disable-libstdcxx-pch --disable-multilib \
+ --disable-bootstrap --disable-libgomp \
+ --with-gmp-include=$(pwd)/gmp --with-gmp-lib=$(pwd)/gmp/.libs \
+ --without-ppl --without-cloog
+make
+make install
+
+ln -vs gcc /tools/bin/cc
+
+# SANITY CHECK
+cd ~
+
+echo "Expected: [Requesting program interpreter: /tools/lib/ld-linux.so.2]"
+echo -n "Real: "
+
+echo 'main(){}' > dummy.c
+cc dummy.c
+readelf -l a.out | grep ': /tools'
+
+rm -v dummy.c a.out
+
+# Cleanup
+cd $LFS/sources
+rm -rf gcc-4.5.2 gcc-build
27 3_as_lfs/511_tcl.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/tcl.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 tcl8.5.9-src.tar.gz
+cd tcl8.5.9
+
+cd unix
+./configure --prefix=/tools
+make
+#TZ=UTC make test || echo "Errors encountered, but this is okay."
+make install
+chmod -v u+w /tools/lib/libtcl8.5.so
+make install-private-headers
+ln -sv tclsh8.5 /tools/bin/tclsh
+
+# Cleanup
+cd $LFS/sources
+rm -rf tcl8.5.9
27 3_as_lfs/512_expect.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/expect.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 expect5.45.tar.gz
+cd expect5.45
+
+cp -v configure{,.orig}
+sed 's:/usr/local/bin:/bin:' configure.orig > configure
+
+./configure --prefix=/tools --with-tcl=/tools/lib \
+ --with-tclinclude=/tools/include
+make
+#make test
+make SCRIPTS="" install
+
+# Cleanup
+cd $LFS/sources
+rm -rf expect5.45
23 3_as_lfs/513_dejagnu.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/dejagnu.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 dejagnu-1.4.4.tar.gz
+cd dejagnu-1.4.4
+
+patch -Np1 -i ../dejagnu-1.4.4-consolidated-1.patch
+./configure --prefix=/tools
+make install
+make check
+
+# Cleanup
+cd $LFS/sources
+rm -rf dejagnu-1.4.4
23 3_as_lfs/514_ncurses.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# LFS Reference:
+# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/ncurses.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 ncurses-5.7.tar.gz
+cd ncurses-5.7
+
+./configure --prefix=/tools --with-shared \
+ --without-debug --without-ada --enable-overwrite
+make
+make install
+
+# Cleanup
+cd $LFS/sources
+rm -rf ncurses-5.7
1 3_as_lfs/shared.sh
19 shared.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Shared functions
+function die () {
+ echo "$@" > /dev/stdout
+ exit 1
+}
+
+function match_root () {
+ (( $(id -u) == 0 ))
+}
+
+function match_user () {
+ user=$1
+ [ "$(id -un)" == "$user" ]
+}
+
+# Shared constants
+LFS=/mnt/lfs
20 using_run-parts.txt
@@ -0,0 +1,20 @@
+The scripts are organized in folders based upon the user they must be
+run as and based upon areas which require human intervention.
+
+The scripts are intended to be runnable via the run-parts command,
+using the following form:
+
+ run-parts --exit-on-error --regex '^[0-9].*' <folder>
+
+For example, to install the prerequisites (which must be done as the
+root user), the following will work:
+
+ sudo run-parts --exit-on-error --regex '^[0-9].*' 0_prereqs
+
+And later, when necessary to run the 2_as_lfs folder as the lfs user,
+the following will work:
+
+ sudo -u lfs -i # Allows full login, since we use a replacement shell
+ # which breaks sudo...
+ cd /home/ubuntu
+ run-parts --exit-on-error --regex '^[0-9].*' 2_as_lfs
122 virt_install_notes.txt
@@ -0,0 +1,122 @@
+Assuming that kvm and libvirt have never been used on your system
+previously, the following should set up the necessary environment::
+
+ # Install kvm, libvirt, and virt-install
+ sudo apt-get update
+ sudo apt-get install -y kvm libvirt-bin virtinst
+
+ # Enable the default network bridge (needed for SSH access)
+ sudo virsh net-autostart default
+ sudo virsh net-start default
+
+Disk images are stored in /var/lib/libvirt/images by default. If this
+is not okay, then replace this folder with an appropriate symlink.
+(Alternatively, you probably can dump the XML of the disk pool, put in
+a different directory and then re-create the pool.)
+
+To create a VM compatible with the scripts in this repository, use
+virt-install with options similar to those which follow. Update it as
+you like, but please note these requirements:
+
+ - The CD image is assumed to be Ubuntu 10.10 Desktop i386. Other
+ host environments have not been tested.
+
+ - It is assumed that the VM has a single 20 GB disk, so it's
+ generally advised to leave the "--disk" flag as-is.
+
+ - I suggest using the "format=qcow2" option on the disk as specified
+ below. This allows for the use of disk overlays which, although
+ an advanced virtualization feature, allows for a form of disk
+ snapshots which additional VMs can be based off of. (Some people
+ may call these images "templates").
+
+The command is as follows::
+
+ sudo virt-install \
+ --name lfs1 \
+ --ram 4096 \
+ --disk pool=default,format=qcow2,size=20 \
+ --cdrom=/home/vultaire/ubuntu-10.10-desktop-i386.iso
+
+Wait for the VM viewer window to pop up, and select to "Try Ubuntu".
+Once the regular desktop appears, from the viewer window's menu,
+select "Send key", then "Ctrl + Alt + F1". This will get to a
+console.
+
+If running on a non-US keyboard, it's helpful to load the appropriate
+keymap. I don't know all codes, but for my keyboard, the following
+works::
+
+ sudo loadkeys jp
+
+The password for the ubuntu user should be changed, so::
+
+ sudo passwd ubuntu # "sudo" will skip some password safety checks.
+ # Enter a password. We'll use this later.
+
+Next, install SSH::
+
+ sudo apt-get install -y openssh-server
+
+Finally, let's set up DNS for this VM:
+
+ sudo hostname <vm_name>
+ sudo dhclient eth0 # Refreshes DNS
+
+From here, SSH access should work. To get the IP address, you can use
+a line as follows:
+
+ # -From outside of the VM-
+ function vm_host () {
+ vm_name="$1"
+ host -t A "$vm_name" 192.168.122.1 \
+ | grep "^$vm_name has address" \
+ | awk '{print $4}'
+ }
+ vm_addr=$(vm_host "<vm_name>") # vm_addr will receive the IP address.
+
+I assume you already have a working SSH key; if not, run ssh-keygen to
+create one.
+
+It's probably convenient to copy your key to the VM; this can be done
+with "ssh-copy-id ubuntu@<vm_ip>".
+
+Now, you are ready to create an LFS system via an SSH shell in a VM.
+You can close the VM's viewer window; the VM will still be running in
+the background.
+
+You're ready to begin, but a few VM control notes:
+
+1. VM commands should always be run via sudo. `1`_
+
+2. To save a VM's state to disk (stops the VM)::
+
+ sudo virsh save <vm_name> <path/to/target.file>
+
+3. To restore a VM from a saved state file (starts the VM
+ automatically)::
+
+ sudo virsh restore <path/to/target.file>
+
+4. To shutdown a VM gracefully::
+
+ sudo virsh shutdown <vm_name>
+
+ Note that the VM must have ACPI support installed. The Ubuntu
+ 10.10 environment does have acpid installed, so it should work
+ without modification.
+
+5. To destroy a VM completely::
+
+ sudo virsh destroy <vm_name> # Terminates the VM (if running)
+ sudo virsh undefine <vm_name> # Deletes the VM definition from libvirt.
+ sudo virsh vol-delete --pool default <disk_img_name_or_path> `2`_
+
+.. [1] Well, not really. Of course, you should avoid using root or
+ sudo unless you need to. However, libvirt controls virtual network
+ devices and disk pools, and these may not show up unless the root
+ account is used. Sorry, but I don't yet know the appropriate group
+ permissions so that virsh and virt-install work in their entirety
+ without problems... so for now, "sudo" it is.
+
+.. [2] Usually, the disk image's name is "<vm_name>.img".

0 comments on commit db26533

Please sign in to comment.