2017-12-09 21:51:48 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-02-14 13:47:54 +01:00
|
|
|
set -u -e
|
2017-12-09 21:51:48 +01:00
|
|
|
|
|
|
|
FILE=$1
|
|
|
|
MOUNTED=0
|
|
|
|
LOOPATTACHED=0
|
|
|
|
|
|
|
|
function do_cleanup() {
|
|
|
|
[ $MOUNTED -ne 0 ] && umount /tmp/mnt.$$
|
|
|
|
[ $LOOPATTACHED -ne 0 ] && losetup -d ${LODEV}
|
|
|
|
rmdir /tmp/mnt.$$
|
|
|
|
}
|
|
|
|
|
|
|
|
trap do_cleanup ERR INT
|
|
|
|
|
|
|
|
cd `dirname $0`
|
|
|
|
|
2018-02-14 13:47:54 +01:00
|
|
|
if [ -e "$FILE" ]; then
|
|
|
|
echo "Error, $FILE exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-12-09 21:51:48 +01:00
|
|
|
truncate -s 1G $FILE
|
|
|
|
|
|
|
|
parted --script $FILE \
|
|
|
|
"mklabel msdos" \
|
|
|
|
"mkpart primary fat32 1M 256M" \
|
|
|
|
"mkpart primary btrfs 256M 100%" \
|
|
|
|
"set 1 boot on"
|
|
|
|
|
|
|
|
LODEV=$(losetup -f)
|
|
|
|
losetup -P ${LODEV} ${FILE}
|
|
|
|
LOOPATTACHED=1
|
|
|
|
|
|
|
|
mkfs.vfat ${LODEV}p1
|
|
|
|
mkfs.btrfs -f ${LODEV}p2
|
|
|
|
|
|
|
|
mkdir /tmp/mnt.$$
|
|
|
|
mount -t vfat ${LODEV}p1 /tmp/mnt.$$
|
|
|
|
MOUNTED=1
|
|
|
|
|
|
|
|
syslinux --install ${LODEV}p1
|
|
|
|
cp syslinux.cfg /tmp/mnt.$$/syslinux.cfg
|
2018-02-14 13:07:23 +01:00
|
|
|
cp -r VERSIONDIR /tmp/mnt.$$/
|
2017-12-09 21:51:48 +01:00
|
|
|
|
|
|
|
umount /tmp/mnt.$$
|
|
|
|
MOUNTED=0
|
|
|
|
|
|
|
|
mount -t btrfs ${LODEV}p2 /tmp/mnt.$$
|
|
|
|
MOUNTED=1
|
|
|
|
mkdir /tmp/mnt.$$/etc /tmp/mnt.$$/etc_work
|
|
|
|
mkdir /tmp/mnt.$$/var_lib /tmp/mnt.$$/var_lib_work
|
2018-04-19 07:23:15 +02:00
|
|
|
mkdir -p /tmp/mnt.$$/usr/root /tmp/mnt.$$/usr_work
|
2018-09-15 20:25:27 +02:00
|
|
|
chmod 700 /tmp/mnt.$$/usr/root /tmp/mnt.$$/usr_work
|
2018-04-19 07:23:15 +02:00
|
|
|
chown 0:0 /tmp/mnt.$$/usr/root
|
2017-12-09 21:51:48 +01:00
|
|
|
umount /tmp/mnt.$$
|
|
|
|
MOUNTED=0
|
|
|
|
|
|
|
|
losetup -d ${LODEV}
|
|
|
|
LOOPATTACHED=0
|
|
|
|
|
|
|
|
dd if=mbr.bin of=$FILE conv=notrunc
|
|
|
|
|
|
|
|
rmdir /tmp/mnt.$$
|