[617118d] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # cross-lfs final target partition prep
|
---|
| 4 | # -------------------------------------
|
---|
| 5 | # $LastChangedBy$
|
---|
| 6 | # $LastChangedDate$
|
---|
| 7 | # $LastChangedRevision$
|
---|
| 8 | # $HeadURL$
|
---|
| 9 | #
|
---|
| 10 |
|
---|
| 11 | test x${LFS} != x || barf
|
---|
| 12 |
|
---|
| 13 | LOG=final-prep-target.log
|
---|
| 14 | max_log_init "Final prep" "" "target" ${INSTLOGS} ${LOG}
|
---|
| 15 |
|
---|
| 16 | ### Final Prep for chroot ###
|
---|
| 17 |
|
---|
| 18 | mkdir -p ${LFS}/{bin,boot,dev/pts,/dev/shm,etc/opt,home,lib,mnt,proc}
|
---|
| 19 | mkdir -p ${LFS}/{root,sbin,tmp,usr/local,var,opt}
|
---|
| 20 |
|
---|
| 21 | case ${KERNEL_VER} in
|
---|
| 22 | 2.5* | 2.6* ) mkdir -p ${LFS}/sys ;;
|
---|
| 23 | esac
|
---|
| 24 |
|
---|
| 25 | for dirname in ${LFS}/usr ${LFS}/usr/local
|
---|
| 26 | do
|
---|
| 27 |
|
---|
| 28 | mkdir -p $dirname/{bin,etc,include,lib,sbin,share,src}
|
---|
| 29 | # Apparently not FHS compliant but without these LFS breaks (RO)
|
---|
| 30 | ln -sf share/{man,doc,info} $dirname
|
---|
| 31 |
|
---|
| 32 | # More FHS compliant but breaks LFS builds
|
---|
| 33 | #mkdir -p $dirname/{bin,include,lib,sbin,share,src}
|
---|
| 34 |
|
---|
| 35 | mkdir -p $dirname/share/{dict,doc,info,locale,man}
|
---|
| 36 | mkdir -p $dirname/share/{nls,misc,terminfo,zoneinfo}
|
---|
| 37 | mkdir -p $dirname/share/man/man{1,2,3,4,5,6,7,8}
|
---|
| 38 | done
|
---|
| 39 | mkdir -p ${LFS}/usr/local/games
|
---|
| 40 | ln -sf share/man ${LFS}/usr/local
|
---|
| 41 | mkdir -p ${LFS}/var/{lock,log,mail,run,spool} &&
|
---|
| 42 | mkdir -p ${LFS}/var/{tmp,opt,cache,lib/misc,local} &&
|
---|
| 43 | mkdir -p ${LFS}/opt/{bin,doc,include,info} &&
|
---|
| 44 | mkdir -p ${LFS}/opt/{lib,man/man{1,2,3,4,5,6,7,8}} &&
|
---|
| 45 |
|
---|
| 46 | touch ${LFS}/var/run/utmp ${LFS}/var/log/{btmp,lastlog,wtmp} &&
|
---|
| 47 | chmod 644 ${LFS}/var/run/utmp ${LFS}/var/log/{btmp,lastlog,wtmp}
|
---|
| 48 |
|
---|
| 49 | chmod 0750 ${LFS}/root &&
|
---|
| 50 | chmod 1777 ${LFS}/tmp ${LFS}/var/tmp
|
---|
| 51 |
|
---|
| 52 | if [ ! "${USE_SYSROOT}" = "Y" ]; then
|
---|
| 53 | # setup bash symlinks
|
---|
| 54 | ln -sf ..${TGT_TOOLS}/bin/bash ${LFS}/bin
|
---|
| 55 | ln -sf bash ${LFS}/bin/sh
|
---|
| 56 |
|
---|
| 57 | # Required for glibc build
|
---|
| 58 | ln -sf ..${TGT_TOOLS}/bin/pwd ${LFS}/bin
|
---|
| 59 | ln -sf ../..${TGT_TOOLS}/bin/perl ${LFS}/usr/bin
|
---|
| 60 | # added for glibc make check
|
---|
| 61 | ln -sf ..${TGT_TOOLS}/bin/cat ${LFS}/bin
|
---|
| 62 |
|
---|
| 63 | # added for binutils ar test
|
---|
| 64 | ln -sf ..${TGT_TOOLS}/bin/stty ${LFS}/bin
|
---|
| 65 | # ln -sf ../..${TGT_TOOLS}/bin/msgfmt ${LFS}/usr/bin
|
---|
| 66 | # ln -sf ../..${TGT_TOOLS}/bin/xgettext ${LFS}/usr/bin
|
---|
| 67 | # ln -sf ../..${TGT_TOOLS}/bin/msgmerge ${LFS}/usr/bin
|
---|
| 68 | ln -sf ../..${TGT_TOOLS}/bin/install ${LFS}/usr/bin
|
---|
| 69 | ln -sf ../usr/bin/install ${LFS}/bin
|
---|
| 70 |
|
---|
| 71 | # Added for ch6 findutils locate tests
|
---|
| 72 | ln -sf ..${TGT_TOOLS}/bin/echo ${LFS}/bin
|
---|
| 73 |
|
---|
| 74 | ## CHECK IF FINDUTILS STILL NEEDS AWK/SED SYMLINKS ##
|
---|
| 75 | ln -sf ..${TGT_TOOLS}/bin/sed ${LFS}/bin
|
---|
| 76 | ln -sf ..${TGT_TOOLS}/bin/awk ${LFS}/bin
|
---|
| 77 |
|
---|
| 78 | # ch6 ed make check needs cmp
|
---|
| 79 | ln -sf ../..${TGT_TOOLS}/bin/cmp ${LFS}/usr/bin
|
---|
| 80 |
|
---|
| 81 | # for ch6 coreutils user checks
|
---|
| 82 | ln -sf ..${TGT_TOOLS}/bin/su ${LFS}/bin
|
---|
| 83 |
|
---|
| 84 | # For the bootscripts
|
---|
| 85 | ln -sf ../..${TGT_TOOLS}/bin/find ${LFS}/usr/bin
|
---|
| 86 | ln -sf ..${TGT_TOOLS}/sbin/fsck ${LFS}/sbin
|
---|
| 87 | ln -sf ..${TGT_TOOLS}/bin/grep ${LFS}/bin
|
---|
| 88 | ln -sf ..${TGT_TOOLS}/bin/ls ${LFS}/bin
|
---|
| 89 | ln -sf ..${TGT_TOOLS}/bin/ln ${LFS}/bin
|
---|
| 90 | ln -sf ..${TGT_TOOLS}/bin/mkdir ${LFS}/bin
|
---|
| 91 | ln -sf ..${TGT_TOOLS}/bin/rm ${LFS}/bin
|
---|
| 92 | ln -sf ..${TGT_TOOLS}/bin/sleep ${LFS}/bin
|
---|
| 93 | ln -sf ..${TGT_TOOLS}/bin/chown ${LFS}/bin
|
---|
| 94 | ln -sf ..${TGT_TOOLS}/bin/chmod ${LFS}/bin
|
---|
| 95 |
|
---|
| 96 | # for hotplug...
|
---|
| 97 | ln -sf ..${TGT_TOOLS}/bin/uname ${LFS}/bin
|
---|
| 98 | ln -sf ../..${TGT_TOOLS}/bin/env ${LFS}/usr/bin
|
---|
| 99 | ln -sf ../..${TGT_TOOLS}/bin/cut ${LFS}/usr/bin
|
---|
| 100 | ln -sf ../..${TGT_TOOLS}/bin/od ${LFS}/usr/bin
|
---|
| 101 | ln -sf ../..${TGT_TOOLS}/bin/wc ${LFS}/usr/bin
|
---|
| 102 | ln -sf ../..${TGT_TOOLS}/bin/readlink ${LFS}/usr/bin
|
---|
| 103 | fi
|
---|
| 104 |
|
---|
| 105 | if [ ! -f ${LFS}/etc/passwd ]; then
|
---|
| 106 | # Our new root user will be called "root".
|
---|
| 107 | # NOTE root password field should be "x" if shadow is installed.
|
---|
| 108 | echo "root::0:0:root:/root:/bin/bash" > ${LFS}/etc/passwd
|
---|
| 109 | echo "plfstest:x:1000:100:root:/root:/bin/bash" >> ${LFS}/etc/passwd
|
---|
| 110 | echo "nobody:x:65534:65534:nobody:/home:/bin/false" >> ${LFS}/etc/passwd
|
---|
| 111 | fi
|
---|
| 112 |
|
---|
| 113 | chmod 644 ${LFS}/etc/passwd
|
---|
| 114 |
|
---|
| 115 | if [ ! -f ${LFS}/etc/shadow ]; then
|
---|
| 116 | # Get number of seconds since epoch
|
---|
| 117 | LASTCHG=`date +%s`
|
---|
| 118 | # Convert to days since epoch
|
---|
| 119 | LASTCHG=`expr ${LASTCHG} / 86400`
|
---|
| 120 |
|
---|
| 121 | echo "root::${LASTCHG}:0:99999:7:::" > ${LFS}/etc/shadow
|
---|
| 122 | echo "plfstest:!:${LASTCHG}:0:99999:7:::" >> ${LFS}/etc/shadow
|
---|
| 123 | echo "nobody:!:${LASTCHG}:0:99999:7:::" >> ${LFS}/etc/shadow
|
---|
| 124 | fi
|
---|
| 125 |
|
---|
| 126 | chmod 600 ${LFS}/etc/shadow
|
---|
| 127 |
|
---|
| 128 | # Note: these are from LFS book CVS 2003-03-24, but with some modifications
|
---|
| 129 | if [ ! -f ${LFS}/etc/group ]; then
|
---|
| 130 | cat > ${LFS}/etc/group << "EOF"
|
---|
| 131 | root:x:0:
|
---|
| 132 | bin:x:1:
|
---|
| 133 | sys:x:2:
|
---|
| 134 | kmem:x:3:
|
---|
| 135 | tty:x:4:
|
---|
| 136 | tape:x:5:
|
---|
| 137 | daemon:x:6:
|
---|
| 138 | floppy:x:7:
|
---|
| 139 | disk:x:8:
|
---|
| 140 | lp:x:9:
|
---|
| 141 | dialout:x:10:
|
---|
| 142 | audio:x:11:
|
---|
| 143 | wheel:x:12:
|
---|
| 144 | users:x:100:
|
---|
| 145 | nogroup:x:65534:
|
---|
| 146 | EOF
|
---|
| 147 | fi
|
---|
| 148 |
|
---|
| 149 | chmod 644 ${LFS}/etc/group
|
---|
| 150 |
|
---|
| 151 | # Create initial nsswitch.conf file
|
---|
| 152 |
|
---|
| 153 | cat > ${LFS}/etc/nsswitch.conf << "EOF"
|
---|
| 154 | passwd: files
|
---|
| 155 | shadow: files
|
---|
| 156 | group: files
|
---|
| 157 | hosts: files dns
|
---|
| 158 | EOF
|
---|
| 159 |
|
---|
| 160 | # Create files required for NSS
|
---|
| 161 |
|
---|
| 162 | # ${LFS}/etc/hosts should have been created when target-lfs-bootscripts was run.
|
---|
| 163 | # If it wasnt (???) create one here
|
---|
| 164 |
|
---|
| 165 | test -f ${LFS}/etc/hosts ||
|
---|
| 166 | echo -e "127.0.0.1\tlocalhost.localdomain\tlocalhost" > ${LFS}/etc/hosts
|
---|
| 167 |
|
---|
| 168 | chmod 644 ${LFS}/etc/hosts
|
---|
| 169 |
|
---|
| 170 | # TODO: need to install
|
---|
| 171 | test -f ${LFS}/etc/resolv.conf ||
|
---|
| 172 | touch ${LFS}/etc/resolv.conf
|
---|
| 173 |
|
---|
| 174 | chmod 644 ${LFS}/etc/resolv.conf
|
---|
| 175 |
|
---|
| 176 | # This fstab is merely a template, you will have to edit the / entry before
|
---|
| 177 | # attempting to boot a rw root filesystem.
|
---|
| 178 |
|
---|
| 179 | cat > ${LFS}/etc/fstab << "EOF"
|
---|
| 180 | #/dev/BOOT /boot ext2 noauto,noatime 1 1
|
---|
| 181 | #/dev/ROOT / xfs noatime 0 0
|
---|
| 182 | #/dev/SWAP none swap sw 0 0
|
---|
| 183 | #/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
|
---|
| 184 | #/dev/fd0 /mnt/floppy auto noauto 0 0
|
---|
| 185 | none /proc proc defaults 0 0
|
---|
| 186 | none /dev/pts devpts gid=4,mode=620 0 0
|
---|
| 187 | none /dev/shm tmpfs defaults 0 0
|
---|
| 188 | EOF
|
---|
| 189 |
|
---|
| 190 | case ${KERNEL_VER} in
|
---|
| 191 | 2.5* | 2.6* )
|
---|
| 192 | echo "none /sys sysfs defaults 0 0" >> ${LFS}/etc/fstab
|
---|
| 193 | ;;
|
---|
| 194 | esac
|
---|
| 195 |
|
---|
| 196 | chmod 644 ${LFS}/etc/fstab
|
---|
| 197 |
|
---|
| 198 | # We create /etc/shells for the benefit of inetutils ftpd
|
---|
| 199 |
|
---|
| 200 | cat > ${LFS}/etc/shells << "EOF"
|
---|
| 201 | /bin/sh
|
---|
| 202 | /bin/bash
|
---|
| 203 | EOF
|
---|
| 204 |
|
---|
| 205 | chmod 644 ${LFS}/etc/shells
|
---|
| 206 |
|
---|
| 207 | # TODO: need to create some (if not all) of the following
|
---|
| 208 | # NSSFILES="ethers netmasks networks rpc netgroup automount aliases"
|
---|
| 209 |
|
---|
| 210 | # Unfortunately we can't just chown to root only the stuff owned by the user
|
---|
| 211 | # running the build. That is because some installers created files with
|
---|
| 212 | # certain group and user rights (bin, tty, etc). This gets screwed up if
|
---|
| 213 | # the build host doesn't have identical system accounts to those in the
|
---|
| 214 | # passwd file we just installed. So we chown the whole damn thing to root, being
|
---|
| 215 | # careful of sticky, SGID and SUID files. Some systems clear those bits upon
|
---|
| 216 | # chown.
|
---|
| 217 | # The ch. 6 build will have to overwrite all of the problems this causes.
|
---|
| 218 |
|
---|
| 219 | cd ${LFS}
|
---|
| 220 | ( echo "These SUID files are having their user changed to root:"
|
---|
| 221 | find . -user 0 -o \( -perm +4000 -print \)
|
---|
| 222 | echo "These SGID files are having their group changed to root:"
|
---|
| 223 | find . -group 0 -o \( -perm +2000 -print \)
|
---|
| 224 | echo "These sticky directories are having their user/group changed to root:"
|
---|
| 225 | find . \( -user 0 -group 0 \) -o \( -perm +1000 -print \)
|
---|
| 226 | echo "These world writable executables are being made non-world writable:"
|
---|
| 227 | find . -type f -perm +111 -perm -2 -print
|
---|
| 228 | find . -type f -perm +111 -perm -2 -exec chmod o-w \{\} \; ) | tee -a ${LOGFILE}
|
---|
| 229 | chown -R 0 ${LFS}
|
---|
| 230 | chgrp -R 0 ${LFS}
|
---|
| 231 |
|
---|
| 232 | echo export PS1="'"'\u@\h \W$ '"'" >${LFS}/etc/profile
|
---|
| 233 | echo export PATH=/bin:/usr/bin:/sbin:/usr/sbin:${TGT_TOOLS}/bin:${TGT_TOOLS}/sbin:${TGT_TOOLS}/usr/bin >>${LFS}/etc/profile
|
---|
| 234 |
|
---|
| 235 | echo " o All OK"
|
---|