1 |
The Gentoo Handbook provides detailed instructions for preparing a |
2 |
/mnt/gentoo |
3 |
file system tree for new installations. After having to dig through the |
4 |
Handbook a |
5 |
few times of doing new or re-installs of Gentoo using an existing Gentoo |
6 |
install |
7 |
as the base system, I wrote this script as a shortcut way to handle the |
8 |
process |
9 |
of doing the mounting of /mnt/gentoo either the first time or again after a |
10 |
re-boot. |
11 |
|
12 |
1. The device containing the new file-system for the chroot MUST be already |
13 |
made with mkfs. |
14 |
|
15 |
2. Read through the script and remove, add, or change directory creations |
16 |
or |
17 |
bind/rbind mounts for your environment. |
18 |
|
19 |
3. This presumes that the sudo command is available and set up for group |
20 |
wheel to have access to all commands with :NOPASSWD |
21 |
and that you are a member of group wheel. |
22 |
|
23 |
4. Newer file-system types, such as ext4 or btrfs, do not really care |
24 |
about the |
25 |
sequence of directories made in the root. (I just have this habit from |
26 |
doing |
27 |
things on systems that did care.) |
28 |
|
29 |
5. Watch out for email line wrapping in inappropriate places. |
30 |
|
31 |
6. Enjoy a hopefully easier experience. |
32 |
|
33 |
|
34 |
|
35 |
------<cut here>----------------------------------------------- |
36 |
#!/bin/bash |
37 |
# |
38 |
# script to mount the devices for a new chroot of /mnt/gentoo for building |
39 |
a new system |
40 |
# |
41 |
# 2015-05-02 ggw first version |
42 |
# 2016-01-23 ggw 2nd version |
43 |
# 2016-02-06 ggw some additions |
44 |
# |
45 |
# function usage |
46 |
function usage { |
47 |
echo "usage: $0 <disk-dev>" |
48 |
echo " where <disk-dev> is the partition to mount as /mnt/gentoo" |
49 |
|
50 |
exit 1 |
51 |
} |
52 |
|
53 |
# check for required argument and then its type |
54 |
if [ $# -lt 1 ] # no argument given? |
55 |
then |
56 |
usage; |
57 |
elif [ ! -b $1 ] # it is not a block device? |
58 |
then |
59 |
usage; |
60 |
fi |
61 |
|
62 |
# presume the argument is what it claims to be FIXME |
63 |
|
64 |
# this needs sudo setup properly, too hard to really check for now |
65 |
rEUID=`id -u` # who are we? |
66 |
if [ $rEUID -eq 0 ] #root? |
67 |
then |
68 |
prefix="" |
69 |
else |
70 |
prefix="/usr/bin/sudo" |
71 |
fi |
72 |
|
73 |
# make sure /mnt/gentoo exists |
74 |
if [ ! -d /mnt/gentoo ] |
75 |
then |
76 |
echo "WARNING: /mnt/gentoo does not exist!" |
77 |
eval $prefix mkdir /mnt/gentoo |
78 |
fi |
79 |
|
80 |
# mount the block device to /mnt/gentoo |
81 |
eval $prefix mount $1 /mnt/gentoo |
82 |
if [ $? -ne 0 ] |
83 |
then |
84 |
echo "FAILURE: cound not mount device, code = " $? |
85 |
exit 3 |
86 |
fi |
87 |
|
88 |
# now mount the proc, dev and sys pseudo-filesystems |
89 |
eval $prefix mkdir -p /mnt/gentoo/proc |
90 |
eval $prefix mount -t proc proc /mnt/gentoo/proc |
91 |
if [ $? -ne 0 ] |
92 |
then |
93 |
echo "FAILURE: could not add new proc filesystem to /mnt/gentoo" |
94 |
exit 4 |
95 |
fi |
96 |
|
97 |
eval $prefix mkdir -p /mnt/gentoo/dev |
98 |
eval $prefix mount --rbind /dev /mnt/gentoo/dev |
99 |
if [ $? -ne 0 ] |
100 |
then |
101 |
echo "FAILURE: cound not bind /dev to /mnt/gentoo/dev" |
102 |
exit 5 |
103 |
fi |
104 |
|
105 |
eval $prefix mkdir -p /mnt/gentoo/sys |
106 |
eval $prefix mount --rbind /sys /mnt/gentoo/sys |
107 |
if [ $? -ne 0 ] |
108 |
then |
109 |
echo "FAILURE: could not bind /sys to /mnt/gentoo/sys" |
110 |
exit 6 |
111 |
fi |
112 |
|
113 |
# check other root directories and make them if necessary |
114 |
pushd /mnt/gentoo 2>&1 >/dev/null |
115 |
|
116 |
umask 0002 |
117 |
|
118 |
if [ ! -d run ]; then eval $prefix mkdir run; fi |
119 |
if [ ! -d boot ]; then eval $prefix mkdir boot; fi |
120 |
if [ ! -d home ]; then eval $prefix mkdir home; fi |
121 |
if [ ! -d bin ]; then eval $prefix mkdir bin; fi |
122 |
if [ ! -d sbin ]; then eval $prefix mkdir sbin; fi |
123 |
if [ ! -d etc ]; then eval $prefix mkdir etc; eval $prefix chgrp |
124 |
wheel etc; fi |
125 |
if [ ! -d lib64 ]; then eval $prefix mkdir lib64; fi |
126 |
if [ ! -d lib32 ]; then eval $prefix mkdir lib32; fi |
127 |
if [ `uname -m` == "x86_64" ]; then eval $prefix ln -s lib64 lib; fi |
128 |
if [ ! -d tmp ]; then eval $prefix mkdir tmp; eval $prefix chmod |
129 |
1777 tmp; fi |
130 |
if [ ! -d usr ]; then eval $prefix mkdir usr; fi |
131 |
if [ ! -d usr/bin ]; then eval $prefix mkdir usr/bin; fi |
132 |
if [ ! -d usr/sbin ]; then eval $prefix mkdir usr/sbin; fi |
133 |
if [ ! -d root ]; then eval $prefix mkdir root; eval $prefix chgrp |
134 |
wheel root; eval $prefix chmod 0771 root; fi |
135 |
if [ ! -d var ]; then eval $prefix mkdir var; fi |
136 |
if [ ! -d opt ]; then eval $prefix mkdir opt; fi |
137 |
if [ ! -d mnt ]; then eval $prefix mkdir mnt; fi |
138 |
if [ ! -d media ]; then eval $prefix mkdir media; fi |
139 |
if [ ! -d srv ]; then eval $prefix mkdir srv; fi |
140 |
|
141 |
popd 2>&1 >/dev/null |
142 |
|
143 |
# try rbind mounting of some standard mountpoints (2016-02-06) |
144 |
eval $prefix mount --rbind /boot /mnt/gentoo/boot |
145 |
eval $prefix mount --rbind /home /mnt/gentoo/home |
146 |
findmnt -n /srv && eval $prefix mount --rbind /srv /mnt/gentoo/srv |
147 |
# 2016-02-21 ggw for convenience, mount the distfiles collection |
148 |
eval $prefix mkdir -p /mnt/gentoo/usr/portage/distfiles && eval $prefix |
149 |
mount --rbind /usr/portage/distfiles /mnt/gentoo/usr/portage/distfiles |
150 |
|
151 |
# so far, so good: tell user to mount any other needed filesystems befor |
152 |
chroot'ing |
153 |
echo "SUCCESS: mount any other desired filesystems before chroot'ing to new |
154 |
instance" |
155 |
|
156 |
exit 0 |
157 |
#sh vim: set noai textwidth=0 ft=bash |
158 |
------<cut here>----------------------------------------------- |
159 |
|
160 |
-- |
161 |
G.Wolfe Woodbury |
162 |
redwolfe@×××××.com |