在mount和mkdir之间循环

时间:2019-01-10 16:06:06

标签: shell partitioning mount mkdir

我正在尝试使用此脚本挂载一些分区。这正是我在系统上运行的:

#!/bin/bash

FILENAME="2018-11-13-raspbian-stretch-lite.img"
MOUNTPATH="/mnt/rasp-pi-rootfs"
HOMEPATH=$(pwd)

cd $HOMEPATH
set +e
umount /dev/loop0p4
umount /dev/loop0p3
umount /dev/loop0p1
umount /dev/loop0p2
losetup -D
losetup -a
rm $FILENAME
rm $HOMEPATH/home.tgz
set -e

unzip $FILENAME.zip
truncate -s +800M $FILENAME
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $FILENAME
    d # delete partition
    2 # partition number 2
    n # new partition
    p # primary
    2 # partition number 2
    98304 # first sector
    +2G # 2GB partition
    n # don't remove the signature
    n # new partition
    p # primary 
    3 # partition number 3
    4292608 # first sector
    +50M # 50MB partition
    n # new partition
    p # primary
    4395008 # first sector
    5283839 # last sector
    t # change partition type
    4 # partition number 4
    c # W96 FAT32 (LBA)
    p # print partition table
    w # write and exit
EOF

losetup -P /dev/loop0 $FILENAME
e2fsck -f /dev/loop0p2
resize2fs /dev/loop0p2
mkfs.ext4 /dev/loop0p3
e2fsck -f /dev/loop0p3
mkfs.vfat -F 32 /dev/loop0p4

mount /dev/loop0p2 $MOUNTPATH

cd $MOUNTPATH/home/
tar cf $HOMEPATH/home.tgz pi/
rm -r pi/
cd $HOMEPATH

mount /dev/loop0p1 $MOUNTPATH/boot/
mount /dev/loop0p3 $MOUNTPATH/home/

tar xf home.tgz -C /mnt/rasp-pi-rootfs/home/
rm $MOUNTPATH/etc/init.d/resize2fs_once 
rm $MOUNTPATH/etc/rc3.d/S01resize2fs_once

#mkdir -p $MOUNTPATH/home/pi/resources
mount /dev/loop0p4 $MOUNTPATH/home/pi/resources

在没有mkdir的情况下,最后一个mount调用失败,表明挂载点不存在(并且实际上不存在)。相反,如果我尝试创建目录,则mkdir不能说该目录已经存在(尽管-p不应返回错误),但目录确实存在。

我不明白这里发生了什么。 该脚本以root的身份运行。

0 个答案:

没有答案