From 5b6e48376938fde473ee908d7a7482b93647eb0e Mon Sep 17 00:00:00 2001 From: Vinay Gahlout Date: Fri, 1 Mar 2024 14:50:11 +0530 Subject: [PATCH] Added logic to mount Linux boot disk with LVM and to mount NTFS disk automatically --- gce_rescue/startup-script.txt | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/gce_rescue/startup-script.txt b/gce_rescue/startup-script.txt index 43c7593..165d690 100644 --- a/gce_rescue/startup-script.txt +++ b/gce_rescue/startup-script.txt @@ -9,8 +9,36 @@ hostname ${HOSTNAME}-rescue while [ true ]; do [[ -e /dev/disk/by-id/google-${disk} ]] && { mkdir -p /mnt/sysroot - disk_p=$(lsblk -rf /dev/disk/by-id/google-${disk} | egrep -i 'ext[3-4]|xfs|microsoft') - [[ /dev/${disk_p%% *} ]] && mount /dev/${disk_p%% *} /mnt/sysroot + fs=$(lsblk -rf /dev/disk/by-id/google-${disk} | egrep -i 'ext[3-4]|xfs|ntfs'| awk '{print $2}') + case $fs in + ntfs) + apt-get install -y ntfs-3g + disk_map=$(lsblk -rf /dev/disk/by-id/google-${disk}| egrep -i 'ntfs'| awk '{print $1}') + ntfsfix /dev/${disk_map} + [[ /dev/${disk_map} ]] && mount -t ntfs /dev/${disk_map} /mnt/sysroot + ;; + + ext4|ext3|xfs) + disk_map=$(lsblk -rf /dev/disk/by-id/google-${disk}| egrep -i LVM2_member| awk '{print $1}') + if [[ -n ${disk_map} ]]; + then + apt-get install -y lvm2 + pvscan; vgscan + vgname=$(vgs --devices /dev/${disk_map} -o vg_name --noheadings) + vgchange -ay $vgname + vgscan; lvscan + disk_p=$(blkid -U $(lsblk -rf /dev/disk/by-id/google-${disk} | egrep -i 'ext[3-4]|xfs' | awk '{print $NF}')) + [[ $disk_p ]] && mount $disk_p /mnt/sysroot + else + disk_p=$(lsblk -rf /dev/disk/by-id/google-${disk} | egrep -i 'ext[3-4]|xfs') + [[ /dev/${disk_p%% *} ]] && mount /dev/${disk_p%% *} /mnt/sysroot + fi + ;; + + *) + echo "FS not supported ";; + + esac [[ -d /mnt/sysroot/proc ]] && mount -t proc proc /mnt/sysroot/proc [[ -d /mnt/sysroot/sys ]] && mount -t sysfs sys /mnt/sysroot/sys @@ -36,4 +64,4 @@ EOF chmod 644 /etc/systemd/system/rescue_automount.service systemctl enable rescue_automount.service systemctl start rescue_automount.service -echo "END:${ts}" 2>&1 \ No newline at end of file +echo "END:${ts}" 2>&1