Right way to turn UDOO power off

Discussion in 'General Discussion' started by y.seksit, Jul 10, 2014.

  1. y.seksit

    y.seksit New Member

    Joined:
    May 8, 2014
    Messages:
    17
    Likes Received:
    0
    while using udoo without keyboard monitor and mouse, if turn off power, Can it possible file on Ubuntu or SDCard lost or fail to access?
    How can i protect file?
     
  2. mmeinert

    mmeinert Member

    Joined:
    Jun 17, 2014
    Messages:
    61
    Likes Received:
    1
    I would connect to my board via ssh and use the "shutdown -h now" command
     
  3. fetcher

    fetcher Member

    Joined:
    Mar 9, 2014
    Messages:
    166
    Likes Received:
    20
    If you need to be able to turn power off at any time without the risk of filesystem corruption, I'd suggest mounting the SD card read-only, using a ramdisk (tmpfs) for logs and other transient data, and periodically synchronizing the two, either on demand or via crontab, etc. This should have the added benefit of greatly extending SD card lifetime, considering limited write-cycle endurance of NAND flash media. Here is a page going into some of the necessary details: (for debian, but Ubuntu is Debian-derived and should be very similar)

    https://wiki.debian.org/ReadonlyRoot

    I usually mount the extra tmpfs at /rw ("read-write"), with home directories, various config files and such moved into that and symlinked to their usual locations (e.g. mkdir -p /rw/etc; mv /etc/resolv.conf /rw/etc; ln -s /rw/etc/resolv.conf /etc/resolv.conf) and a flash backing directory at /ro ("read-only"... a directory off of root is fine, it doesn't need ot be a separate fs) to hold snapshots of the ramdisk contents. Use something like 'rsync' for taking snapshots to aoid unneccesary ovewrrites of files that haven't changed.

    After making sure /rw is in /etc/fstab as a tmpfs, add this to the do_start sectoin of /etc/init.d/mountall.sh to automatically populate the ramdisk during boot from its latest snapshot:

    tar -C /ro -cf - . | tar -C /rw -xf - > /dev/null 2>&1

    If you go this route, you do have to be careful about accumulating too much data in the ramdisk and potentially filling it and/or exhausting available RAM. If logfiles are expected to be extremely voluminous (but plain-text), layering a transparent-compression fs on top of the tmpfs may be worthwhile.

    I use small scripts named 'remountrw', 'remountro' to change the SD card root filesystem between read-write (for syncing tmpfs, software updates etc.) and its normal read-only state. A red LED wired to GPIO 150 (Arduino pin 14 / TX3) gets switched on to warn when the rootfs (SD card) is mounted read-write:

    Code:
    #!/bin/sh
    
    # remountrw script (go to read-write mode):
    
    if mount -o remount,rw,noatime /; then
     echo out >/sys/class/gpio/gpio150/direction
     echo 1 >/sys/class/gpio/gpio150/value
    fi
    
    Code:
    #!/bin/sh
    
    # remountro script: (back to read-only state)
    
    sync
    sleep 1
    if mount -o remount,ro  /; then
     echo out >/sys/class/gpio/gpio150/direction
     echo 0 >/sys/class/gpio/gpio150/value
    fi
    
     
  4. y.seksit

    y.seksit New Member

    Joined:
    May 8, 2014
    Messages:
    17
    Likes Received:
    0
    Thank you Fether, let me try which i think it should work
     

Share This Page