-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-0.6.sh
86 lines (69 loc) · 2.58 KB
/
gen-0.6.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
source ./my-utils.sh
cwd=`pwd`
target_path=$cwd/initrd-0.6
prepare_060() {
echo "Generating dir at $target_path"
check_delete $target_path
create_dir $target_path
cd $target_path
create_dir dev proc etc lib/modules sys root var/log var/run lib64
# copy /lib/modules
lib_list="scsi_transport_spi mptbase mptscsih mptspi cdrom sr_mod crc_t10dif sd_mod jbd2 mbcache ext4"
for lib_mod in $lib_list
do
mod_path=`modinfo $lib_mod | awk '{print $2}' | sed -n '1,1p'`
check_copy $mod_path $target_path
done
cp /lib/modules/2.6.32-431.el6.x86_64/modules.* $target_path/lib/modules/2.6.32-431.el6.x86_64/
# copy /lib/udev, /etc/udev, /etc/nsswitch.conf, /lib/libnss*
cp -r /lib/udev $target_path/lib/
cp -r /etc/udev $target_path/etc/
cp /etc/nsswitch.conf $target_path/etc/
cp /lib64/libnss* $target_path/lib64/
# fix some bugs of udev
check_copy /etc/sysconfig/udev $target_path
cp /etc/sysconfig/network $target_path/etc/sysconfig/
cp -r /etc/rc.d/init.d $target_path/etc/
cp /etc/passwd $target_path/etc/
cp /etc/group $target_path/etc/
echo '#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
export PS1="[\s-\v] \w \$ "
mknod /dev/null c 1 3
mknod /dev/console c 5 1
mount -t proc proc /proc > /dev/null 2>&1
mount -t sysfs sysfs /sys > /dev/null 2>&1
start_udev
mknod /dev/sda2 b 8 2
mount -t ext4 /dev/sda2 /root
/bin/bash' > $target_path/init
chmod 755 $target_path/init
}
generate_060() {
cd $cwd
./autocopy.sh $target_path
./autopack.sh $target_path
UUID=$(ls -l /dev/disk/by-uuid | grep sda2 | awk '{print $9}')
grub_path=/boot/grub/grub.conf
imgname=$(echo $target_path | sed -e 's/\/[^ ]*\///g').img
if [[ ! -f /boot/grub/grub.conf.bak ]]
then
/bin/cp -f $grub_path /boot/grub/grub.conf.bak
fi
/bin/cp -f /boot/grub/grub.conf.bak $grub_path
echo -e "title CentOS (0.6 with udev) [auto-gen]" >> $grub_path
echo -e "\troot (hd0,0)" >> $grub_path
echo -e "\tkernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=$UUID" >> $grub_path
echo -e "\tinitrd /$imgname" >> $grub_path
if [[ -f /boot/grub/grub0.6.conf ]]
then
rm -f /boot/grub/grub0.6.conf
fi
cp $grub_path /boot/grub/grub0.6.conf
echo -e "\n============================================================================\n"
echo -e "Successfully generate /boot/grub/grub.conf, now you can reboot to enjoy it:)"
echo -e "\n============================================================================\n"
}
prepare_060
generate_060