root / common_linux.sh @ aa661a7e
History | View | Annotate | Download (6.3 kB)
1 |
|
---|---|
2 |
get_os_type() { |
3 |
target=$1 |
4 |
if [ -z "${target}" ] ; then |
5 |
log_error "target is not set in get_os_type" |
6 |
exit 1 |
7 |
fi |
8 |
if [ -e ${target}/etc/redhat-release ] ; then |
9 |
OS_TYPE="redhat" |
10 |
elif [ -e ${target}/etc/debian_version ] ; then |
11 |
OS_TYPE="debian" |
12 |
elif [ -e ${target}/etc/gentoo-release ] ; then |
13 |
OS_TYPE="gentoo" |
14 |
elif [ -e ${target}/etc/SuSE-release ] ; then |
15 |
OS_TYPE="suse" |
16 |
fi |
17 |
} |
18 |
|
19 |
get_os() { |
20 |
target=$1 |
21 |
if [ -z "${target}" ] ; then |
22 |
log_error "target is not set in get_os" |
23 |
exit 1 |
24 |
fi |
25 |
if [ -e ${target}/etc/debian_version ] ; then |
26 |
if [ -e ${target}/etc/lsb-release ] ; then |
27 |
ID=$(grep ^DISTRIB_ID= ${target}/etc/lsb-release | cut -d= -f2) |
28 |
fi |
29 |
if [ "a$ID" = "aUbuntu" ] ; then |
30 |
OPERATING_SYSTEM="ubuntu" |
31 |
else |
32 |
OPERATING_SYSTEM="debian" |
33 |
fi |
34 |
elif [ -e ${target}/etc/gentoo-release ] ; then |
35 |
OPERATING_SYSTEM="gentoo" |
36 |
elif [ -e ${target}/etc/fedora-release ] ; then |
37 |
OPERATING_SYSTEM="fedora" |
38 |
elif [ -e ${target}/etc/redhat-release ] ; then |
39 |
if [ -n "$(grep -i centos ${target}/etc/redhat-release)" ] ; then |
40 |
OPERATING_SYSTEM="centos" |
41 |
else |
42 |
OPERATING_SYSTEM="redhat" |
43 |
fi |
44 |
fi |
45 |
} |
46 |
|
47 |
get_os_release() { |
48 |
target=$1 |
49 |
if [ -z "${target}" ] ; then |
50 |
log_error "target is not set in get_os_release" |
51 |
exit 1 |
52 |
fi |
53 |
if [ -e ${target}/etc/debian_version ] ; then |
54 |
OS_RELEASE="$(cat ${target}/etc/debian_version)" |
55 |
elif [ -e ${target}/etc/fedora-release ] ; then |
56 |
OS_RELEASE="$(cat ${target}/etc/fedora-release | awk '{print $3}')" |
57 |
elif [ -e ${$target}/etc/redhat-release ] ; then |
58 |
OS_RELEASE="$(cat ${target}/etc/redhat-release | awk '{print $3}')" |
59 |
fi |
60 |
} |
61 |
|
62 |
linux_format_disk0() { |
63 |
local sfdisk_cmd="$SFDISK -uM -H 255 -S 63 --quiet --Linux --DOS $1" |
64 |
if [ "${SWAP}" = "yes" -a "${BOOT}" = "yes" ] ; then |
65 |
# Create three partitions: |
66 |
# 1 - 100MB /boot, bootable |
67 |
# 2 - Size of Memory, swap |
68 |
# 3 - Rest |
69 |
$sfdisk_cmd > /dev/null <<EOF |
70 |
,100,L,* |
71 |
,${SWAP_SIZE},S |
72 |
,,L |
73 |
EOF |
74 |
elif [ "${SWAP}" = "no" -a "${BOOT}" = "yes" ] ; then |
75 |
# Create two partitions: |
76 |
# 1 - 100MB /boot, bootable |
77 |
# 2 - Rest |
78 |
$sfdisk_cmd > /dev/null <<EOF |
79 |
,100,L,* |
80 |
,,L |
81 |
EOF |
82 |
elif [ "${SWAP}" = "yes" -a "${BOOT}" = "no" ] ; then |
83 |
# Create two partitions: |
84 |
# 1 - Size of Memory, swap |
85 |
# 2 - Rest |
86 |
$sfdisk_cmd > /dev/null <<EOF |
87 |
,$SWAP_SIZE,S |
88 |
,,L |
89 |
EOF |
90 |
elif [ "${SWAP}" = "no" -a "${BOOT}" = "no" ] ; then |
91 |
# Create two partitions: |
92 |
# 1 - Whole |
93 |
$sfdisk_cmd > /dev/null <<EOF |
94 |
,,L |
95 |
EOF |
96 |
fi |
97 |
} |
98 |
|
99 |
linux_mkfs_disk0() { |
100 |
local mkfs="mkfs.${FILESYSTEM}" |
101 |
|
102 |
if [[ "$FILESYSTEM" == ext[123] ]] ; then |
103 |
# Some GRUB legacy versions like the one used by CentOS 5.x have issues |
104 |
# with 256 byte inode size which is the default for recent versions of |
105 |
# e2fsprogs. We'll stick with 128 bytes for now. |
106 |
mkfs+=" -I 128" |
107 |
fi |
108 |
|
109 |
# Format / |
110 |
$mkfs -Fq -L / $root_dev > /dev/null |
111 |
# Format /boot |
112 |
if [ -n "${boot_dev}" ] ; then |
113 |
$mkfs -Fq -L /boot $boot_dev > /dev/null |
114 |
fi |
115 |
# Format swap |
116 |
if [ -n "${swap_dev}" ] ; then |
117 |
# Format swap |
118 |
mkswap -f $swap_dev > /dev/null |
119 |
fi |
120 |
# During reinstalls, ext4 needs a little time after a mkfs so add it here |
121 |
# and also run a sync to be sure. |
122 |
sync |
123 |
sleep 2 |
124 |
} |
125 |
|
126 |
linux_setup_fstab() { |
127 |
local target=$1 fs=${FILESYSTEM} |
128 |
get_os_type $target |
129 |
cat > $target/etc/fstab <<EOF |
130 |
# /etc/fstab: static file system information. |
131 |
# |
132 |
# <file system> <mount point> <type> <options> <dump> <pass> |
133 |
UUID=$root_uuid / $fs defaults 0 1 |
134 |
proc /proc proc defaults 0 0 |
135 |
EOF |
136 |
|
137 |
if [ -n "$boot_dev" -a -n "$boot_uuid" ] ; then |
138 |
cat >> $target/etc/fstab <<EOF |
139 |
UUID=$boot_uuid /boot $fs defaults 1 2 |
140 |
EOF |
141 |
fi |
142 |
|
143 |
if [ -n "$swap_dev" -a -n "$swap_uuid" ] ; then |
144 |
cat >> $target/etc/fstab <<EOF |
145 |
UUID=$swap_uuid swap swap defaults 0 0 |
146 |
EOF |
147 |
fi |
148 |
|
149 |
# OS Specific fstabs |
150 |
if [ "$OS_TYPE" = "redhat" ] ; then |
151 |
cat >> $target/etc/fstab <<EOF |
152 |
tmpfs /dev/shm tmpfs defaults 0 0 |
153 |
devpts /dev/pts devpts gid=5,mode=620 0 0 |
154 |
sysfs /sys sysfs defaults 0 0 |
155 |
EOF |
156 |
fi |
157 |
|
158 |
if [ "$OS_TYPE" = "gentoo" ] ; then |
159 |
cat >> $target/etc/fstab <<EOF |
160 |
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0 |
161 |
EOF |
162 |
fi |
163 |
} |
164 |
|
165 |
linux_setup_console() { |
166 |
local target=$1 |
167 |
if [ -z "$target" ] ; then |
168 |
log_error "target not set for setup_console" |
169 |
exit 1 |
170 |
fi |
171 |
# Upstart is on this system, so do this instead |
172 |
if [ -e ${target}/etc/event.d/tty1 ] ; then |
173 |
cat ${target}/etc/event.d/tty1 | sed -re 's/tty1/ttyS0/' \ |
174 |
> ${target}/etc/event.d/ttyS0 |
175 |
return |
176 |
fi |
177 |
# upstart in karmic and newer |
178 |
if [ -e ${target}/etc/init/tty1.conf ] ; then |
179 |
cat ${target}/etc/init/tty1.conf | \ |
180 |
sed -re 's/^exec.*/exec \/sbin\/getty -L 115200 ttyS0 vt102/' \ |
181 |
> ${target}/etc/init/ttyS0.conf |
182 |
sed -ie 's/tty1/ttyS0/g' ${target}/etc/init/ttyS0.conf |
183 |
return |
184 |
fi |
185 |
get_os $target |
186 |
case $OPERATING_SYSTEM in |
187 |
gentoo) |
188 |
sed -i -e 's/.*ttyS0.*/s0:12345:respawn:\/sbin\/agetty 115200 ttyS0 vt100/' \ |
189 |
${target}/etc/inittab |
190 |
;; |
191 |
centos) |
192 |
echo "s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100" >> \ |
193 |
${target}/etc/inittab |
194 |
;; |
195 |
debian|ubuntu) |
196 |
sed -i -e 's/.*T0.*/T0:23:respawn:\/sbin\/getty -L ttyS0 115200 vt100/' \ |
197 |
${target}/etc/inittab |
198 |
;; |
199 |
*) |
200 |
echo "No support for your OS in instance-image, skipping..." |
201 |
;; |
202 |
esac |
203 |
} |
204 |
|
205 |
linux_epilogue() { |
206 |
local target=$1 |
207 |
if [ -z "$target" ] ; then |
208 |
log_error "target not set" |
209 |
exit 1 |
210 |
fi |
211 |
|
212 |
get_os_type $target |
213 |
|
214 |
if [ "${OS_TYPE}" = "redhat" ]; then |
215 |
# we have to force a filesystem relabeling for SELinux after messing |
216 |
# around with the filesystem in redhat derived OSs |
217 |
echo "Enforce an automatic relabeling in the initial boot process..." |
218 |
touch $target/.autorelabel |
219 |
fi |
220 |
} |
221 |
|