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
|
||||
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 " 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)"
|
||||
@ -29,13 +29,15 @@ function usage() {
|
||||
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 "-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 : rootfs volume label (default: 'openmamba')"
|
||||
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 "-y : assume yes to all questions (script mode)"
|
||||
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
|
||||
}
|
||||
|
||||
@ -112,6 +114,7 @@ while [ "$1" ]; do
|
||||
INSTALLPACKAGES="$2"
|
||||
shift
|
||||
;;
|
||||
-I) IMAGEMODE=1 ;;
|
||||
-l) LOCALONLY=1 ;;
|
||||
-L) [ "$2" ] || {
|
||||
echo "Error: -L option requires a volume label as argument; aborting."
|
||||
@ -236,59 +239,69 @@ echo
|
||||
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
|
||||
}
|
||||
|
||||
sudo parted -s ${DRIVE} mktable msdos
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
|
||||
fi
|
||||
sync
|
||||
if [ ! "$IMAGEMODE" ]; then
|
||||
sudo parted -s ${DRIVE} mktable msdos
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
|
||||
fi
|
||||
sync
|
||||
|
||||
if [ "$BOOTFSTYPE" ]; then
|
||||
# FAT partition
|
||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE $BOOTFSSTART $BOOTFSSIZE
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
|
||||
if [ "$BOOTFSTYPE" ]; then
|
||||
# FAT partition
|
||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE $BOOTFSSTART $BOOTFSSIZE
|
||||
if [ "$?" != "0" ]; then
|
||||
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
|
||||
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."
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
# 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
|
||||
|
||||
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`
|
||||
ROOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
|
||||
|
||||
@ -318,14 +331,17 @@ fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "Uncompressing $ROOTFSARCHIVE..."
|
||||
echo -n "This can take a while, please wait..."
|
||||
tar xf $ROOTFSARCHIVE || {
|
||||
echo
|
||||
echo "ERROR: unable to uncompress rootfs archive; aborting."
|
||||
exit 1
|
||||
}
|
||||
echo "DONE"
|
||||
if [ ! "${IMAGEMODE}" ]; then
|
||||
echo "Uncompressing $ROOTFSARCHIVE..."
|
||||
echo -n "This can take a while, please wait..."
|
||||
tar xf $ROOTFSARCHIVE || {
|
||||
echo
|
||||
echo "ERROR: unable to uncompress rootfs archive; aborting."
|
||||
exit 1
|
||||
}
|
||||
echo "DONE"
|
||||
fi
|
||||
|
||||
for b in dev dev/pts proc sys run; do
|
||||
mount -o bind /$b $ROOTMP/$b
|
||||
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
|
||||
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
|
||||
cp /etc/resolv.conf $ROOTMP/etc/resolv.conf
|
||||
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
|
||||
fi
|
||||
|
||||
if [ "$REMOVEPACKAGES" ]; then
|
||||
if [ "$REMOVEPACKAGES" -a ! "${IMAGEMODE}" ]; then
|
||||
chroot $ROOTMP smart remove -y $REMOVEPACKAGES 2>/dev/null || true
|
||||
fi
|
||||
|
||||
@ -391,6 +407,7 @@ KERNELDEST2=`echo $KERNELDEST2 | sed "s|@BOOT@|$BOOTMP|g"`
|
||||
#
|
||||
# Prepare boot partition
|
||||
#
|
||||
if [ ! "${IMAGEMODE}" ]; then
|
||||
if [ "$TARGETDEVICE" = "baytrail" ]; then
|
||||
# create EFI Grub 64 bit image
|
||||
mkdir -p $BOOTMP/EFI/BOOT/
|
||||
@ -561,6 +578,8 @@ if [ "$USEKERNEL" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
fi # ! IMAGEMODE
|
||||
|
||||
#
|
||||
# Final custom commands
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user