1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

raspberrypi readonly

Last updated at Posted at 2019-06-15

ICカードで施錠 https://qiita.com/carpenders/items/94d29098127faaffe1fc

作業開始

pi@raspberrypi:~ $ sudo bash
root@raspberrypi:/home/pi# cd /usr/share/initramfs-tools
root@raspberrypi:/usr/share/initramfs-tools# vi hook-functions
# ★497行目
        for arg in "$@" ; do
                case "$arg" in
                base)
                        modules="$modules btrfs ext2 ext3 ext4 ext4dev overlay" # ★overlayを追加
                        modules="$modules isofs jfs reiserfs udf xfs"
                        modules="$modules nfs nfsv2 nfsv3 nfsv4"
                        modules="$modules af_packet atkbd i8042 psmouse"
                        modules="$modules virtio_pci virtio_mmio"

root@raspberrypi:/usr/share/initramfs-tools# cd scripts
root@raspberrypi:/usr/share/initramfs-tools/scripts#
root@raspberrypi:/usr/share/initramfs-tools/scripts# cp local overlay
root@raspberrypi:/usr/share/initramfs-tools/scripts# cp -rp local-premount overlay-premount
root@raspberrypi:/usr/share/initramfs-tools/scripts# cp -rp local-bottom overlay-bottom
cp: cannot stat 'local-bottom': No such file or directory # ★エラーは無視する
root@raspberrypi:/usr/share/initramfs-tools/scripts# vi overlay

local_mount_root()を変更
local_mount_root()
{
        local_top
        local_device_setup "${ROOT}" "root file system"
        ROOT="${DEV}"

        # Get the root filesystem type if not set
        if [ -z "${ROOTFSTYPE}" ]; then
                FSTYPE=$(get_fstype "${ROOT}")
        else
                FSTYPE=${ROOTFSTYPE}
        fi

        local_premount

#        if [ "${readonly}" = "y" ]; then # ★コメントアウト
                roflag=-r
#        else # ★コメントアウト
#                roflag=-w # ★コメントアウト
#        fi # ★コメントアウト

        # FIXME This has no error checking
        modprobe ${FSTYPE}

        checkfs ${ROOT} root # ★"${FSTYPE}"を削除

        # FIXME This has no error checking
        # Mount root
        mkdir /upper /lower # ★1行追加
        if [ "${FSTYPE}" != "unknown" ]; then
                mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /lower # ★/lowerに変更
        else
                mount ${roflag} ${ROOTFLAGS} ${ROOT} /lower # ★/lowerに変更
        fi
        # ★以下を追加
        modprobe overlay
        mount -t tmpfs tmpfs /upper
        mkdir /upper/data /upper/work
        mount -t overlay -olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work overlay ${rootmnt}
}
root@raspberrypi:/usr/share/initramfs-tools/scripts# update-initramfs -c -k $(uname -r)
update-initramfs: Generating /boot/initrd.img-4.14.98-v7+
root@raspberrypi:/usr/share/initramfs-tools/scripts# cd /boot
root@raspberrypi:/boot# mv initrd.img-$(uname -r) initrd7.img
root@raspberrypi:/boot# vi config.txt
★末尾に以下を追加
kernel=kernel7.img
initramfs initrd7.img
root@raspberrypi:/boot# vi cmdline.txt
★以下に変更 boot=overlay root=/dev/mmcblk0p2
boot=overlay dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
root@raspberrypi:/boot# reboot

readonlyを確認する。

pi@raspberrypi:~ $ mount | fgrep ' / '
overlay on / type overlay (rw,noatime,lowerdir=/lower,upperdir=/upper/data,workdir=/upper/work)

readonlyを解除する。

/boot/cmdline.txtboot=overlay を削除する

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?