The Gentoo Handbook provides detailed instructions for preparing a
/mnt/gentoo
file system tree for new installations.  After having to dig through the
Handbook a
few times of doing new or re-installs of Gentoo using an existing Gentoo
install
as the base system, I wrote this script as a shortcut way to handle the
process
of doing the mounting of /mnt/gentoo either the first time or again after a
re-boot.

1.  The device containing the new file-system for the chroot MUST be already
     made with mkfs.

2.  Read through the script and remove, add, or change directory creations
or
     bind/rbind mounts for your environment.

3.  This presumes that the sudo command is available and set up for group
     wheel to have access to all commands with :NOPASSWD
     and that you are a member of group wheel.

4.  Newer file-system types, such as ext4 or btrfs, do not really care
about the
     sequence of directories made in the root. (I just have this habit from
doing
     things on systems that did care.)

5.  Watch out for email line wrapping in inappropriate places.

6.  Enjoy a hopefully easier experience.



------<cut here>-----------------------------------------------
#!/bin/bash
#
# script to mount the devices for a new chroot of /mnt/gentoo for building
a new system
#
# 2015-05-02 ggw        first version
# 2016-01-23 ggw        2nd version
# 2016-02-06 ggw         some additions
#
# function usage
function usage {
        echo "usage:    $0 <disk-dev>"
        echo "  where <disk-dev> is the partition to mount as /mnt/gentoo"

        exit 1
}

# check for required argument and then its type
if [ $# -lt 1 ]                         # no argument given?
then
        usage;
elif [ ! -b $1 ]                        # it is not a block device?
then
        usage;
fi

# presume the argument is what it claims to be FIXME

# this needs sudo setup properly, too hard to really check for now
rEUID=`id -u`   # who are we?
if [ $rEUID -eq 0 ]     #root?
then
        prefix=""
else
        prefix="/usr/bin/sudo"
fi

# make sure /mnt/gentoo exists
if [ ! -d /mnt/gentoo ]
then
        echo "WARNING: /mnt/gentoo does not exist!"
        eval $prefix mkdir /mnt/gentoo
fi

# mount the block device to /mnt/gentoo
 eval $prefix mount $1 /mnt/gentoo
 if [ $? -ne 0 ]
 then
        echo "FAILURE: cound not mount device, code = " $?
        exit 3
 fi

# now mount the proc, dev and sys pseudo-filesystems
 eval $prefix mkdir -p /mnt/gentoo/proc
 eval $prefix mount -t proc proc /mnt/gentoo/proc
 if [ $? -ne 0 ]
 then
        echo "FAILURE: could not add new proc filesystem to /mnt/gentoo"
        exit 4
 fi

 eval $prefix mkdir -p /mnt/gentoo/dev
 eval $prefix mount --rbind /dev /mnt/gentoo/dev
 if [ $? -ne 0 ]
 then
        echo "FAILURE: cound not bind /dev to /mnt/gentoo/dev"
        exit 5
 fi

 eval $prefix mkdir -p /mnt/gentoo/sys
 eval $prefix mount --rbind /sys /mnt/gentoo/sys
 if [ $? -ne 0 ]
 then
        echo "FAILURE: could not bind /sys to /mnt/gentoo/sys"
        exit 6
 fi

# check other root directories and make them if necessary
pushd /mnt/gentoo 2>&1 >/dev/null

umask 0002

if [ ! -d run      ]; then eval $prefix mkdir run;      fi
if [ ! -d boot     ]; then eval $prefix mkdir boot;     fi
if [ ! -d home     ]; then eval $prefix mkdir home;     fi
if [ ! -d bin      ]; then eval $prefix mkdir bin;      fi
if [ ! -d sbin     ]; then eval $prefix mkdir sbin;     fi
if [ ! -d etc      ]; then eval $prefix mkdir etc;      eval $prefix chgrp
wheel etc;   fi
if [ ! -d lib64    ]; then eval $prefix mkdir lib64;    fi
if [ ! -d lib32    ]; then eval $prefix mkdir lib32;    fi
if [ `uname -m` == "x86_64" ]; then eval $prefix ln -s lib64 lib; fi
if [ ! -d tmp      ]; then eval $prefix mkdir tmp;      eval $prefix chmod
1777 tmp;    fi
if [ ! -d usr      ]; then eval $prefix mkdir usr;      fi
if [ ! -d usr/bin  ]; then eval $prefix mkdir usr/bin;  fi
if [ ! -d usr/sbin ]; then eval $prefix mkdir usr/sbin; fi
if [ ! -d root     ]; then eval $prefix mkdir root;     eval $prefix chgrp
wheel root; eval $prefix chmod 0771 root; fi
if [ ! -d var      ]; then eval $prefix mkdir var;      fi
if [ ! -d opt      ]; then eval $prefix mkdir opt;      fi
if [ ! -d mnt      ]; then eval $prefix mkdir mnt;      fi
if [ ! -d media    ]; then eval $prefix mkdir media;    fi
if [ ! -d srv      ]; then eval $prefix mkdir srv;      fi

popd 2>&1 >/dev/null

# try rbind mounting of some standard mountpoints (2016-02-06)
 eval $prefix mount --rbind /boot /mnt/gentoo/boot
 eval $prefix mount --rbind /home /mnt/gentoo/home
 findmnt -n /srv && eval $prefix mount --rbind /srv /mnt/gentoo/srv
# 2016-02-21 ggw        for convenience, mount the distfiles collection
 eval $prefix mkdir -p /mnt/gentoo/usr/portage/distfiles && eval $prefix
mount --rbind /usr/portage/distfiles /mnt/gentoo/usr/portage/distfiles

# so far, so good: tell user to mount any other needed filesystems befor
chroot'ing
echo "SUCCESS: mount any other desired filesystems before chroot'ing to new
instance"

exit 0
#sh vim: set noai textwidth=0 ft=bash
------<cut here>-----------------------------------------------

-- 
G.Wolfe Woodbury
redwo...@gmail.com

Reply via email to