2a461c30d091c036eb3f815c8a889a6186911b95
[dragonfly.git] / sbin / mkinitrd / mkinitrd.sh
1 #!/bin/sh
2
3 BUILD_DIR="/tmp/initrd"
4 INITRD_SIZE="15m"
5 BIN_TOOLS="echo ln ls mv rm rmdir sh"
6 SBIN_TOOLS="mount mount_devfs mount_hammer mount_nfs mount_null mount_procfs mount_tmpfs umount iscontrol"
7 INITRD_DIRS="bin boot dev etc mnt proc sbin tmp var new_root"
8 CONTENT_DIRS="/usr/share/initrd"
9
10 if [ -e /etc/defaults/mkinitrd.conf ]; then
11         . /etc/defaults/mkinitrd.conf
12         echo "Loaded configuration from /etc/defaults/mkinitrd.conf"
13 fi
14
15
16 if [ -e /etc/mkinitrd.conf ]; then
17         . /etc/mkinitrd.conf
18         echo "Loaded configuration from /etc/mkinitrd.conf"
19 fi
20
21 VN_DEV=""
22
23 create_vn() {
24         if [ ! -d  $BUILD_DIR ]; then
25                 mkdir -p $BUILD_DIR
26                 echo "Created build directory $BUILD_DIR"
27         fi
28         VN_DEV=`vnconfig -c -S ${INITRD_SIZE} -Z -T vn initrd.img | cut -f 2 -d ' '`
29         echo "Configured $VN_DEV"
30         newfs /dev/${VN_DEV}s0
31         echo "Formatted initrd image with UFS"
32         mount /dev/${VN_DEV}s0 $BUILD_DIR
33         echo "Mounted initrd image on ${BUILD_DIR}"
34 }
35
36 destroy_vn() {
37         umount /dev/${VN_DEV}s0
38         echo "Unmounted initrd image"
39         vnconfig -u $VN_DEV
40         echo "Unconfigured $VN_DEV"
41 }
42
43 make_hier() {
44         for dir in ${INITRD_DIRS}; do
45                 mkdir -p ${BUILD_DIR}/${dir}
46         done
47
48         echo "Created directory structure"
49 }
50
51 copy_tools() {
52         for tool in ${BIN_TOOLS}; do
53                 objcopy -S /bin/${tool} ${BUILD_DIR}/bin/${tool}
54         done
55
56         for tool in ${SBIN_TOOLS}; do
57                 objcopy -S /sbin/${tool} ${BUILD_DIR}/sbin/${tool}
58         done
59
60         echo "Copied essential tools"
61 }
62
63 copy_content() {
64         for dir in ${CONTENT_DIRS}; do
65                 cp -R ${dir}/* ${BUILD_DIR}/
66         done
67 }
68
69 print_info() {
70 #       tree ${BUILD_DIR}
71         df -h | head -n 1
72         df -h | grep $VN_DEV
73 }
74
75 create_vn
76 make_hier
77 copy_tools
78 copy_content
79 print_info
80 destroy_vn
81 mv initrd.img /boot/initrd.img