vmimage.subr (4bf53d0b4672dca72c809b44349fb82657f482f5) vmimage.subr (4b8175ee8f196b4d52d3bf0aea4af8de77955449)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5#
6# Common functions for virtual machine image build scripts.
7#
8
9export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
10trap "cleanup" INT QUIT TRAP ABRT TERM
11
12write_partition_layout() {
13 if [ -z "${NOSWAP}" ]; then
14 SWAPOPT="-p freebsd-swap/swapfs::1G"
15 fi
16
1#!/bin/sh
2#
3# $FreeBSD$
4#
5#
6# Common functions for virtual machine image build scripts.
7#
8
9export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
10trap "cleanup" INT QUIT TRAP ABRT TERM
11
12write_partition_layout() {
13 if [ -z "${NOSWAP}" ]; then
14 SWAPOPT="-p freebsd-swap/swapfs::1G"
15 fi
16
17 _OBJDIR="$(make -C ${WORLDDIR} -V .OBJDIR)"
18 if [ -d "${_OBJDIR%%/usr/src}/${TARGET}.${TARGET_ARCH}" ]; then
19 BOOTFILES="${_OBJDIR%%/usr/src}/${TARGET}.${TARGET_ARCH}/usr/src/sys/boot"
20 else
21 BOOTFILES="${_OBJDIR}/usr/src/sys/boot"
22 fi
23
17 case "${TARGET}:${TARGET_ARCH}" in
18 amd64:amd64 | i386:i386)
24 case "${TARGET}:${TARGET_ARCH}" in
25 amd64:amd64 | i386:i386)
19 mkimg -s gpt -b /boot/pmbr \
20 -p freebsd-boot/bootfs:=/boot/gptboot \
26 mkimg -s gpt -b ${BOOTFILES}/i386/pmbr/pmbr \
27 -p freebsd-boot/bootfs:=${BOOTFILES}/i386/gptboot/gptboot \
21 ${SWAPOPT} \
22 -p freebsd-ufs/rootfs:=${VMBASE} \
23 -o ${VMIMAGE}
24 ;;
25 powerpc:powerpc*)
26 mkimg -s apm \
28 ${SWAPOPT} \
29 -p freebsd-ufs/rootfs:=${VMBASE} \
30 -o ${VMIMAGE}
31 ;;
32 powerpc:powerpc*)
33 mkimg -s apm \
27 -p apple-boot/bootfs:=/boot/boot1.hfs \
34 -p apple-boot/bootfs:=${BOOTFILES}/powerpc/boot1.chrp/boot1.hfs \
28 ${SWAPOPT} \
29 -p freebsd-ufs/rootfs:=${VMBASE} \
30 -o ${VMIMAGE}
31 ;;
32 *)
33 # ENOTSUPP
34 return 1
35 ;;

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

58
59vm_create_base() {
60 # Creates the UFS root filesystem for the virtual machine disk,
61 # written to the formatted disk image with mkimg(1).
62
63 mkdir -p ${DESTDIR}
64 truncate -s ${VMSIZE} ${VMBASE}
65 mddev=$(mdconfig -f ${VMBASE})
35 ${SWAPOPT} \
36 -p freebsd-ufs/rootfs:=${VMBASE} \
37 -o ${VMIMAGE}
38 ;;
39 *)
40 # ENOTSUPP
41 return 1
42 ;;

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

65
66vm_create_base() {
67 # Creates the UFS root filesystem for the virtual machine disk,
68 # written to the formatted disk image with mkimg(1).
69
70 mkdir -p ${DESTDIR}
71 truncate -s ${VMSIZE} ${VMBASE}
72 mddev=$(mdconfig -f ${VMBASE})
66 newfs -j /dev/${mddev}
73 newfs /dev/${mddev}
67 mount /dev/${mddev} ${DESTDIR}
68
69 return 0
70}
71
72vm_copy_base() {
73 # Creates a new UFS root filesystem and copies the contents of the
74 # current root filesystem into it. This produces a "clean" disk
75 # image without any remnants of files which were created temporarily
76 # during image-creation and have since been deleted (e.g., downloaded
77 # package archives).
78
79 mkdir -p ${DESTDIR}/old
80 mdold=$(mdconfig -f ${VMBASE})
81 mount /dev/${mdold} ${DESTDIR}/old
82
83 truncate -s ${VMSIZE} ${VMBASE}.tmp
84 mkdir -p ${DESTDIR}/new
85 mdnew=$(mdconfig -f ${VMBASE}.tmp)
74 mount /dev/${mddev} ${DESTDIR}
75
76 return 0
77}
78
79vm_copy_base() {
80 # Creates a new UFS root filesystem and copies the contents of the
81 # current root filesystem into it. This produces a "clean" disk
82 # image without any remnants of files which were created temporarily
83 # during image-creation and have since been deleted (e.g., downloaded
84 # package archives).
85
86 mkdir -p ${DESTDIR}/old
87 mdold=$(mdconfig -f ${VMBASE})
88 mount /dev/${mdold} ${DESTDIR}/old
89
90 truncate -s ${VMSIZE} ${VMBASE}.tmp
91 mkdir -p ${DESTDIR}/new
92 mdnew=$(mdconfig -f ${VMBASE}.tmp)
86 newfs -j /dev/${mdnew}
93 newfs /dev/${mdnew}
87 mount /dev/${mdnew} ${DESTDIR}/new
88
94 mount /dev/${mdnew} ${DESTDIR}/new
95
89 tar -cf- -C ${DESTDIR}/old . | tar -xf- -C ${DESTDIR}/new
96 tar -cf- -C ${DESTDIR}/old . | tar -xUf- -C ${DESTDIR}/new
90
91 umount_loop /dev/${mdold}
92 rmdir ${DESTDIR}/old
93 mdconfig -d -u ${mdold}
94
95 umount_loop /dev/${mdnew}
96 rmdir ${DESTDIR}/new
97
98 umount_loop /dev/${mdold}
99 rmdir ${DESTDIR}/old
100 mdconfig -d -u ${mdold}
101
102 umount_loop /dev/${mdnew}
103 rmdir ${DESTDIR}/new
104 tunefs -j enable /dev/${mdnew}
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
104 cd ${WORLDDIR} && \

--- 113 unchanged lines hidden ---
105 mdconfig -d -u ${mdnew}
106 mv ${VMBASE}.tmp ${VMBASE}
107}
108
109vm_install_base() {
110 # Installs the FreeBSD userland/kernel to the virtual machine disk.
111
112 cd ${WORLDDIR} && \

--- 113 unchanged lines hidden ---