作者归档:yangyouji

[树莓派扩容]Extend root filesystem using CLI parted & resize2fs

by tedsluis » Tue May 28, 2013 6:28 am

I opened this new topic to answer cclauss his question, posted in the “Pidora 18 (Raspberry Pi Fedora Remix) Release” topic:http://www.raspberrypi.org/phpBB3/viewtopic.php?p=358244#p358244:

cclauss wrote:In Pidora, is there a headless mode way to expand the rootfs to take up the entire SD card without doing remote Xwindows into the Pi?

‘Parted’ runs on the command line but I don’t know how to expand the rootfs with it.

You could login using headless mode (headless mode means that you don’t have a display connect and you login with ssh from any other system) and use these steps to expand your root partition and file system on a Raspberry Pi running Pedora (fedora remix):
– backup your system in case of a misstake!
– use “fdisk /dev/mmcblk0” to view your partitions.
– use “parted” to delete the partition and then recreate it but with a larger size. (don’t worry, the data will remain)
– reboot to activate the partition changes.
– use “resize2fs /dev/mmclk0p2” to enlarge the root file system.
– use e2fsck -f /dev/mmcblk0p2 to perform a file system check.
– use “df -h” to check results.

Before you extend your root partition and filesystem you should know how big your rootfs is and how much space is available:

CODE: SELECT ALL
[root@raspi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.6G  1.5G   53M  97% /
/dev/mmcblk0p1   50M   18M   33M  35% /boot
[root@raspi ~]#

Determine the storage devices:

CODE: SELECT ALL
[root@raspi ~]# ll /dev/mm*
brw-rw---- 1 root disk 179, 0 Jun  3 13:22 /dev/mmcblk0
brw-rw---- 1 root disk 179, 1 Jun  3 13:21 /dev/mmcblk0p1
brw-rw---- 1 root disk 179, 2 Jun  3 13:21 /dev/mmcblk0p2
[root@raspi ~]

Check the partition table:

CODE: SELECT ALL
[root@raspi ~] fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.22.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): p

Disk /dev/mmcblk0: 16.0 GB, 16012804096 bytes, 31275008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000622ba

Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      104447       51200    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          104448     3494304     1694928+  83  Linux

Command (m for help): q

[root@raspi ~]#

So the SD card has 31275008 (16GB) sectors and the last one in use is 3494304 (1.6GB).
Print the partition table with “parted”:

CODE: SELECT ALL
[root@raspi ~]# parted /dev/mmcblk0
GNU Parted 3.1
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit chs
(parted) print
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 1946,198,43
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1946,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags:
Number  Start     End        Type     File system  Flags
1      0,32,32   6,127,56   primary  fat16        boot, lba
2      6,127,57  217,130,9  primary  ext4
(parted)

So the disk ends at 1946,198,43 cylinder,head,sector and the current root partition ends at 217,130,9.

Note: “fdisk” displays the partition info in 512 bytes blocks and “parted” displays the cylinder,head,sector geometry. Each cylinder is 8225kB.

Now remove the second partition and recreate it larger.

Note: If you have a third swap or other partition that you don’t need any longer, you can remove that one too and use the disk space to extend you.

Removing the partition will only change the partition table and not the data. Creating a new partition will write a new start and end point in the partition table.

Be careful: If you make a misstake, you lose you root partition data:
(Ignore the warning.)

CODE: SELECT ALL
(parted) rm 2
Error: Partition(s) 2 on /dev/mmcblk0 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will
remain in use.  You should reboot now before making further changes.
Ignore/Cancel? i
(parted)

And check whether the partition was removed:

CODE: SELECT ALL
(parted) print
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 1946,198,43
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1946,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags:
Number  Start    End       Type     File system  Flags
1      0,32,32  6,127,56  primary  fat16        boot, lba(parted)

Now the second partition is removed. Do not reboot your system before you have created the new partition! Other wise you lose your root file system.

The new partition must start at the same position where the old root partition did start and it ends where you like. It must have at least the same size as current partition and it may not exceed the end of the disk (in my case 1946,198,43).
(Ignore the warning.)

CODE: SELECT ALL
(parted) mkpart primary 6,127,57  1946,198,43
Error: Partition(s) 2 on /dev/mmcblk0 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will
remain in use.  You should reboot now before making further changes.
Ignore/Cancel? i
(parted)

And check whether the partition was created:

CODE: SELECT ALL
(parted) print
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 1946,198,43
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1946,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags:
Number  Start     End          Type     File system  Flags
1      0,32,32   6,127,56     primary  fat16        boot, lba
2      6,127,57  1946,198,43  primary  ext4(parted) quit
Information: You may need to update /etc/fstab.

[root@raspi ~]#

Be carefull: The kernel is not aware yet of the new partition size. You must reboot your system before you do any thing else.

CODE: SELECT ALL
[root@raspi ~]# reboot

Check the new partition size after the reboot:

CODE: SELECT ALL
[root@raspi ~]# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.22.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): p

Disk /dev/mmcblk0: 16.0 GB, 16012804096 bytes, 31275008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000622ba

Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      104447       51200    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          104448    31275007    15585280   83  Linux

Command (m for help): quit
[root@raspi ~]#

Now the partition is larger, but the root file system has still the old size. Re-size the root filesystem:

CODE: SELECT ALL
[root@raspi ~]# resize2fs /dev/mmcblk0p2
resize2fs 1.42.3 (14-May-2012)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3896320 blocks long.
[root@raspi ~]

The root file system is now extended.
Then check the file system for errors:

CODE: SELECT ALL
[root@raspi ~]# e2fsck -f /dev/mmcblk0p2
e2fsck 1.42.3 (14-May-2012)
/dev/mmcblk0p2 is mounted.
WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***
cause ***SEVERE*** filesystem damage.Do you really want to continue<n>? yes
rootfs: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (3453563, counted=3453559).
Fix<y>? yes

rootfs: ***** FILE SYSTEM WAS MODIFIED *****
rootfs: ***** REBOOT LINUX *****
rootfs: 63775/952000 files (0.1% non-contiguous), 442761/3896320 blocks
[root@raspi ~]#

The file system is free of errors.
Finaly check the file systems size and the available space:

CODE: SELECT ALL
[root@raspi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  1.5G   13G  11% /
/dev/mmcblk0p1   50M   18M   33M  35% /boot
[root@raspi ~]#

It has lots of free space available and it is ready to use.

I hope this helps you.

[转载]CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)

准备篇

1、配置防火墙,开启80端口、3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT #允许80端口通过防火墙
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT #允许3306端口通过防火墙

备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,

正确的应该是添加到默认的22端口这条规则的下面

如下所示:
################################ 添加好之后防火墙规则如下所示################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
#######################################################################################
/etc/init.d/iptables restart #最后重启防火墙使配置生效

2、关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq #保存退出
shutdown -r now #重启系统

3、安装第三方yum源

yum install wget #安装下载工具

1950

wget http://www.atomicorp.com/installers/atomic #下载

1951

sh ./atomic #安装

1953

yum check-update #更新yum源

1954

安装篇

一、安装nginx

yum remove httpd* php* #删除系统自带的软件包

1955

yum install nginx #安装nginx 根据提示输入y进行安装

chkconfig nginx on #设置nginx开机启动

service nginx start #启动nginx

二、安装MySQL

1、安装MySQL

yum install mysql mysql-server #输入Y即可自动安装,直到安装完成

1956

/etc/init.d/mysqld start #启动MySQL

1957

chkconfig mysqld on #设为开机启动

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

2、为root账户设置密码

mysql_secure_installation

#回车,根据提示输入Y,输入2次密码,回车,根据提示一路输入Y,最后出现:Thanks for using MySQL!

1958

1959

MySql密码设置完成,重新启动 MySQL:

/etc/init.d/mysqld restart #重启

/etc/init.d/mysqld stop #停止

/etc/init.d/mysqld start #启动

三、安装PHP5

1、安装PHP5

1960

yum install php php-fpm #根据提示输入Y直到安装完成

2、安装PHP组件,使 PHP5 支持 MySQL

1961

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt

#这里选择以上安装包进行安装,根据提示输入Y回车

chkconfig php-fpm on #设置php-fpm开机启动

/etc/init.d/php-fpm start #启动php-fpm

配置篇

一、配置nginx支持php
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak#备份原有配置文件
vi /etc/nginx/nginx.conf #编辑
user nginx nginx; #修改nginx运行账号为:nginx组的nginx用户
:wq #保存退出
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #备份原有配置文件
vi /etc/nginx/conf.d/default.conf #编辑

index index.php index.html index.htm; #增加index.php

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
service nginx restart #重启nginx

二、php配置
vi /etc/php.ini #编辑
date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC
disable_functions =

passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,ope

nlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdns

rr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,

posix_getegid,posix_geteuid,posix_getgid,

posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,

posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty,

posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,

posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
expose_php = Off #在432行 禁止显示php版本的信息
magic_quotes_gpc = On #在745行 打开magic_quotes_gpc来防止SQL注入
short_open_tag = ON #在229行支持php短标签
open_basedir = .:/tmp/ #在380行 设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/
:wq! #保存退出

三、配置php-fpm
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #备份原有配置文件
vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
:wq #保存退出

测试篇

cd /usr/share/nginx/html

vi index.php #添加以下代码
<?php
phpinfo();
?>

:wq! #保存退出

chown nginx.nginx /usr/share/nginx/html -R #设置权限

chmod 775 /usr/share/nginx/html -R #设置可编辑运行权限(#添加)

service nginx restart #重启nginx

service php-fpm restart #重启php-fpm

1962

在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!

说明lnmp配置成功!

1963

 

至此,CnetOS 6.4安装配置LNMP(Nginx+PHP+MySQL)教程完成。

谁是民国最会说理的人

本文看点

1、一个人愿意说理,那他在心理上一定是把自己和对方平等对待的

2、现实之中,喜谈滥用宏大概念的人,最大的毛病不是愚蠢,而是懒。还有一个原因,是智商不够

3、经得起时间考验的,往往是看似“浅薄”的常识
作者:羽戈

关于胡适先生,我有一个偏见,今人读胡适的文章,首先需要注意的不是他说出了什么道理,而在于他怎么说理,换言之,其说理的方式、逻辑、风度等,高于说理本身。

那么,胡适怎么说理呢?谈论这个问题之前,我们必须明确一点:什么是说理。比定义更便捷的方法,是将说理与我们熟知的宣传做一对比:宣传是一种单向的行为,说理则是一种双向的行为,“兼顾信息发送者和接受者双方的交流需要”;宣传居高临下,说理则平等相待;宣传往往为达目的而不择手段,可能会扭曲、阉割、抹杀真相,说理则必须遵守真实原则;宣传往往不容受众发问,说服则必须容许、鼓励对方发问;宣传充满了强制性,说理则“释放一种理解、尊重、不轻慢对方的善意,让彼此变得温和而有理性”。(见徐贲《明亮的对话:公共说理十八讲》,中信出版社2014年1月第一版,第23页)

继续阅读