Fix #47: Support /dev/sd* as sdcard device

* The check for valid sdcard paths has been removed (because it
  doesn't make sense for /dev/sd*, this might as well be a real
  harddrive)
* New check: abort if any partition of the sdcard is mounted
* Automatically detect if the partitions are called "p1", "p2" etc.
  or just "1", "2" etc. (/dev/sda1 vs. /dev/mmcblk0p1)
* pmb.helpers.mount.ismount(): check the source (new) and the target
  path in /proc/mounts
This commit is contained in:
Oliver Smith 2017-06-04 02:57:37 +02:00
parent 1f96439a84
commit 9d4bc61545
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
4 changed files with 23 additions and 17 deletions

View File

@ -166,10 +166,6 @@ install_device_packages = [
install_size_image = "835M" install_size_image = "835M"
install_size_boot = "100M" install_size_boot = "100M"
# fnmatch-patterns, that the sdcard patch must match. Otherwise the
# installer will refuse to format the device.
install_valid_sdcard_devices = ["/dev/mmcblk*", "/dev/loop*"]
# #
# FLASH # FLASH

View File

@ -31,6 +31,8 @@ def ismount(folder):
words = line.split() words = line.split()
if len(words) >= 2 and words[1] == folder: if len(words) >= 2 and words[1] == folder:
return True return True
if words[0] == folder:
return True
return False return False

View File

@ -18,6 +18,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
""" """
import logging import logging
import os import os
import glob
import pmb.helpers.mount import pmb.helpers.mount
import pmb.install.losetup import pmb.install.losetup
import pmb.helpers.cli import pmb.helpers.cli
@ -25,13 +26,6 @@ import pmb.config
import fnmatch import fnmatch
def sdcard_validate_path(args):
for pattern in pmb.config.install_valid_sdcard_devices:
if fnmatch.fnmatch(args.sdcard, pattern):
return True
return False
def mount_sdcard(args): def mount_sdcard(args):
# Sanity checks # Sanity checks
if args.deviceinfo["external_disk_install"] != "true": if args.deviceinfo["external_disk_install"] != "true":
@ -40,9 +34,10 @@ def mount_sdcard(args):
if not os.path.exists(args.sdcard): if not os.path.exists(args.sdcard):
raise RuntimeError("The sdcard device does not exist: " + raise RuntimeError("The sdcard device does not exist: " +
args.sdcard) args.sdcard)
if not sdcard_validate_path(args): for path in glob.glob(args.sdcard + "*"):
raise RuntimeError("The sdcard path does not look valid. We will" if pmb.helpers.mount.ismount(path):
" not attempt to format this!") raise RuntimeError(path + " is mounted! We will not attempt"
" to format this!")
if pmb.helpers.cli.ask(args, "EVERYTHING ON " + args.sdcard + " WILL BE" if pmb.helpers.cli.ask(args, "EVERYTHING ON " + args.sdcard + " WILL BE"
" ERASED! CONTINUE?") != "y": " ERASED! CONTINUE?") != "y":
raise RuntimeError("Aborted.") raise RuntimeError("Aborted.")

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>. along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
""" """
import os
import logging import logging
import pmb.chroot import pmb.chroot
import pmb.config import pmb.config
@ -30,9 +31,21 @@ def partitions_mount(args):
if not args.sdcard: if not args.sdcard:
img_path = "/home/user/rootfs/" + args.device + ".img" img_path = "/home/user/rootfs/" + args.device + ".img"
prefix = pmb.install.losetup.device_by_back_file(args, img_path) prefix = pmb.install.losetup.device_by_back_file(args, img_path)
for suffix in ["p1", "p2"]:
pmb.helpers.mount.bind_blockdevice(args, prefix + suffix, partition_prefix = None
args.work + "/chroot_native/dev/install" + suffix) for symbol in ["p", ""]:
if os.path.exists(prefix + symbol + "1"):
partition_prefix = symbol
if not partition_prefix:
raise RuntimeError("Unable to find the partition prefix,"
" expected the first partition of " +
prefix + " to be located at " + prefix
+ "1 or " + prefix + "p1!")
for i in [1, 2]:
source = prefix + partition_prefix + str(i)
target = args.work + "/chroot_native/dev/installp" + str(i)
pmb.helpers.mount.bind_blockdevice(args, source, target)
def partition(args): def partition(args):