functionmnt() { echo"MOUNTING" # 确保挂载目录以 '/' 结尾 local mount_dir=${2%/}/ # 检查挂载目录是否存在,如果不存在则创建 if [ ! -d "$mount_dir" ]; then sudo mkdir -p $mount_dir fi # 检查是否提供了镜像文件路径 if [ -n "$3" ]; then # 挂载镜像文件到指定目录 sudo mount -o loop $3$mount_dir fi # 挂载其他必要的文件系统 sudo mount -t proc /proc ${mount_dir}proc sudo mount -t sysfs /sys ${mount_dir}sys sudo mount -o bind /dev ${mount_dir}dev sudo mount -o bind /dev/pts ${mount_dir}dev/pts sudo chroot${mount_dir} }
functionumnt() { echo"UNMOUNTING" # 确保挂载目录以 '/' 结尾 local mount_dir=${2%/}/ # 首先卸载其他挂载的文件系统 sudo umount ${mount_dir}dev/pts sudo umount ${mount_dir}dev sudo umount ${mount_dir}sys sudo umount ${mount_dir}proc # 检查是否有镜像文件路径参数,如果有,则卸载镜像文件 if [ -n "$3" ]; then sudo umount $mount_dir fi }
if [ "$1" == "-m" ] && [ -n "$2" ] ; then mnt $1$2$3 elif [ "$1" == "-u" ] && [ -n "$2" ]; then umnt $1$2$3 else echo"" echo"Either 1'st, 2'nd or both parameters were missing" echo"" echo"1'st parameter can be one of these: -m(mount) OR -u(umount)" echo"2'nd parameter is the full path of rootfs directory" echo"3'rd parameter (optional) is the path to the image file" echo"" echo"For example: ./ch-mount -m /mnt/rootfs/ /path/to/image.img" echo"" echo 1st parameter : ${1} echo 2nd parameter : ${2} echo 3rd parameter : ${3} fi
$ apt upgrade -y Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 1 not fully installed or removed. After this operation, 0 B of additional disk space will be used. Setting up blueman (2.0.4-1ubuntu2.1) ... Running inchroot, ignoring request. * Reloading system message bus config... Failed to open connection to "system" message bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory invoke-rc.d: initscript dbus, action "reload" failed. dpkg: error processing package blueman (--configure): subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: blueman E: Sub-process /usr/bin/dpkg returned an error code (1)