rootfsinstall: new -I parameter to support installation from image (.img) instead of rootfs

This commit is contained in:
Silvan Calarco 2017-10-06 18:08:05 +02:00
parent 3aba21d977
commit 5339856ef0

View File

@ -20,7 +20,7 @@ function usage() {
echo "-rpi : make a RaspberryPi image with boot partition" echo "-rpi : make a RaspberryPi image with boot partition"
echo echo
echo "Options:" echo "Options:"
echo "-a archive : additional archive to unpack in rootfs root" echo "-a archive : additional archive to unpack in rootfs root (may be specified multiple times)"
echo "-cp command : command to run before chroot (may be specified multiple times)" echo "-cp command : command to run before chroot (may be specified multiple times)"
echo " Use @ROOT@ as reference to rootfs path and @BOOT@ as reference to bootfs path" echo " Use @ROOT@ as reference to rootfs path and @BOOT@ as reference to bootfs path"
echo "-c command : command to run through chroot in rootfs (may be specified multiple times)" echo "-c command : command to run through chroot in rootfs (may be specified multiple times)"
@ -29,13 +29,15 @@ function usage() {
echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot" echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot"
echo "-k2 kernel : extract and use specified second kernel file from ROOTFS/boot/ for boot" echo "-k2 kernel : extract and use specified second kernel file from ROOTFS/boot/ for boot"
echo "-i packages : install packages using package manager in chroot" echo "-i packages : install packages using package manager in chroot"
echo "-I : treat input as an image file"
echo "-l : force local installation only; don't perform installation from network" echo "-l : force local installation only; don't perform installation from network"
echo "-L : rootfs volume label (default: 'openmamba')" echo "-L : rootfs volume label (default: 'openmamba')"
echo "-p password : set given password for root user" echo "-p password : set given password for root user"
echo "-r mode : set given default video mode where applicable (e.g. -r 1920x1080-32@60)" echo "-r mode : set given default video mode where applicable (e.g. -r 1920x1080-32@60)"
echo "-y : assume yes to all questions (script mode)" echo "-y : assume yes to all questions (script mode)"
echo echo
echo "Example: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz" echo "Example 1: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz"
echo "Example 2: $0 /dev/sdb -rpi /tmp/openmamba-diskimg-raspberrypi-it-snapshot-20170910.arm.img.gz"
exit 1 exit 1
} }
@ -112,6 +114,7 @@ while [ "$1" ]; do
INSTALLPACKAGES="$2" INSTALLPACKAGES="$2"
shift shift
;; ;;
-I) IMAGEMODE=1 ;;
-l) LOCALONLY=1 ;; -l) LOCALONLY=1 ;;
-L) [ "$2" ] || { -L) [ "$2" ] || {
echo "Error: -L option requires a volume label as argument; aborting." echo "Error: -L option requires a volume label as argument; aborting."
@ -236,6 +239,7 @@ echo
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0 [ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
} }
if [ ! "$IMAGEMODE" ]; then
sudo parted -s ${DRIVE} mktable msdos sudo parted -s ${DRIVE} mktable msdos
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting." echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
@ -289,6 +293,15 @@ mke2fs -q -F -t $SYSTEMFSTYPE -j -L "$VOLUME_LABEL" $PARTITION2 || {
exit 1 exit 1
} }
else
# Image mode
gunzip -c ${ROOTFSARCHIVE} | dd of=${DRIVE} bs=32M
# Grow system partition to 100%
parted ${DRIVE} resizepart 2 100%
e2fsck -f ${PARTITION2}
resize2fs ${PARTITION2}
fi
[ "$BOOTFSTYPE" ] && BOOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX` [ "$BOOTFSTYPE" ] && BOOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
ROOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX` ROOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
@ -318,6 +331,7 @@ fi
exit 1 exit 1
} }
if [ ! "${IMAGEMODE}" ]; then
echo "Uncompressing $ROOTFSARCHIVE..." echo "Uncompressing $ROOTFSARCHIVE..."
echo -n "This can take a while, please wait..." echo -n "This can take a while, please wait..."
tar xf $ROOTFSARCHIVE || { tar xf $ROOTFSARCHIVE || {
@ -326,6 +340,8 @@ fi
exit 1 exit 1
} }
echo "DONE" echo "DONE"
fi
for b in dev dev/pts proc sys run; do for b in dev dev/pts proc sys run; do
mount -o bind /$b $ROOTMP/$b mount -o bind /$b $ROOTMP/$b
done done
@ -364,7 +380,7 @@ if [ "$SETHOSTNAME" ]; then
sed -i "s|\(127\.0\.0\.1\W*\)\(.*\)|\1 $SETHOSTNAME.localdomain $SETHOSTNAME localhost.localdomain localhost|" $ROOTMP/etc/hosts sed -i "s|\(127\.0\.0\.1\W*\)\(.*\)|\1 $SETHOSTNAME.localdomain $SETHOSTNAME localhost.localdomain localhost|" $ROOTMP/etc/hosts
fi fi
if [ "$INSTALLPACKAGES" -a "$LOCALONLY" != "1" ]; then if [ "$INSTALLPACKAGES" -a "$LOCALONLY" != "1" -a ! "${IMAGEMODE}" ]; then
mv $ROOTMP/etc/resolv.conf $ROOTMP/etc/resolv.conf.rootfsinstall mv $ROOTMP/etc/resolv.conf $ROOTMP/etc/resolv.conf.rootfsinstall
cp /etc/resolv.conf $ROOTMP/etc/resolv.conf cp /etc/resolv.conf $ROOTMP/etc/resolv.conf
chroot $ROOTMP bash -c /etc/profile.d/gpg-key-openmamba.sh chroot $ROOTMP bash -c /etc/profile.d/gpg-key-openmamba.sh
@ -381,7 +397,7 @@ if [ "$INSTALLPACKAGES" -a "$LOCALONLY" != "1" ]; then
mv $ROOTMP/etc/resolv.conf.rootfsinstall $ROOTMP/etc/resolv.conf mv $ROOTMP/etc/resolv.conf.rootfsinstall $ROOTMP/etc/resolv.conf
fi fi
if [ "$REMOVEPACKAGES" ]; then if [ "$REMOVEPACKAGES" -a ! "${IMAGEMODE}" ]; then
chroot $ROOTMP smart remove -y $REMOVEPACKAGES 2>/dev/null || true chroot $ROOTMP smart remove -y $REMOVEPACKAGES 2>/dev/null || true
fi fi
@ -391,6 +407,7 @@ KERNELDEST2=`echo $KERNELDEST2 | sed "s|@BOOT@|$BOOTMP|g"`
# #
# Prepare boot partition # Prepare boot partition
# #
if [ ! "${IMAGEMODE}" ]; then
if [ "$TARGETDEVICE" = "baytrail" ]; then if [ "$TARGETDEVICE" = "baytrail" ]; then
# create EFI Grub 64 bit image # create EFI Grub 64 bit image
mkdir -p $BOOTMP/EFI/BOOT/ mkdir -p $BOOTMP/EFI/BOOT/
@ -561,6 +578,8 @@ if [ "$USEKERNEL" ]; then
fi fi
fi fi
fi # ! IMAGEMODE
# #
# Final custom commands # Final custom commands
# #