Help us understand the problem. What is going on with this article?

「RaspberryPiをROM化する」をシェルスクリプト化した

「RaspberryPiをROM化する」にシェルスクリプトをかぶせただけの投稿。
https://qiita.com/felis_silv/items/e69f3490091bee9fe619
簡単にかいつまんで説明すると書き込みをONにしておくと、破損しやすいSDカードを読み取り専用にすることによって、破損しにくくなるスクリプト。

これを /usr/local/sbinにでも置いておいてください。

使い方

最初に rom installを実行してください。
その後、読み取り専用を解除したい場合はrom rw、読み取り専用にしたい場合はrom roです。

スクリプト

ご自由に煮るなり焼くなりどうぞ。

rom
#!/bin/sh

#RaspberryPiをROM化/解除するシェルスクリプト
#options:
# rw: 読み書き可能に
# ro: 読み取り専用に
# status: 現在の読み取り専用かどうかの状態を表示
# install: このスクリプトを使える状態にする。最初に実行
#https://qiita.com/felis_silv/items/e69f3490091bee9fe619

help(){
    echo "Usage: $CMDNAME ro|rw|status|install" 1>&2
}
# Read / Write
toRW(){
    if [ -e /mnt/boot-ro/config.txt ]; then
        sudo mount -o remount,rw /dev/mmcblk0p1
        sudo grep -v initramfs /mnt/boot-ro/config.txt >/tmp/config.txt
        sudo cp /tmp/config.txt /mnt/boot-ro/config.txt
        echo "Write enabled now."
        echo "done. please reboot."
    else
        echo "Already write enabled"
    fi
}
# Readonly
toRO(){
    if [ -e /mnt/boot-ro/config.txt ]; then
        echo "Already write protected"
    else
        sudo grep -v initramfs /boot/config.txt >/tmp/config.txt
        sudo echo initramfs initrd.gz >> /tmp/config.txt
        sudo cp /tmp/config.txt /boot/config.txt
        echo "Write protected now."
        echo "done. please reboot."
    fi
}
#show status
status(){
    if [ -e /mnt/boot-ro/config.txt ]; then
        echo "Write protected now"
    else
        echo "Write enabled now"
    fi
}
install(){
    echo "Install start... Aftre install, will be reboot."
    sudo bash
    apt-get install -y git rsync gawk busybox bindfs
    dphys-swapfile swapoff
    dphys-swapfile uninstall
    update-rc.d dphys-swapfile disable
    systemctl disable dphys-swapfile
    git clone https://github.com/josepsanzcamp/root-ro.git
    rsync -va root-ro/etc/initramfs-tools/* /etc/initramfs-tools/
    mkinitramfs -o /boot/initrd.gz
    echo initramfs initrd.gz >> /boot/config.txt
    echo "install end."
    echo "done. please reboot."
}

case $@ in
    ro)
        toRO
        ;;
    rw)
        toRW
         ;;
    status)
        status
        ;;
    install)
        install
        ;;
    *)
        help
        ;;
esac
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした