add image syncing capabilities and only touch filesystem if something is
wrong with it
This commit is contained in:
parent
6f5d3309df
commit
61afe74f0c
3 changed files with 49 additions and 17 deletions
|
|
@ -4,7 +4,8 @@ RUN apt-get update \
|
|||
&& apt-get -y install \
|
||||
initramfs-tools \
|
||||
linux-image-amd64 \
|
||||
aria2
|
||||
aria2 \
|
||||
xxd
|
||||
|
||||
COPY imagesync.sh /etc/initramfs-tools/scripts/local-premount/
|
||||
|
||||
|
|
|
|||
61
imagesync.sh
61
imagesync.sh
|
|
@ -9,6 +9,8 @@ prereqs)
|
|||
copy_exec /usr/bin/aria2c
|
||||
copy_exec /sbin/sfdisk
|
||||
copy_exec /sbin/mke2fs
|
||||
copy_exec /sbin/e2fsck
|
||||
copy_exec /usr/bin/xxd
|
||||
copy_file cert /etc/ssl/certs/ca-certificates.crt
|
||||
exit 0
|
||||
;;
|
||||
|
|
@ -38,20 +40,37 @@ size_part_1=$((3072 * 1024 * 1024 / 512))
|
|||
# PARTITIONING OF DISK
|
||||
##
|
||||
|
||||
print_waiting "Partitioning disk"
|
||||
sfdisk -q /dev/sda << PARTTABLE
|
||||
label: dos
|
||||
parttable="label: dos
|
||||
label-id: 0xdeadbeef
|
||||
device: /dev/sda
|
||||
unit: sectors
|
||||
|
||||
/dev/sda1 : start= 2048, size= $size_part_1, type=83
|
||||
PARTTABLE
|
||||
print_done
|
||||
/dev/sda1 : start= 2048, size= $size_part_1, type=83"
|
||||
|
||||
print_waiting "Creating Filesystem"
|
||||
mke2fs -q -F -t ext4 ${disk}1
|
||||
print_done
|
||||
readtable="$(sfdisk -d $disk)" # wtf? but it is needed
|
||||
|
||||
print_waiting "Checking partition tables"
|
||||
if [ "$parttable" != "$readtable" ];then
|
||||
print_done
|
||||
print_waiting "Partition tables do not match; partitioning disk"
|
||||
sfdisk -q /dev/sda << PARTTABLE
|
||||
$parttable
|
||||
PARTTABLE
|
||||
print_done
|
||||
else
|
||||
print_done
|
||||
fi
|
||||
|
||||
print_waiting "Checking root filesystem"
|
||||
e2fsck /dev/sda1 &>/dev/null
|
||||
if [ $? != 0 ];then
|
||||
print_done
|
||||
print_waiting "Creating root filesystem"
|
||||
mke2fs -q -F -t ext4 ${disk}1
|
||||
print_done
|
||||
else
|
||||
print_done
|
||||
fi
|
||||
|
||||
##
|
||||
# TEMPORARY NETWORK CONFIG (only for qemu)
|
||||
|
|
@ -77,12 +96,26 @@ print_done
|
|||
##
|
||||
|
||||
print_waiting "Downloading root filesystem image"
|
||||
# (DHT error seems normal, because it is aria2c’s first run)
|
||||
# do not complain about missing dht database
|
||||
echo '
|
||||
00000000: a1a2 0200 0000 0003 0000 0000 5a81 9b23 ............Z..#
|
||||
00000010: 0000 0000 0000 0000 0c26 e387 dc94 df37 .........&.....7
|
||||
00000020: 41be 919e 5166 4676 60e0 7435 0000 0000 A...QfFv`.t5....
|
||||
00000030: 0000 0000 0000 0000 ........
|
||||
'|xxd -r > dht.dat
|
||||
|
||||
# --allow-overwrite: do not rename the torrent file
|
||||
# --check-integrity: verify downloaded file and do not complain about missing controll file
|
||||
# --seed-time=0: do not wait until ratio 1, we seed when we’re booted
|
||||
# --quiet: no console output
|
||||
aria2c --check-integrity --seed-time=0 --quiet=true 'http://10.2.2.1:8081/image.torrent'
|
||||
# --summary-interval=0: do not show summary while downloading
|
||||
# --console-log-level=error: Only show errors
|
||||
# --dht-file-path=dht.dat: use generated dht data file and do not complain
|
||||
aria2c --allow-overwrite --check-integrity --seed-time=0 --summary-interval=0 --console-log-level=error --dht-file-path=dht.dat 'http://10.2.2.1:8081/rootfs.torrent'
|
||||
rm dht.dat
|
||||
print_done
|
||||
|
||||
print_waiting "Extracting root filesystem image"
|
||||
tar xzf rootfs.tar.gz
|
||||
print_done
|
||||
|
||||
##
|
||||
|
|
@ -93,7 +126,3 @@ print_waiting "Unmounting temporary root filesystem"
|
|||
cd /
|
||||
umount /tmp_root
|
||||
print_done
|
||||
|
||||
print_waiting "Waiting for implementation of more features"
|
||||
|
||||
while sleep 3600;do sleep 3600;done
|
||||
|
|
|
|||
2
qemu.sh
2
qemu.sh
|
|
@ -19,6 +19,8 @@ qemu-system-x86_64 \
|
|||
-initrd initrd.gz \
|
||||
-drive format=raw,file=pladde.img \
|
||||
-append "root=/dev/sda1" \
|
||||
-curses \
|
||||
-enable-kvm \
|
||||
-m 1G \
|
||||
-net nic \
|
||||
-net tap,ifname=$ifname_tap,script=no,downscript=no
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue