顯示具有 ARM rootfs 標籤的文章。 顯示所有文章
顯示具有 ARM rootfs 標籤的文章。 顯示所有文章

2015年5月11日 星期一

ARM rootfs 語系設定

rootfs 太陽春, 解壓縮包時, 常常有一些語系相關的警告出現. 今天來看看如何設定.

打 locale 看到 LANGUAGE & LC_ALL 沒有定義, 另外有 3 個警告
debian@arm:~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
debian@arm:~$

打 locale -a 可看到目前已經安裝語系.
debian@arm:~$ locale -a
C
C.UTF-8
POSIX

sudo nano /etc/default/locale
改 LANG=C.UTF-8
加 LANGUAGE=C.UTF-8
LC_ALL=C

若是要增加語系, 則用
locale-gen en_US.UTF-8
dpkg-reconfigure locales





ARM rootfs 減肥

檢查各目錄使用容量

du -hx --max-depth=1 /
du –sh /var/cache/apt/archives
du –sh /var/lib/apt/lists

清除記錄
apt-get clean
apt-get autoremove --purge

/usr/share/doc 及 /usr/share/man 的文件, 在 embedded 系統中沒有甚麼大用, 只是佔空間 40幾MB, 就看看如何把它們刪掉

建立 /etc/dpkg/dpkg.cfg.d/01_nodoc
加入如下內容, dpkg 在抓套件時, 就不會抓 doc
path-exclude /usr/share/doc/*
# we need to keep copyright files for legal reasons
path-include /usr/share/doc/*/copyright
path-exclude /usr/share/man/*
path-exclude /usr/share/groff/*
path-exclude /usr/share/info/*
# lintian stuff is small, but really unnecessary
path-exclude /usr/share/lintian/*
path-exclude /usr/share/linda/*
然後執行刪除既有 doc
find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true
find /usr/share/doc -empty|xargs rmdir || true
rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

在 /usr/share/locale 也有一堆用不到的語系資料, 可以用 localepurge 來移除

apt-get install localepurge


增加 /etc/locale.nopurge, 假設只留英語

####################################################
# This is the configuration file for localepurge(8).
####################################################

####################################################
# Uncommenting this string enables removal of localized
# man pages based on the configuration information for
# locale files defined below:

MANDELETE

####################################################
# Uncommenting this string causes localepurge to simply delete
# locales which have newly appeared on the system without
# bothering you about it:

DONTBOTHERNEWLOCALE

####################################################
# Uncommenting this string enables display of freed disk
# space if localepurge has purged any superfluous data:

SHOWFREEDSPACE

#####################################################
# Commenting out this string enables faster but less
# accurate calculation of freed disk space:

#QUICKNDIRTYCALC

#####################################################
# Commenting out this string disables verbose output:

#VERBOSE

#####################################################
# Following locales won't be deleted from this system
# after package installations done with apt-get(8):

en
en_US
en_US.ISO-8859-15
en_US.UTF-8


sudo localepurge
localepurge 會刪除不要的語系, 以後安裝新套件, localepurge 會被啟動, 將不要的刪除, 這樣會讓系統變慢. 最好是用完, 將 localpurge remove. 需要再重裝

如果不需要 X-windows, 相關套件也可以刪去

apt-get remove libx11-6 libx11-data

另外 /var 也有些肥胖, 如果不再安裝套件, 可以刪去內容物, 但是路徑要留下來
sudo find /var/cache/apt/ -type f -exec rm -v {} \;
sudo find /var/lib/apt/lists -type f -exec rm -v {} \;














2015年3月31日 星期二

修改 ARM rootfs

用 cross system 在x86 OS 修改 ARM OS感到麻煩, 直接在 ARM target board 直接修改看看

用 su 權限
mkdir /mnt/rootfs
cd  /mnt/rootfs
tar zxvf   my_arm_rootfs.tgz
如果有 symbol link, tar 參數加 -h

for f in proc sys dev ; do mount --bind /$f /mnt/$f ; done

#!/bin/bash
mount --bind /dev  /mnt/rootfs/dev
mount --bind /proc/mnt/rootfs/proc
mount --bind /sys /mnt/rootfs/sys
mount --bind /dev/pts /mnt/rootfs/dev/pts
cp /etc/resolv.conf /mnt/rootfs/etc/resolv.conf
chroot /mnt/rootfs su

修改設定, 加減套件

最後做 rootfs 減肥

打 exit 離開 chroot

解除 ramfs
sync
umount /mnt/rootfs/dev
umount /mnt/rootfs/proc
umount /mnt/rootfs/sys
umount /mnt/rootfs/dev/pts

打包, 用 -C 設相對位置

tar zcvf my_new_rootfs.tgz -C /mnt/rootfs .

Linux console 自動登入

Linux 純文字模式登入需要 user name 及 password.

有些場合, 是機器之間對接, 不需要user name, password

編輯 /etc/login.defs
找到 NO_PASSWORD_CONSOLE, 這個設定是 login 時不用打password

修改例子 NO_PASSWORD_CONSOLE ttyS0:ttyS1

編輯 /etc/inittab
找到 getty, 有些OS是 agetty
原來像這樣
T0:123:respawn:/sbin/getty -L ttyS0 115200

修改例子 T0:123:respawn:/sbin/getty -n -l  /usr/sbin/autologin -L ttyS0 115200
-n 意思是不顯示 login 訊息
-l 意思是使用指定的 login 程式

但是 /usr/sbin 找不到 autologin

我們要自己準備 autologin.c,  code 如下, "your user name here" 換成你的 user name

#include "unistd.h"

int main() 
{
  execlp( "login", "login", "-f", "your user name here", 0);
}

產生執行檔
gcc autologin.c -o autologin

2015年3月27日 星期五

ARM Linux normal user can not access network, eg 無法 ping


下了 Ubuntu 的 ARM Linux rootfs, 在 root 時, ping 都正常, 但是一般user 就出現如下問題

ping www.google.com
ping: unknown host www.google.com

ping 8.8.8.8
socket: Permission denied

在 /etc/group   

inet:x:3003:root
net_raw:x:3004:root



然後給一般 user 使用 inet 權限

sudo gpasswd -a username inet

再使用 ping 出現


Ping: icmp open socket: Operation not permitted


原因是 ping 需要 suid, 那麼開權限給 user 

sudo chmod u+s `which ping`




追蹤者