mkimage: guess platform automatically, add new options to set fstype and boot fssize.
This commit is contained in:
parent
531d38dc73
commit
20f2340387
|
@ -50,30 +50,38 @@ die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $PROGNAME [-b fstype] [-o filename] [-r fstype] [-hV] <rootfs-tarball> [size]"
|
cat <<_EOF
|
||||||
echo
|
Usage: $PROGNAME [options] <rootfs-tarball>
|
||||||
echo " The <rootfs-tarball> argument expects a file generated by void-mkrootfs."
|
|
||||||
echo " The <size> argument expects a number (GB). If <size> is not set, defaults to 2."
|
The <rootfs-tarball> argument expects a tarball generated by void-mkrootfs.
|
||||||
echo
|
The platform is guessed automatically by its name.
|
||||||
echo "OPTIONS"
|
|
||||||
echo " -b <fstype> Set /boot <fstype> (defaults to FAT, 32MB)"
|
Accepted sizes suffixes: K, M, G, T, E.
|
||||||
echo " -o <filename> Set output <filename>."
|
|
||||||
echo " -r <fstype> Set / <fstype> (defaults to ext4, 32MB - <size>)"
|
OPTIONS
|
||||||
echo " -p <platform> Set platform type: cubieboard2, rpi, odroid-u2"
|
-b <fstype> Set /boot filesystem type (defaults to FAT)
|
||||||
echo
|
-B <bsize> Set /boot filesystem size (defaults to 64MB)
|
||||||
echo " Resulting image will have 2 partitions, /boot and / of total <size>."
|
-r <fstype> Set / filesystem type (defaults to EXT4)
|
||||||
|
-s <totalsize> Set total image size (defaults to 2GB)
|
||||||
|
-o <output> Set image filename (guessed automatically)
|
||||||
|
-h Show this help
|
||||||
|
-V Show version
|
||||||
|
|
||||||
|
Resulting image will have 2 partitions, /boot and /.
|
||||||
|
_EOF
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# main()
|
# main()
|
||||||
#
|
#
|
||||||
while getopts "b:o:r:p:hV" opt; do
|
while getopts "b:B:o:r:s:hV" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
b) BOOT_FSTYPE="$OPTARG";;
|
b) BOOT_FSTYPE="$OPTARG";;
|
||||||
|
B) BOOT_FSSIZE="$OPTARG";;
|
||||||
o) FILENAME="$OPTARG";;
|
o) FILENAME="$OPTARG";;
|
||||||
r) ROOT_FSTYPE="$OPTARG";;
|
r) ROOT_FSTYPE="$OPTARG";;
|
||||||
p) PLATFORM="$OPTARG";;
|
s) IMGSIZE="$OPTARG";;
|
||||||
V) echo "$PROGNAME @@MKLIVE_VERSION@@"; exit 0;;
|
V) echo "$PROGNAME @@MKLIVE_VERSION@@"; exit 0;;
|
||||||
h) usage;;
|
h) usage;;
|
||||||
esac
|
esac
|
||||||
|
@ -87,6 +95,9 @@ elif [ ! -r "$ROOTFS_TARBALL" ]; then
|
||||||
die "Cannot read rootfs tarball: $ROOTFS_TARBALL"
|
die "Cannot read rootfs tarball: $ROOTFS_TARBALL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
PLATFORM="${ROOTFS_TARBALL#void-}"
|
||||||
|
PLATFORM="${PLATFORM%-rootfs*}"
|
||||||
|
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
die "need root perms to continue, exiting."
|
die "need root perms to continue, exiting."
|
||||||
fi
|
fi
|
||||||
|
@ -98,19 +109,18 @@ else
|
||||||
IMGSIZE="${2}G"
|
IMGSIZE="${2}G"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$BOOT_FSTYPE" ]; then
|
: ${BOOT_FSTYPE:=vfat}
|
||||||
BOOT_FSTYPE="vfat"
|
: ${BOOT_FSSIZE:=64M}
|
||||||
fi
|
: ${ROOT_FSTYPE:=ext4}
|
||||||
if [ -z "$ROOT_FSTYPE" ]; then
|
|
||||||
ROOT_FSTYPE="ext4"
|
|
||||||
fi
|
|
||||||
if [ -z "$FILENAME" ]; then
|
if [ -z "$FILENAME" ]; then
|
||||||
FILENAME="void-image-$(date +%Y%m%d).img"
|
FILENAME="void-${PLATFORM}-$(date +%Y%m%d).img"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# double check PLATFORM is supported...
|
||||||
case "$PLATFORM" in
|
case "$PLATFORM" in
|
||||||
cubieboard2|odroid-u2|rpi);;
|
cubieboard2|odroid-u2|rpi);;
|
||||||
*) die "Unknown platform or platform unset, set it with -p!"
|
*) die "The $PLATFORM is not supported, exiting..."
|
||||||
esac
|
esac
|
||||||
|
|
||||||
for f in parted partx losetup mount mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}; do
|
for f in parted partx losetup mount mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}; do
|
||||||
|
@ -135,8 +145,8 @@ if [ "$BOOT_FSTYPE" = "vfat" ]; then
|
||||||
_btype="fat32"
|
_btype="fat32"
|
||||||
_args="-I"
|
_args="-I"
|
||||||
fi
|
fi
|
||||||
parted $FILENAME mkpart primary ${_btype} 4096s 64M
|
parted $FILENAME mkpart primary ${_btype} 4096s ${BOOT_FSSIZE}
|
||||||
parted $FILENAME mkpart primary ext2 64M 100%
|
parted $FILENAME mkpart primary ext2 ${BOOT_FSSIZE} 100%
|
||||||
parted $FILENAME toggle 1 boot
|
parted $FILENAME toggle 1 boot
|
||||||
LOOPDEV=$(losetup --show --find $FILENAME)
|
LOOPDEV=$(losetup --show --find $FILENAME)
|
||||||
partx -a $LOOPDEV
|
partx -a $LOOPDEV
|
||||||
|
|
Loading…
Reference in New Issue