Jump to content

peacok

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by peacok

  1. #!/bin/bash

    # Set back a SD Card,  then flash if you like, without file you get a total blank SD Crad, without FS/MBR, real blank

    #Installation:
    # Save this as  /usr/local/bin/mksdcardpi
    # sudo chown root.root /usr/local/bin/mksdcardpi
    # sudo chmod 755 /usr/local/bin/mksdcardpi
    #
    # So now you can use it....
    # mksdcardpi 'filename'  with ' is better... cue

    # text in script german, i am lazy to translate... do it your own.

    # Vars
    sdcard=sdb
    sdcardmount=/mnt/sdcardtmp

    # Frage richtiges Device,,,
    echo '

     '`basename $0`' flashfile
     
     Ohne flashfile, lösche ich auch das FS raus, also empty/blank Karte.
     (2GB flashfiles in der Regel so 3 Minuten zum schreiben)
     
     Es wird die ganze SD Karte zurück gesetzt, und ein trim, auch über den MBR
     der SD Karte.
     

     !! Achtung Device: sonst löscht es dein Computer !!
    =====================================================

     Ist dass das richtige Device? -->  /dev/'$sdcard'
                    y/n
     '
    read -n 1 a
    echo
    if [ "$a" != "y" ];then exit 0;fi

    # Ich frage nochmals, es ist Danger...
    echo '

     Zweite Anfrage !!
     
     !! Achtung Device: sonst löscht es dein Computer !!
    =====================================================

     Ist dass das richtige Device? -->  /dev/'$sdcard'
                    y/n
     '
    read -n 1 a
    echo
    if [ "$a" != "y" ];then exit 0;fi

    # Erstelle temp Mountpoint, umount und löschen der FS Einträge auf sdcard
    sudo mkdir -p $sdcardmount
    sudo umount /dev/"$sdcard"1
    sudo umount /dev/"$sdcard"
    sudo wipefs -a /dev/"$sdcard"

    # Mache ein ganzes FS über die ganze sdcard für fstrim, mount temp und fstrim
    sudo mkfs.ext4 /dev/"$sdcard"
    sync
    sudo mount /dev/"$sdcard" "$sdcardmount"
    #mount
    #echo "taste";read a
    sudo fstrim -a
    #echo "taste";read a

    # Unmount temp, entferne temp mountpoint
    sudo umount /dev/"$sdcard"
    #mount
    #echo "taste";read a
    sudo rm -r "$sdcardmount"

    # Schreibe ein flashfile oder lösche das ganze FS auf sdcard, gleich blank sdcard
    if [ "$1" != "" ];then
     echo '
       Schreibe '"$1"' auf /dev/'"$sdcard"'
       
       '`ls -lah "$1"`'
    '
       dd if="$1" of=/dev/"$sdcard" bs=1M conv=fsync
       sync
     echo '
       Datei '"$1"' geschrieben...
       Done....
    '
    else
       echo '
       Lösche das Filesystem....
    '
       sudo wipefs -a /dev/"$sdcard"
       echo '
       Dateisystem gelöscht....
       Done
    '
    fi

     

  2. I hope you can publish without me having to register in the forum.

     

    I have an SD card, I don't know eMMC (so I never used it), I use a USB SD adapter, maybe there is something similar for eMMS fstrim:

     

    But what I noticed, since you sometimes have to flash it again, it it may be that it no longer works with the boot. The first bootbits are then not at the desired address in the file system on the SD where the boot process wants to access. The remedy for me with an SD card is always to trim the SD card. I don't know if it works for eMMC.

     

    Note: /!\ !!

    ================================================== ==================================================

    The correct device must be selected, otherwise you will delete your normal computer. As Attention /!\ !!

     

    fstrim can only trim mounted filesystems.

     

    PS: A SWAP partition cannot be edited by fstrim. The SWAP must be maintained via fstab with the discard option.

    Example /etc/fstab:

    # swap was on /dev/nvme0n1p5 during installation

    UUID=1346a3ab-57fc-4484-86c1-*******1e0 none swap sw,discard 0 0

     

    However, the images that write normally to the SD card do not work with SWAP partition, so that doesn't concern us.

    ================================================== ===================================================

     

    Here's how I do it: In the example I'm talking about my device, i.e. /dev/sdb (note you have to take what your SD card is)

     

    The SD card is plugged into the USB SD adapter on the normal computer

     

    sudo mkdir -p /mnt/tmp (you can leave /mnt/tmp if you need a tmp mount point again)

     

    Only one umount would be necessary, but both as an example, if necessary, check sudo mount to see if it hangs where.

    sudo umount /dev/sdb1

    sudo umount /dev/sdb

     

    wipefs -a /dev/sdb (very dangerous command, it just wipes out everything from entries in the MBR)

     

    sudo mkfs.ext4 /dev/sdb (that means everything becomes ext4 also the MBR, I want that because of the trim)

     

    sudo mount /dev/sdb /mnt/tmp (now I mount that temporarily)

     

    sudo fstrim -a (this trims everything that is mounted)

     

    sudo umount /dev/sdb

     

    Now you can flash again.....

    Example: (I got the image from the community, decompressing the .xz first with unxz file)

    chris@z240:~/Downloads/OrangePiZero2/ArmBian$ sudo dd if=Armbian_23.02.0-trunk_Orangepizero2_sid_edge_6.1.0.img of=/dev/sdb bs=1M conv=fsync

    2276+0 records 2276+0 records out 2386558976 bytes (2.4 GB, 2.2 GiB) copied, 228,217 s, 10.5 MB/s

     

    Much luck

×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines