vmimage.subr (e6e746bfb086d563bf0ad454a33ecbcab8836dbf) vmimage.subr (963412283a1752b3b6f67bb86940c9d166a59e67)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5#
6# Common functions for virtual machine image build scripts.
7#
8

--- 31 unchanged lines hidden (view full) ---

40
41err() {
42 printf "${@}\n"
43 cleanup
44 return 1
45}
46
47cleanup() {
1#!/bin/sh
2#
3# $FreeBSD$
4#
5#
6# Common functions for virtual machine image build scripts.
7#
8

--- 31 unchanged lines hidden (view full) ---

40
41err() {
42 printf "${@}\n"
43 cleanup
44 return 1
45}
46
47cleanup() {
48 umount ${DESTDIR}/dev 2>/dev/null
49 umount ${DESTDIR}
48 if mount | grep -qE "devfs on ${DESTDIR}/dev"; then
49 umount_loop ${DESTDIR}/dev 2>/dev/null
50 fi
51 umount_loop ${DESTDIR}
50 if [ ! -z "${mddev}" ]; then
51 mdconfig -d -u ${mddev}
52 fi
53
54 return 0
55}
56
57vm_create_base() {

--- 23 unchanged lines hidden (view full) ---

81 truncate -s ${VMSIZE} ${VMBASE}.tmp
82 mkdir -p ${DESTDIR}/new
83 mdnew=$(mdconfig -f ${VMBASE}.tmp)
84 newfs -j /dev/${mdnew}
85 mount /dev/${mdnew} ${DESTDIR}/new
86
87 tar -cf- -C ${DESTDIR}/old . | tar -xf- -C ${DESTDIR}/new
88
52 if [ ! -z "${mddev}" ]; then
53 mdconfig -d -u ${mddev}
54 fi
55
56 return 0
57}
58
59vm_create_base() {

--- 23 unchanged lines hidden (view full) ---

83 truncate -s ${VMSIZE} ${VMBASE}.tmp
84 mkdir -p ${DESTDIR}/new
85 mdnew=$(mdconfig -f ${VMBASE}.tmp)
86 newfs -j /dev/${mdnew}
87 mount /dev/${mdnew} ${DESTDIR}/new
88
89 tar -cf- -C ${DESTDIR}/old . | tar -xf- -C ${DESTDIR}/new
90
89 umount /dev/${mdold}
91 umount_loop /dev/${mdold}
90 rmdir ${DESTDIR}/old
91 mdconfig -d -u ${mdold}
92
92 rmdir ${DESTDIR}/old
93 mdconfig -d -u ${mdold}
94
93 umount /dev/${mdnew}
95 umount_loop /dev/${mdnew}
94 rmdir ${DESTDIR}/new
95 mdconfig -d -u ${mdnew}
96 mv ${VMBASE}.tmp ${VMBASE}
97}
98
99vm_install_base() {
100 # Installs the FreeBSD userland/kernel to the virtual machine disk.
101

--- 10 unchanged lines hidden (view full) ---

112 echo '/dev/gpt/swapfs none swap sw 0 0' \
113 >> ${DESTDIR}/etc/fstab
114 fi
115
116 mkdir -p ${DESTDIR}/dev
117 mount -t devfs devfs ${DESTDIR}/dev
118 chroot ${DESTDIR} /usr/bin/newaliases
119 chroot ${DESTDIR} /etc/rc.d/ldconfig forcestart
96 rmdir ${DESTDIR}/new
97 mdconfig -d -u ${mdnew}
98 mv ${VMBASE}.tmp ${VMBASE}
99}
100
101vm_install_base() {
102 # Installs the FreeBSD userland/kernel to the virtual machine disk.
103

--- 10 unchanged lines hidden (view full) ---

114 echo '/dev/gpt/swapfs none swap sw 0 0' \
115 >> ${DESTDIR}/etc/fstab
116 fi
117
118 mkdir -p ${DESTDIR}/dev
119 mount -t devfs devfs ${DESTDIR}/dev
120 chroot ${DESTDIR} /usr/bin/newaliases
121 chroot ${DESTDIR} /etc/rc.d/ldconfig forcestart
120 umount ${DESTDIR}/dev
122 umount_loop ${DESTDIR}/dev
121
122 cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf
123
124 return 0
125}
126
127vm_extra_install_base() {
128 # Prototype. When overridden, runs extra post-installworld commands

--- 18 unchanged lines hidden (view full) ---

147 return 0
148 fi
149 mkdir -p ${DESTDIR}/dev
150 mount -t devfs devfs ${DESTDIR}/dev
151 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
152 /usr/sbin/pkg bootstrap -y
153 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
154 /usr/sbin/pkg install -y ${VM_EXTRA_PACKAGES}
123
124 cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf
125
126 return 0
127}
128
129vm_extra_install_base() {
130 # Prototype. When overridden, runs extra post-installworld commands

--- 18 unchanged lines hidden (view full) ---

149 return 0
150 fi
151 mkdir -p ${DESTDIR}/dev
152 mount -t devfs devfs ${DESTDIR}/dev
153 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
154 /usr/sbin/pkg bootstrap -y
155 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
156 /usr/sbin/pkg install -y ${VM_EXTRA_PACKAGES}
155 umount ${DESTDIR}/dev
157 umount_loop ${DESTDIR}/dev
156
157 return 0
158}
159
160vm_extra_install_ports() {
161 # Prototype. When overridden, installs additional ports within the
162 # virtual machine environment.
163

--- 12 unchanged lines hidden (view full) ---

176 if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then
177 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
178 /usr/local/sbin/pkg clean -y -a
179 fi
180
181 return 0
182}
183
158
159 return 0
160}
161
162vm_extra_install_ports() {
163 # Prototype. When overridden, installs additional ports within the
164 # virtual machine environment.
165

--- 12 unchanged lines hidden (view full) ---

178 if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then
179 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
180 /usr/local/sbin/pkg clean -y -a
181 fi
182
183 return 0
184}
185
184vm_umount_base() {
186umount_loop() {
187 DIR=$1
185 i=0
186 sync
188 i=0
189 sync
187 while ! umount ${DESTDIR}/dev ${DESTDIR}; do
190 while ! umount ${DIR}; do
188 i=$(( $i + 1 ))
189 if [ $i -ge 10 ]; then
190 # This should never happen. But, it has happened.
191 i=$(( $i + 1 ))
192 if [ $i -ge 10 ]; then
193 # This should never happen. But, it has happened.
191 msg="Cannot umount(8) ${DESTDIR}\n"
192 msg="${msg}Something has gone horribly wrong."
193 err "${msg}"
194 echo "Cannot umount(8) ${DIR}"
195 echo "Something has gone horribly wrong."
196 return 1
194 fi
195 sleep 1
196 done
197
198 return 0
199}
200
201vm_create_disk() {

--- 13 unchanged lines hidden ---
197 fi
198 sleep 1
199 done
200
201 return 0
202}
203
204vm_create_disk() {

--- 13 unchanged lines hidden ---