Bläddra i källkod

change(init_script): check whether the ext4 image exists before mounting the image

greatbridf 7 månader sedan
förälder
incheckning
d9c5949512
2 ändrade filer med 14 tillägg och 8 borttagningar
  1. 7 4
      user-programs/init_script_riscv64.sh
  2. 7 4
      user-programs/init_script_x86_64.sh

+ 7 - 4
user-programs/init_script_riscv64.sh

@@ -42,10 +42,13 @@ echo ok >&2
 do_or_freeze mkdir -p /etc /root /proc
 do_or_freeze mount -t procfs proc proc
 
-echo -n -e "Mounting the ext4 image... " >&2
-do_or_freeze mkdir -p /mnt1
-do_or_freeze mount -t ext4 /dev/sdb /mnt1
-echo ok >&2
+# Check if the device /dev/sdb is available and can be read
+if dd if=/dev/sdb of=/dev/null bs=512 count=1; then
+    echo -n -e "Mounting the ext4 image... " >&2
+    do_or_freeze mkdir -p /mnt1
+    do_or_freeze mount -t ext4 /dev/sdb /mnt1
+    echo ok >&2
+fi
 
 cp /mnt/ld-musl-i386.so.1 /lib/ld-musl-i386.so.1
 ln -s /lib/ld-musl-i386.so.1 /lib/libc.so

+ 7 - 4
user-programs/init_script_x86_64.sh

@@ -42,10 +42,13 @@ echo ok >&2
 do_or_freeze mkdir -p /etc /root /proc
 do_or_freeze mount -t procfs proc proc
 
-echo -n -e "Mounting the ext4 image... " >&2
-do_or_freeze mkdir -p /mnt1
-do_or_freeze mount -t ext4 /dev/sdb /mnt1
-echo ok >&2
+# Check if the device /dev/sdb is available and can be read
+if dd if=/dev/sdb of=/dev/null bs=512 count=1; then
+    echo -n -e "Mounting the ext4 image... " >&2
+    do_or_freeze mkdir -p /mnt1
+    do_or_freeze mount -t ext4 /dev/sdb /mnt1
+    echo ok >&2
+fi
 
 cp /mnt/ld-musl-i386.so.1 /lib/ld-musl-i386.so.1
 ln -s /lib/ld-musl-i386.so.1 /lib/libc.so