11#! /bin/bash
2-
2+ set -x
33socket=" /tmp/virtiofs.sock"
44
55rootfs=" "
66kernel=" $rootfs /boot/vmlinuz"
77initram=" $rootfs /boot/initrd.img"
88cmdline=" rw console=ttyS0 reboot=k panic=1 root=vroot rootfstype=virtiofs rootdelay=30"
9+ overlayfs=" /tmp/merged"
10+ flist=" "
911
1012user=" user"
1113pass=" pass"
1214name=" cloud"
1315
1416fspid=0
17+ flpid=0
1518
1619fail () {
1720 echo " $1 " >&2
@@ -31,19 +34,30 @@ usage() {
3134}
3235
3336handle_options () {
37+
3438 while [[ " $# " -gt 0 ]]; do
3539 case $1 in
3640 --rootfs)
3741 rootfs=" $2 "
3842 kernel=" $rootfs /boot/vmlinuz"
3943 initram=" $rootfs /boot/initrd.img"
40-
41- if [[ -z " $rootfs " ]]; then
42- echo " Error: -r (rootfs) flag is required."
43- usage
44+ shift
45+ ;;
46+ --flist)
47+ flist=" $2 "
48+ shift
49+ ;;
50+ --cidata)
51+ cidata=" $2 "
52+ shift
53+ ;;
54+ --init)
55+ if [ ! -z " $2 " ]; then
56+ cmdline=" $cmdline init=$2 "
4457 fi
4558 shift
4659 ;;
60+
4761 --user)
4862 user=" $2 "
4963 shift
@@ -56,12 +70,7 @@ handle_options() {
5670 name=" $2 "
5771 shift
5872 ;;
59- --init)
60- if [ ! -z " $2 " ]; then
61- cmdline=" $cmdline init=$2 "
62- fi
63- shift
64- ;;
73+
6574 * )
6675 usage
6776 ;;
@@ -72,6 +81,8 @@ handle_options() {
7281}
7382
7483validate () {
84+ # if no rootfs or metadata, fail
85+ # check other binaries
7586 which virtiofsd & > /dev/null || fail " virtiofsd not found in PATH"
7687 which cloud-hypervisor & > /dev/null || fail " cloud-hypervior not found in path"
7788
@@ -112,14 +123,16 @@ EOF
112123start_fs () {
113124 sudo virtiofsd \
114125 --socket-path=" ${socket} " \
115- --shared-dir=" ${rootfs } " \
126+ --shared-dir=" ${overlayfs } " \
116127 --cache=never \
117128 &
118129
119130 fspid=$!
120131}
121132
122133cleanup () {
134+ sudo umount " $overlayfs "
135+ kill " $flpid " & > /dev/null
123136 kill " $fspid " & > /dev/null || true
124137}
125138trap cleanup EXIT
@@ -137,8 +150,53 @@ run_hypervisor() {
137150 --console off
138151}
139152
153+ create_rwlayer () {
154+ sudo mkdir -p /tmp/upper /tmp/workdir " $overlayfs "
155+
156+ sudo mount \
157+ -t overlay \
158+ -o lowerdir=" $rootfs " ,upperdir=/tmp/upper,workdir=/tmp/workdir \
159+ none \
160+ " $overlayfs "
161+ }
162+
163+ mount_flist () {
164+ wget " $flist " -O /tmp/flist.flist
165+
166+ rootfs=/home/omar/tmp
167+ mkdir -p " $rootfs "
168+ rfs1 --meta /tmp/flist.flist " $rootfs " &
169+
170+ flpid=$!
171+ }
172+
173+ # decompress_kernel() {
174+ # wget -O /tmp/extract-vmlinux https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux
175+ # chmod +x /tmp/extract-vmlinux
176+
177+ # }
178+
179+ prepare_cloud_image () {
180+ # chroot and install ci
181+ # symlink to host vmlinuz/initrd
182+ # load virtiofs and update ramfs
183+ }
184+
185+ boot () {
186+ start_fs
187+ run_hypervisor
188+ }
189+
140190handle_options " $@ "
191+
141192validate
193+
194+ # if no cidata
142195create_cidata
143- start_fs
144- run_hypervisor
196+
197+ # if is metadata
198+ mount_flist
199+
200+ create_rwlayer
201+
202+ boot
0 commit comments