rootfsinstall: new -I parameter to support installation from image (.img) instead of rootfs
This commit is contained in:
parent
3aba21d977
commit
5339856ef0
@ -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,59 +239,69 @@ echo
|
|||||||
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
|
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
sudo parted -s ${DRIVE} mktable msdos
|
if [ ! "$IMAGEMODE" ]; then
|
||||||
if [ "$?" != "0" ]; then
|
sudo parted -s ${DRIVE} mktable msdos
|
||||||
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
|
if [ "$?" != "0" ]; then
|
||||||
fi
|
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
|
||||||
sync
|
fi
|
||||||
|
sync
|
||||||
|
|
||||||
if [ "$BOOTFSTYPE" ]; then
|
if [ "$BOOTFSTYPE" ]; then
|
||||||
# FAT partition
|
# FAT partition
|
||||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE $BOOTFSSTART $BOOTFSSIZE
|
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE $BOOTFSSTART $BOOTFSSIZE
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
|
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
|
||||||
|
fi
|
||||||
|
sudo parted -s -- ${DRIVE} toggle 1 boot
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo "ERROR: parted exited with error $? while setting boot flag on ${DRIVE} boot partition; aborting."
|
||||||
|
fi
|
||||||
|
# rootfs partition
|
||||||
|
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE $BOOTFSSIZE -1
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# rootfs partition
|
||||||
|
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE 0 -1
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
sudo parted -s -- ${DRIVE} toggle 1 boot
|
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$BOOTFSTYPE" ]; then
|
||||||
echo "ERROR: parted exited with error $? while setting boot flag on ${DRIVE} boot partition; aborting."
|
echo "Formatting $PARTITION1 ($BOOTFSTYPE) ..."
|
||||||
fi
|
case "$BOOTFSTYPE" in
|
||||||
# rootfs partition
|
vfat|fat32) mkfs.vfat -s 1 -F 32 -n "boot" $PARTITION1 || {
|
||||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE $BOOTFSSIZE -1
|
echo "ERROR: unable to format $PARTITION1; aborting."
|
||||||
if [ "$?" != "0" ]; then
|
exit 1
|
||||||
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
} ;;
|
||||||
|
fat16) mkfs.vfat -s 1 -F 16 -n "boot" $PARTITION1 || {
|
||||||
|
echo "ERROR: unable to format $PARTITION1; aborting."
|
||||||
|
exit 1
|
||||||
|
} ;;
|
||||||
|
ext*) mke2fs -q -t $BOOTFSTYPE -j -L "boot" $PARTITION1 || {
|
||||||
|
echo "ERROR: unable to format $PARTITION1; aborting."
|
||||||
|
exit 1
|
||||||
|
} ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Formatting $PARTITION2 ($SYSTEMFSTYPE)..."
|
||||||
|
mke2fs -q -F -t $SYSTEMFSTYPE -j -L "$VOLUME_LABEL" $PARTITION2 || {
|
||||||
|
echo "ERROR: unable to format $PARTITION2; aborting."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
# rootfs partition
|
# Image mode
|
||||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE 0 -1
|
gunzip -c ${ROOTFSARCHIVE} | dd of=${DRIVE} bs=32M
|
||||||
if [ "$?" != "0" ]; then
|
# Grow system partition to 100%
|
||||||
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
parted ${DRIVE} resizepart 2 100%
|
||||||
fi
|
e2fsck -f ${PARTITION2}
|
||||||
|
resize2fs ${PARTITION2}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$BOOTFSTYPE" ]; then
|
|
||||||
echo "Formatting $PARTITION1 ($BOOTFSTYPE) ..."
|
|
||||||
case "$BOOTFSTYPE" in
|
|
||||||
vfat|fat32) mkfs.vfat -s 1 -F 32 -n "boot" $PARTITION1 || {
|
|
||||||
echo "ERROR: unable to format $PARTITION1; aborting."
|
|
||||||
exit 1
|
|
||||||
} ;;
|
|
||||||
fat16) mkfs.vfat -s 1 -F 16 -n "boot" $PARTITION1 || {
|
|
||||||
echo "ERROR: unable to format $PARTITION1; aborting."
|
|
||||||
exit 1
|
|
||||||
} ;;
|
|
||||||
ext*) mke2fs -q -t $BOOTFSTYPE -j -L "boot" $PARTITION1 || {
|
|
||||||
echo "ERROR: unable to format $PARTITION1; aborting."
|
|
||||||
exit 1
|
|
||||||
} ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Formatting $PARTITION2 ($SYSTEMFSTYPE)..."
|
|
||||||
mke2fs -q -F -t $SYSTEMFSTYPE -j -L "$VOLUME_LABEL" $PARTITION2 || {
|
|
||||||
echo "ERROR: unable to format $PARTITION2; aborting."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
[ "$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,14 +331,17 @@ fi
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Uncompressing $ROOTFSARCHIVE..."
|
if [ ! "${IMAGEMODE}" ]; then
|
||||||
echo -n "This can take a while, please wait..."
|
echo "Uncompressing $ROOTFSARCHIVE..."
|
||||||
tar xf $ROOTFSARCHIVE || {
|
echo -n "This can take a while, please wait..."
|
||||||
echo
|
tar xf $ROOTFSARCHIVE || {
|
||||||
echo "ERROR: unable to uncompress rootfs archive; aborting."
|
echo
|
||||||
exit 1
|
echo "ERROR: unable to uncompress rootfs archive; aborting."
|
||||||
}
|
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
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user