Raspberry Pi でfsprotectを試す
9回目の今回は、Raspberry Piにfsprotectをインストールします。
- 1回目:Raspberry Pi でOSのインストールと初期設定を行う
- 2回目:Raspberry Pi で使用しないデーモンを停止する
- 3回目:Raspberry Pi でRAMディスクを使う
- 4回目:Raspberry Pi でカーネルにaufsを組み込む
- 5回目:Raspberry Pi で消費電流を測定する
- 6回目:Raspberry Pi でSoftEther VPN 1.0 RC2を試す
- 7回目:SoftEther VPN 1.0 RC2でtapデバイスを試す
- 8回目:Raspberry Pi でAsteriskを試す
- 9回目:Raspberry Pi でfsprotectを試す
普段使っているディスクをリードオンリー(ro)として使い、 RAMディスクを併用してOSに対してリード/ライト(rw)可能なディスクと見せておきながら、再起動すると、変更内容を全てクリアするという環境を作ります。
いわゆる、Live CD的な挙動を実現します。
このようなことを実現するシェルスクリプトが、”fsprotect” というパッケージとなります。
※fsprotectを使用するためには、カーネルにaufsが組み込まれている必要があります。
fsprotectを使用した場合のメリット
- SDカードはリードオンリ動作なので、SDカードの寿命を延ばすことができます。
- いつでも電源オフすることができます。(shutdownコマンドで停止させる必要はありません)
※不意の停電で、ファイルシステムが破損してOSが起動しなくなる等の不具合をなくすことが出来ます。
Raspberry Piを使用したサーバ専用機を、LAN環境に設置して24時間連続動作させます。
SoftEther VPN / Asterisk専用機として設置します。
消費電力は2W程度なので、電気代も気になりません。
※電気代は36円/月くらいです。
fsprotectのインストール
最初に、fsprotectパッケージをインストールします。
[root@ms03 ~]# aptitude install fsprotect
initramfsイメージファイルを作成し直します。
[root@ms03 linux]# update-initramfs -c -k $(uname -r) update-initramfs: Generating /boot/initrd.img-3.6.11-aufs+
/boot/cmdline.txt(カーネルオプションファイル)を修正して、fsprotectを起動するようにします。
変更点は、設定内容の最後に、”fsprotect” の記述を追加するだけです。
※この設定が追加されると、OS起動時に fsprotect が開始され、ファイルシステムを保護するようになります。
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fsprotect
/boot/config.txtを修正して、initramfsの指定を追加します。
[root@ms03 linux]# pico /boot/config.txt # aufs initramfs initrd.img-3.6.11-aufs+
/bootディレクトリもリードオンリーとして、保護するようにします。
[root@ms03 ~]# pico /etc/default/fsprotect # fsprotect configuration for protecting filesystems other than root # Protection will only be enabled when the "fsprotect=" parameter is passed to # the kernel # This is a space separated list of mountpoints to protect. # Only non-virtual filesystems are supported. # DON'T add / in here. Instead use the "fsprotect=" kernel parameter # Each entry is in the form "mountpoint" or "mountpoint=tmpfs_size" # Example: # PROTECT="/boot=100M /home=2G" # bootパーティションも保護する PROTECT="/boot=32M"
起動時のファイルシステムはリードオンリーなので、/etc/fstabで起動時にfsckを行わないように変更します。
変更点は、/dev/mmcblk0p1 , /dev/mmcblk0p2 のfsckオプション(最後の数字の部分)を “0″ に変更します。
[root@ms03 ~]# pico /etc/fstab proc /proc proc defaults 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 0 /dev/mmcblk0p2 / ext4 defaults,noatime 0 0 # a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that # tmpファイルはRAMディスク上に保管する tmpfs /tmp tmpfs defaults,size=32m,noatime,mode=1777 0 0 tmpfs /var/tmp tmpfs defaults,size=16m,noatime,mode=1777 0 0 # /var/logディレクトリはRAMディスク上に配置する tmpfs /var/log tmpfs defaults,size=32m,noatime,mode=0755 0 0
ここで、一旦、OSを再起動させて、aufsとfsprotectが正しく動作することを確認します。
[root@ms03 ~]# reboot
起動時のメッセージを確認しておきます。
起動時のdmesgを確認しておきます。
[root@ms03 ~]# cat /var/log/dmesg [ 0.000000] Booting Linux on physical CPU 0 [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Linux version 3.6.11-aufs+ (root@ms03) (gcc version 4.6.3 (Debian 4.6.3-14+rpi1) ) #2 PREEMPT Wed Mar 13 17:53:08 JST 2013 [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache [ 0.000000] Machine: BCM2708 [ 0.000000] cma: CMA: reserved 16 MiB at 1dc00000 [ 0.000000] Memory policy: ECC disabled, Data cache writeback [ 0.000000] On node 0 totalpages: 126976 [ 0.000000] free_area_init_node: node 0, pgdat c0569e24, node_mem_map c0613000 [ 0.000000] Normal zone: 992 pages used for memmap [ 0.000000] Normal zone: 0 pages reserved [ 0.000000] Normal zone: 125984 pages, LIFO batch:31 [ 0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768 [ 0.000000] pcpu-alloc: [0] 0 [ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 125984 [ 0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1024 bcm2708_fb.fbheight=768 bcm2708.boardrev=0x100000f bcm2708.serial=0xfebafb3d smsc95xx.macaddr=B8:27:EB:BA:FB:3D sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fsprotect [ 0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes) [ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes) [ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes) [ 0.000000] Memory: 496MB = 496MB total [ 0.000000] Memory: 477320k/477320k available, 30584k reserved, 0K highmem [ 0.000000] Virtual kernel memory layout: [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) [ 0.000000] fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) [ 0.000000] vmalloc : 0xdf800000 - 0xff000000 ( 504 MB) [ 0.000000] lowmem : 0xc0000000 - 0xdf000000 ( 496 MB) [ 0.000000] modules : 0xbf000000 - 0xc0000000 ( 16 MB) [ 0.000000] .text : 0xc0008000 - 0xc0511f44 (5160 kB) [ 0.000000] .init : 0xc0512000 - 0xc0534bd4 ( 139 kB) [ 0.000000] .data : 0xc0536000 - 0xc056a640 ( 210 kB) [ 0.000000] .bss : 0xc056a664 - 0xc0612dd8 ( 674 kB) [ 0.000000] NR_IRQS:330 [ 0.000000] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 4294967ms [ 0.000000] Console: colour dummy device 80x30 [ 0.000000] console [tty1] enabled [ 0.000721] Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736) [ 0.040093] pid_max: default: 32768 minimum: 301 [ 0.040330] Mount-cache hash table entries: 512 [ 0.040878] Initializing cgroup subsys cpuacct [ 0.040917] Initializing cgroup subsys devices [ 0.040940] Initializing cgroup subsys freezer [ 0.040960] Initializing cgroup subsys blkio [ 0.041019] CPU: Testing write buffer coherency: ok [ 0.041259] hw perfevents: enabled with v6 PMU driver, 3 counters available [ 0.041364] Setting up static identity map for 0x3c3168 - 0x3c31c4 [ 0.042421] devtmpfs: initialized [ 0.049309] NET: Registered protocol family 16 [ 0.054650] DMA: preallocated 4096 KiB pool for atomic coherent allocations [ 0.055430] bcm2708.uart_clock = 0 [ 0.056368] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers. [ 0.056404] hw-breakpoint: maximum watchpoint size is 4 bytes. [ 0.056429] mailbox: Broadcom VideoCore Mailbox driver [ 0.056494] bcm2708_vcio: mailbox at f200b880 [ 0.056563] bcm_power: Broadcom power driver [ 0.056588] bcm_power_open() -> 0 [ 0.056606] bcm_power_request(0, 8) [ 0.557186] bcm_mailbox_read -> 00000080, 0 [ 0.557213] bcm_power_request -> 0 [ 0.557231] Serial: AMBA PL011 UART driver [ 0.557333] dev:f1: ttyAMA0 at MMIO 0x20201000 (irq = 83) is a PL011 rev3 [ 0.877304] console [ttyAMA0] enabled [ 0.894926] bio: create slab at 0 [ 0.899595] SCSI subsystem initialized [ 0.903505] usbcore: registered new interface driver usbfs [ 0.909117] usbcore: registered new interface driver hub [ 0.914603] usbcore: registered new device driver usb [ 0.920600] Switching to clocksource stc [ 0.924672] FS-Cache: Loaded [ 0.927729] CacheFiles: Loaded [ 0.938509] NET: Registered protocol family 2 [ 0.943470] TCP established hash table entries: 16384 (order: 5, 131072 bytes) [ 0.951112] TCP bind hash table entries: 16384 (order: 4, 65536 bytes) [ 0.957835] TCP: Hash tables configured (established 16384 bind 16384) [ 0.964398] TCP: reno registered [ 0.967653] UDP hash table entries: 256 (order: 0, 4096 bytes) [ 0.973504] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes) [ 0.979985] NET: Registered protocol family 1 [ 0.984736] RPC: Registered named UNIX socket transport module. [ 0.990673] RPC: Registered udp transport module. [ 0.995426] RPC: Registered tcp transport module. [ 1.000135] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 1.006805] Trying to unpack rootfs image as initramfs... [ 1.342611] Freeing initrd memory: 3524K [ 1.346991] bcm2708_dma: DMA manager at f2007000 [ 1.351679] bcm2708_gpio: bcm2708_gpio_probe c0543dd8 [ 1.357072] vc-mem: phys_addr:0x00000000 mem_base=0x1fa00000 mem_size:0x20000000(512 MiB) [ 1.365948] audit: initializing netlink socket (disabled) [ 1.371399] type=2000 audit(1.220:1): initialized [ 1.461726] VFS: Disk quotas dquot_6.5.2 [ 1.465803] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) [ 1.472633] FS-Cache: Netfs nfs registered for caching [ 1.478238] NFS: Registering the id_resolver key type [ 1.483373] Key type id_resolver registered [ 1.487623] Key type id_legacy registered [ 1.491962] aufs 3.6-20130204 [ 1.494998] msgmni has been set to 971 [ 1.499910] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252) [ 1.507582] io scheduler noop registered [ 1.511519] io scheduler deadline registered (default) [ 1.516740] io scheduler cfq registered [ 1.533970] Console: switching to colour frame buffer device 128x48 [ 1.547067] kgdb: Registered I/O driver kgdboc. [ 1.552097] vc-cma: Videocore CMA driver [ 1.556168] vc-cma: vc_cma_base = 0x00000000 [ 1.560947] vc-cma: vc_cma_size = 0x00000000 (0 MiB) [ 1.566444] vc-cma: vc_cma_initial = 0x00000000 (0 MiB) [ 1.578221] brd: module loaded [ 1.584886] loop: module loaded [ 1.588333] vchiq: vchiq_init_state: slot_zero = 0xddc00000, is_master = 0 [ 1.595941] Loading iSCSI transport class v2.0-870. [ 1.601685] usbcore: registered new interface driver smsc95xx [ 1.607733] dwc_otg: version 3.00a 10-AUG-2012 (platform bus) [ 1.818662] Core Release: 2.80a [ 1.821891] Setting default values for core params [ 1.829628] Finished setting default values for core params [ 2.043013] Using Buffer DMA mode [ 2.049103] Periodic Transfer Interrupt Enhancement - disabled [ 2.057695] Multiprocessor Interrupt Enhancement - disabled [ 2.066043] OTG VER PARAM: 0, OTG VER FLAG: 0 [ 2.073141] Dedicated Tx FIFOs mode [ 2.080348] dwc_otg: Microframe scheduler enabled [ 2.080750] dwc_otg bcm2708_usb: DWC OTG Controller [ 2.088619] dwc_otg bcm2708_usb: new USB bus registered, assigned bus number 1 [ 2.098778] dwc_otg bcm2708_usb: irq 32, io mem 0x00000000 [ 2.107155] Init: Port Power? op_state=1 [ 2.113854] Init: Power Port (0) [ 2.120019] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002 [ 2.129680] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 2.139700] usb usb1: Product: DWC OTG Controller [ 2.147178] usb usb1: Manufacturer: Linux 3.6.11-aufs+ dwc_otg_hcd [ 2.156148] usb usb1: SerialNumber: bcm2708_usb [ 2.164098] hub 1-0:1.0: USB hub found [ 2.170703] hub 1-0:1.0: 1 port detected [ 2.177629] dwc_otg: FIQ enabled [ 2.177647] dwc_otg: NAK holdoff enabled [ 2.177663] Module dwc_common_port init [ 2.177883] Initializing USB Mass Storage driver... [ 2.185756] usbcore: registered new interface driver usb-storage [ 2.194476] USB Mass Storage support registered. [ 2.201966] usbcore: registered new interface driver libusual [ 2.210798] mousedev: PS/2 mouse device common for all mice [ 2.219885] bcm2835-cpufreq: min=700000 max=1000000 cur=1000000 [ 2.228766] bcm2835-cpufreq: switching to governor powersave [ 2.237185] bcm2835-cpufreq: switching to governor powersave [ 2.245704] cpuidle: using governor ladder [ 2.253524] cpuidle: using governor menu [ 2.261218] sdhci: Secure Digital Host Controller Interface driver [ 2.271150] sdhci: Copyright(c) Pierre Ossman [ 2.279411] sdhci: Enable low-latency mode [ 2.324785] mmc0: SDHCI controller on BCM2708_Arasan [platform] using platforms DMA [ 2.336632] mmc0: BCM2708 SDHC host at 0x20300000 DMA 2 IRQ 77 [ 2.348597] sdhci-pltfm: SDHCI platform and OF driver helper [ 2.363980] usbcore: registered new interface driver usbhid [ 2.373615] usbhid: USB HID core driver [ 2.383614] Indeed it is in host mode hprt0 = 00021501 [ 2.395438] TCP: cubic registered [ 2.414622] Initializing XFRM netlink socket [ 2.434652] NET: Registered protocol family 17 [ 2.454767] Key type dns_resolver registered [ 2.463255] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5 [ 2.505372] registered taskstats version 1 [ 2.513511] mmc0: read SD Status register (SSR) after 3 attempts [ 2.535788] Freeing init memory: 136K [ 2.548588] mmc0: new high speed SDHC card at address f33e [ 2.568723] mmcblk0: mmc0:f33e SD08G 7.32 GiB [ 2.591992] mmcblk0: p1 p2 [ 2.665491] udevd[56]: starting version 175 [ 2.674733] usb 1-1: new high-speed USB device number 2 using dwc_otg [ 2.701935] Indeed it is in host mode hprt0 = 00001101 [ 3.005037] usb 1-1: New USB device found, idVendor=0424, idProduct=9512 [ 3.029003] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 3.055549] hub 1-1:1.0: USB hub found [ 3.063505] hub 1-1:1.0: 3 ports detected [ 3.364931] usb 1-1.1: new high-speed USB device number 3 using dwc_otg [ 3.485466] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00 [ 3.507742] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 3.537840] smsc95xx v1.0.4 [ 3.619741] smsc95xx 1-1.1:1.0: eth0: register smsc95xx at usb-bcm2708_usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:xx:xx:xx [ 4.289105] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null) [ 6.382548] udevd[305]: starting version 175 [ 7.575537] Registered led device: led0 [ 12.583819] bcm2835 ALSA card created! [ 12.637558] bcm2835 ALSA chip created! [ 12.700339] bcm2835 ALSA chip created! [ 12.748469] bcm2835 ALSA chip created! [ 12.780403] bcm2835 ALSA chip created! [ 12.815338] bcm2835 ALSA chip created! [ 12.845273] bcm2835 ALSA chip created! [ 12.871459] bcm2835 ALSA chip created! [ 18.094175] mmc0: missed completion of cmd 18 DMA (512/512 [1]/[1]) - ignoring it [ 18.105981] mmc0: DMA IRQ 6 ignored - results were reset [ 18.120505] mmc0: missed completion of cmd 18 DMA (512/512 [1]/[1]) - ignoring it [ 18.132412] mmc0: DMA IRQ 6 ignored - results were reset [ 23.021588] NET: Registered protocol family 10 [ 23.022886] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready [ 23.042937] Bridge firewalling registered [ 23.100253] device eth0 entered promiscuous mode [ 23.143781] IPv6: ADDRCONF(NETDEV_UP): br0: link is not ready [ 23.927282] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready [ 23.928852] smsc95xx 1-1.1:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0xC1E1 [ 23.936603] br0: port 1(eth0) entered forwarding state [ 23.936657] br0: port 1(eth0) entered forwarding state [ 23.936803] IPv6: ADDRCONF(NETDEV_CHANGE): br0: link becomes ready [ 26.747239] bcm2835-cpufreq: switching to governor ondemand [ 26.747270] bcm2835-cpufreq: switching to governor ondemand
fsprotect動作の確認
見かけ上、リード・ライト可能なドライブとして動作しますので、パッケージのインストールや削除も、普通に行うことができます。ただし、ファイルの書き込みを伴う動作は、すべてRAMディスク上で処理されていますので、OSの再起動や電源OFFで、”すべての変更は無かったこと” になります。
試しに、動作中にいきなり電源をオフしてみましたが、OSが壊れることはなく正しく起動しました(100回程試験)
さらに、fsprotect.testファイルを作成してみます。中身が空のファイルを作成します。
再起動させて、先ほど作成したfsprotect.testファイルが消えていることを確認します。
SoftEthe VPN やAsteriskの設定変更時の対応
面倒ですが、ユーザ追加などの修正が必要になった場合は、SDカードをWindowsPCに接続して対応します。
※Raspberry Pi上では、見かけ上修正できてもリブートで元に戻りますので、修正できません。
cmdline.txt ファイルをエディタで修正します。最後に記述している fsprotect を nofsprotect に変更します。
※この変更を行うことで、通常どうりのリード・ライト可能なファイルシステムに戻ります。
以上で、「Raspberry Pi でfsprotectを試す」を終了します。