mkjail.sh

Check-in [2439df6e88]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge properly (I think)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:2439df6e887df33bead62767058ecd96c8df30c439696fc7774e1f7af045113a
User & Date: feld 2018-10-02 21:24:15
Context
2018-10-02
21:25
Cannot reliable use set -u in this script check-in: 32a9c7f9ae user: feld tags: master, trunk
21:24
Merge properly (I think) check-in: 2439df6e88 user: feld tags: master, trunk
21:21
Remove old scripts check-in: e309fe668f user: feld tags: master, trunk
21:11
Reliability improvements Automatic release fetching if it's not already seeded Leaf check-in: 87a9ece2e6 user: feld tags: combined
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added src/etc/mkjail.conf.























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
# mkjail config file

# Set your zpool name
ZPOOL="zroot"

# Set jail root filesystem path
JAILROOT="/jails"

# Sets you want extracted into new jail
# options include: base, doc, games (deprecated), kernel, lib32, ports, src
SETS="base doc lib32"

Added src/share/mkjail/create.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
set -e
set -u

: ${ARCH=$(uname -m)}
jflag=0
vflag=0

ip4int=$(route -4 get default | awk '/interface: / {print $2}')
ip6int=$(route -6 get default | awk '/interface: / {print $2}')
ip4guess=$(ifconfig ${ip4int} | awk '/inet / && !/127.0/ {print $2}' | head -n 1)
ip6guess=$(ifconfig ${ip6int} | awk '/inet6 / && !/(fe80| ::1)/ {print $2}' | head -n 1)

show_help() {
cat <<HELP
usage: mkjail create [-j JAILNAME] [-a ARCH] [-v VERSION] [-f FLAVOUR] [-s "SETS"]

        -a Architecture (i386, amd64, etc)
	-f Flavour (copy in files after creation)
	-h View this help
	-j Jail name
	-s Sets: "base doc games lib32"
	-v Version of jail (9.3-RELEASE, 10.1-RELEASE, etc)

mkjail.sh: 2018, feld@FreeBSD.org

HELP
}

exit_opts_req() {
    echo "Both -j and -v must be specified." >&2
    echo ""
    show_help
    exit 1
}


# option parsing has to happen below the show_help
# shift to skip the first argument or getopts loses its mind
shift
while getopts "a:f:hj:v:s:" opt; do
    case ${opt} in
        a)  ARCH=${OPTARG}
            ;;
        f)  fflag=1; FLAVOUR=${OPTARG}
            ;;
        h)
            show_help
            exit 0
            ;;
        j)  jflag=1; JAILNAME=${OPTARG}
            ;;
        s)  sflag=1; SETS=${OPTARG}
            ;;
        v)  vflag=1; VERSION=${OPTARG}
            ;;
    esac
done

shift $(($OPTIND - 1))

if [ -z $jflag ]
then
    exit_opts_req
fi

if [ -z $vflag ]
then
    exit_opts_req
fi

_build() {
# Make sure the release exists
if [ ! -d /var/db/mkjail/releases/${ARCH}/${VERSION} ]; then
    echo "Release ${VERSION} does not exist. Attempting to fetch..."
    ${SCRIPTPREFIX}/getrelease.sh ${VERSION}
fi

# Make sure target flavor exists
if [ x"${fflag}" = x1 ] && [ ! -d /var/db/mkjail/flavours/${FLAVOUR} ]; then
    echo "Error: flavour ${FLAVOUR} does not exist. Please create it first."
    exit 1
fi

# Create the ZFS filesystem
echo "Creating ${ZPOOL}/jails/${JAILNAME}..."
zfs create -p -o mountpoint=/jails ${ZPOOL}/jails
zfs create -p ${ZPOOL}/jails/${JAILNAME}
zfs set mkjail:version=${VERSION} ${ZPOOL}/jails/${JAILNAME}

# Extract the files
for set in $(echo ${SETS}); do
    echo "Extracting ${set} into ${JAILROOT}/${JAILNAME}..."
    tar -xf /var/db/mkjail/releases/${ARCH}/${VERSION}/$set.txz -C ${JAILROOT}/${JAILNAME} ;
done

if [ x"${fflag}" = x1 ] ; then
    # put in default configs:
    echo "Copying in our configs..."
    cp -a /var/db/mkjail/flavours/${FLAVOUR}/ ${JAILROOT}/${JAILNAME}
fi
}

_docs() {
# Give instructions
cat <<DOCS

Now put something like the following in /etc/jail.conf:

exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
path = ${JAILROOT}/\$name;
securelevel = 2;

${JAILNAME} {
    host.hostname = "${JAILNAME}";
    ip4.addr = ${ip4guess};
    ip6.addr = ${ip6guess};
    persist;
}

and then you can start the jail like so:

# service jail start ${JAILNAME}

DOCS
}

_build
_docs