3 # install.sh [device_name] [rootfs_name] [video_mode] [vga_mode]
6 PATH=/sbin:/bin:/usr/sbin:/usr/bin
8 # Get a list of hard drives
10 live_dev_name=`cat /proc/mounts | grep ${1%/} | awk '{print $1}'`
11 live_dev_name=${live_dev_name#\/dev/}
12 # Only strip the digit identifier if the device is not an mmc
13 case $live_dev_name in
19 live_dev_name=${live_dev_name%%[0-9]*}
23 echo "Searching for hard drives ..."
25 # Some eMMC devices have special sub devices such as mmcblk0boot0 etc
26 # we're currently only interested in the root device so pick them wisely
27 devices=`ls /sys/block/ | grep -v mmcblk` || true
28 mmc_devices=`ls /sys/block/ | grep "mmcblk[0-9]\{1,\}$"` || true
29 devices="$devices $mmc_devices"
31 for device in $devices; do
43 # skip the device LiveOS is on
44 # Add valid hard drive name to the list
47 # skip the device we are running from
50 hdnamelist="$hdnamelist $device"
58 for hdname in $hdnamelist; do
59 # Display found hard drives and their basic info
60 echo "-------------------------------"
62 if [ -r /sys/block/$hdname/device/vendor ]; then
64 cat /sys/block/$hdname/device/vendor
66 if [ -r /sys/block/$hdname/device/model ]; then
68 cat /sys/block/$hdname/device/model
70 if [ -r /sys/block/$hdname/device/uevent ]; then
72 cat /sys/block/$hdname/device/uevent
77 # use the first one found
78 for hdname in $hdnamelist; do
79 TARGET_DEVICE_NAME=$hdname
83 if [ -n "$TARGET_DEVICE_NAME" ]; then
84 echo "Installing image on /dev/$TARGET_DEVICE_NAME ..."
86 echo "No hard drive found. Installation aborted."
90 device=/dev/$TARGET_DEVICE_NAME
93 # Unmount anything the automounter had mounted
96 for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts | grep $TARGET_DEVICE_NAME`; do
100 if [ ! -b /dev/loop0 ] ; then
101 mknod /dev/loop0 b 7 0
105 if [ ! -L /etc/mtab ] && [ -e /proc/mounts ]; then
106 ln -sf /proc/mounts /etc/mtab
109 disk_size=$(parted ${device} unit mb print | grep '^Disk .*: .*MB' | cut -d" " -f 3 | sed -e "s/MB//")
111 grub_version=$(grub-install -V|sed 's/.* \([0-9]\).*/\1/')
113 if [ $grub_version -eq 0 ] ; then
116 # For GRUB 2 we need separate parition to store stage2 grub image
117 # 2Mb value is chosen to align partition for best performance.
124 scratch_vol_size=8000
126 data_size=$((disk_size-bios_boot_size-boot_size-rootfs_size))
127 boot_start=$((bios_boot_size))
128 rootfs_start=$((bios_boot_size+boot_size))
129 rootfs_end=$((rootfs_start+rootfs_size))
130 data_start=$((rootfs_end))
132 # MMC devices are special in a couple of ways
133 # 1) they use a partition prefix character 'p'
134 # 2) they are detected asynchronously (need rootwait)
137 if [ ! "${device#/dev/mmcblk}" = "${device}" ] || \
138 [ ! "${device#/dev/nvme}" = "${device}" ]; then
143 # USB devices also require rootwait
144 if [ -n `readlink /dev/disk/by-id/usb* | grep $TARGET_DEVICE_NAME` ]; then
148 if [ $grub_version -eq 0 ] ; then
150 bootfs=${device}${part_prefix}1
151 rootfs=${device}${part_prefix}2
152 data=${device}${part_prefix}3
154 bios_boot=${device}${part_prefix}1
155 bootfs=${device}${part_prefix}2
156 rootfs=${device}${part_prefix}3
157 data=${device}${part_prefix}4
160 echo "*********************************************"
161 [ $grub_version -ne 0 ] && echo "BIOS boot partition size: $bios_boot_size MB ($bios_boot)"
162 echo "Boot partition size: $boot_size MB ($bootfs)"
163 echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
164 echo "Data partition size: $data_size MB ($data)"
165 echo "*********************************************"
166 echo "Deleting partition table on ${device} ..."
167 dd if=/dev/zero of=${device} bs=512 count=35
169 echo "Creating new partition table on ${device} ..."
170 if [ $grub_version -eq 0 ] ; then
171 parted ${device} mktable msdos
172 echo "Creating boot partition on $bootfs"
173 parted ${device} mkpart primary ext3 0% $boot_size
175 parted ${device} mktable gpt
176 echo "Creating BIOS boot partition on $bios_boot"
177 parted ${device} mkpart bios_boot 0% $bios_boot_size
178 parted ${device} set 1 bios_grub on
179 echo "Creating boot partition on $bootfs"
180 parted ${device} mkpart boot ext3 $boot_start $boot_size
183 echo "Creating rootfs partition on $rootfs"
184 [ $grub_version -eq 0 ] && pname='primary' || pname='root'
185 parted ${device} -s mkpart $pname ext4 $rootfs_start $rootfs_end
187 echo "Creating data partition on $data"
188 [ $grub_version -eq 0 ] && pname='primary' || pname='data'
189 parted ${device} -s mkpart $pname $data_start 100%
190 parted ${device} -s set 4 lvm on
192 parted ${device} print
194 echo "Waiting for device nodes..."
196 while [ $C -ne 3 ] && [ ! -e $bootfs -o ! -e $rootfs -o ! -e $data ]; do
201 echo "Formatting $bootfs to ext3..."
204 echo "Formatting $rootfs to ext4..."
207 echo "Create LVM for $data..."
210 # Disable udev scan in lvm.conf
211 sed -i 's/\(md_component_detection =\).*/\1 0/' /etc/lvm/lvm.conf
213 pvcreate -y -ff $data
214 vgcreate -y -ff $vg_name $data
218 lvcreate -y -n log-lv --size $log_vol_size $vg_name
219 lvcreate -y -n scratch-lv --size $scratch_vol_size $vg_name
221 mkfs.ext4 -F /dev/$vg_name/log-lv
222 mkfs.ext4 -F /dev/$vg_name/scratch-lv
229 if [ ! -f /run/media/$1/$2 ]; then
230 mkdir -p /run/media/$1
231 mount /dev/$1 /run/media/$1
234 # Handling of the target root partition
235 mount $rootfs /tgt_root
236 mount /dev/$vg_name/log-lv /tgt_log
237 mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
238 echo "Copying rootfs files..."
239 cp -a /src_root/* /tgt_root
240 if [ -d /tgt_root/etc/ ] ; then
241 if [ $grub_version -ne 0 ] ; then
242 boot_uuid=$(blkid -o value -s UUID ${bootfs})
243 bootdev="UUID=$boot_uuid"
247 sed -i '/vfat/d' /tgt_root/etc/fstab
248 echo "$bootdev /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab
249 echo "/dev/$vg_name/log-lv /var/log ext4 defaults 1 2" >> /tgt_root/etc/fstab
250 echo "/dev/$vg_name/scratch-lv /scratch ext4 defaults 1 2" >> /tgt_root/etc/fstab
252 # We dont want udev to mount our root device while we're booting...
253 if [ -d /tgt_root/etc/udev/ ] ; then
254 echo "${device}" >> /tgt_root/etc/udev/mount.blacklist
258 INSTALL_UUID=`uuidgen`
259 cat << _EOF > /tgt_root/etc/platform/platform.conf
261 subfunction=controller,worker
262 system_type=All-in-one
263 security_profile=standard
264 management_interface=lo
266 INSTALL_UUID=${INSTALL_UUID}
269 # Create first_boot flag
270 touch /tgt_root/etc/platform/.first_boot
272 # The grub.cfg is created by installer, so the postinsts script is not needed.
273 rm -f /tgt_root/etc/rpm-postinsts/*-grub
275 # /var/log will be mounted to the log-lv
276 # so move the all files to log-lv
277 cp -rf /tgt_root/var/log/* /tgt_log
278 rm -rf /tgt_root/var/log
280 # Fake as anaconda to add info needed by stx 3.0
281 cat << _EOF > /tgt_root/etc/rpm-postinsts/999-anaconda
282 # anaconda - postinst
285 mkdir -p /var/log/anaconda/
286 echo "Display mode = t" > /var/log/anaconda/anaconda.log
288 chmod 0755 /tgt_root/etc/rpm-postinsts/999-anaconda
293 echo "Looking for kernels to use as boot target.."
294 # Find kernel to boot to
295 # Give user options if multiple are found
296 kernels="$(find /run/media/$1/ -type f \
297 -name bzImage* -o -name zImage* \
298 -o -name vmlinux* -o -name vmlinuz* \
301 if [ -n "$(echo $kernels)" ]; then
302 # only one kernel entry if no space
303 if [ -z "$(echo $kernels | grep " ")" ]; then
305 echo "$kernel will be used as the boot target"
307 echo "Which kernel do we want to boot by default? The following kernels were found:"
313 echo "No kernels found, exiting..."
317 # Handling of the target boot partition
319 echo "Preparing boot partition..."
321 if [ -f /etc/grub.d/00_header -a $grub_version -ne 0 ] ; then
322 echo "Preparing custom grub2 menu..."
323 root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs})
324 boot_uuid=$(blkid -o value -s UUID ${bootfs})
325 GRUBCFG="/boot/grub/grub.cfg"
326 mkdir -p $(dirname $GRUBCFG)
330 menuentry "Yocto Linux with StarlingX @STX_ID@" {
331 search --no-floppy --fs-uuid $boot_uuid --set root
332 linux /$kernel root=$rootfs $rootwait rw console=tty0 console=ttyS0,115200 $5 $3 $4
337 grub-install ${device}
339 if [ $grub_version -eq 0 ] ; then
340 echo "(hd0) ${device}" > /boot/grub/device.map
341 echo "Preparing custom grub menu..."
342 echo "default 0" > /boot/grub/menu.lst
343 echo "timeout 30" >> /boot/grub/menu.lst
344 echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst
345 echo "root (hd0,0)" >> /boot/grub/menu.lst
346 echo "kernel /$kernel root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst
349 # Copy kernel artifacts. To add more artifacts just add to types
350 # For now just support kernel types already being used by something in OE-core
351 for types in bzImage zImage vmlinux vmlinuz fitImage; do
352 for kernel in `find /run/media/$1/ -name $types*`; do
361 echo "Remove your installation media, and press ENTER"