linux原有的文件系统扩展,原来linux不用LVM也能扩展文件系统

以前总以为UNIX/LINUX使用了lvm才能扩展或缩小卷和文件系统,今天才发现我错了:即使没有lvm,linux也能扩展卷和及其相应的文件系统而不会丢失原有数据。

以下是测试步骤,记录备查。

1、系统是redhat linux 6

[root@localhost ku]# uname -r

2.6.32-131.0.15.el6.x86_64

[root@localhost ku]# more /etc/redhat-release

Red Hat Enterprise Linux Server release 6.1 (Santiago)

[root@localhost ku]#

2、创建/dev/sdb1及其文件系统,创建文本文件

[root@localhost ku]# echo welcome to redhat world > ricky

[root@localhost ku]# more ricky

welcome to redhat world

3、目前/dev/sdb1对应的文件系统/ku为1.2G

[root@localhost ku]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

16G  3.7G   11G  25% /

tmpfs                 613M   88K  613M   1% /dev/shm

/dev/sda1             485M   32M  428M   7% /boot

/dev/sdb1             1.2G   34M  1.1G   3% /ku

4、卸载/ku

[root@localhost ku]# cd /

[root@localhost /]# umount /ku

[root@localhost /]#

5、用fdisk命令删除/dev/sdb1分区,然后重新创建/dev/sdb1分区,并指定大小为4G

[root@localhost /]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x54f7c6df

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         393     3156741   83  Linux

Command (m for help): d

Selected partition 1

Command (m for help): n

Command action

e   extended

p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-652, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +4G

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost /]#

6、fdisk -l /dev/sdb输出可以看出,cylinder已经由393扩为523

[root@localhost /]# fdisk -l /dev/sdb

Disk /dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x54f7c6df

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         523     4200966   83  Linux

7、先check文件系统

[root@localhost /]# e2fsck -f /dev/sdb1

e2fsck 1.41.12 (17-May-2010)

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

/dev/sdb1: 12/73760 files (0.0% non-contiguous), 13234/307200 blocks

8、将文件系统resize为2G

[root@localhost /]# resize2fs /dev/sdb1 2G

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on /dev/sdb1 to 524288 (4k) blocks.

The filesystem on /dev/sdb1 is now 524288 blocks long.

[root@localhost /]# mount /dev/sdb1 /ku

[root@localhost /]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

16G  3.7G   11G  25% /

tmpfs                 613M   88K  613M   1% /dev/shm

/dev/sda1             485M   32M  428M   7% /boot

/dev/sdb1             2.0G   34M  1.9G   2% /ku

[root@localhost /]#

9、检查扩容前的文件是否正确无损

[root@localhost /]# cd /ku

[root@localhost ku]# more ricky

welcome to redhat world

[root@localhost ku]#

10、当然也可以在线扩展文件系统

[root@localhost ku]# resize2fs /dev/sdb1 2500M

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/sdb1 is mounted on /ku; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 1

Performing an on-line resize of /dev/sdb1 to 640000 (4k) blocks.

The filesystem on /dev/sdb1 is now 640000 blocks long.

[root@localhost ku]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

16G  3.7G   11G  25% /

tmpfs                 613M   88K  613M   1% /dev/shm

/dev/sda1             485M   32M  428M   7% /boot

/dev/sdb1             2.5G   34M  2.3G   2% /ku

[root@localhost ku]#

11、但是不可以在线缩小;要缩小文件系统必须先卸载文件系统

[root@localhost ku]# resize2fs /dev/sdb1 1G

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/sdb1 is mounted on /ku; on-line resizing required

On-line shrinking from 640000 to 262144 not supported.

[root@localhost ku]# cd /

[root@localhost /]# umount /ku

[root@localhost /]# resize2fs /dev/sdb1 1G

resize2fs 1.41.12 (17-May-2010)

Please run 'e2fsck -f /dev/sdb1' first.

[root@localhost /]# e2fsck -f /dev/sdb1

e2fsck 1.41.12 (17-May-2010)

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

/dev/sdb1: 12/147520 files (0.0% non-contiguous), 17864/640000 blocks

[root@localhost /]# resize2fs /dev/sdb1 1G

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on /dev/sdb1 to 262144 (4k) blocks.

The filesystem on /dev/sdb1 is now 262144 blocks long.

[root@localhost /]# mount /dev/sdb1 /ku

[root@localhost /]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

16G  3.7G   11G  25% /

tmpfs                 613M   88K  613M   1% /dev/shm

/dev/sda1             485M   32M  428M   7% /boot

/dev/sdb1            1010M   34M  939M   4% /ku

12、当然,你不能将文件系统扩展为比它的逻辑卷大

[root@localhost /]# resize2fs /dev/sdb1 5G

resize2fs 1.41.12 (17-May-2010)

The containing partition (or device) is only 1050241 (4k) blocks.

You requested a new size of 1310720 blocks.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/329026.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

当当网上书店购物车——源码

关于当当网的所有图片资源都已上传&#xff0c;下载地址&#xff1a;当当网资料&#xff0c;点击下载即可&#xff0c;下面上html代码&#xff1a; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml…

Java NIO系列教程(二) Channel

转载自 Java NIO系列教程&#xff08;二&#xff09; Channel译文链接 作者&#xff1a;Jakob Jenkov 译者&#xff1a;airu 校对&#xff1a;丁一 Java NIO的通道类似流&#xff0c;但又有些不同&#xff1a; 既可以从通道中读取数据&#xff0c;又可以写数据到通…

linux写入二进制文件内容,linux – 从管道读取数据并写入标准输出,中间延迟.必须处理二进制文件...

我现在已经尝试了大约一个小时来找到解决这个问题的优雅方案.我的目标基本上是编写带宽控制管道命令,我可以在各种情况下重复使用(不仅仅是网络传输,我知道scp -l 1234).我想做的是&#xff1a;>延迟X秒.>从管道读取Y量(或者如果没有足够的话,小于Y).>将读取数据写入标…

ASP.NET Core 发布至Linux生产环境 Ubuntu 系统

ASP.NET Core 发布至Linux生产环境 Ubuntu 系统&#xff0c;之前跟大家讲解了 dotnet publish 发布&#xff0c;而没有将整个系统串起来。 今天就跟大家综合的讲一下ASP.NET Core发布至Linux生产环境。 开发及发布环境&#xff1a;WIN10 x64 生产Linux环境&#xff1a;Ubuntu …

Java NIO系列教程(三) Buffer

转载自 Java NIO系列教程&#xff08;三&#xff09; Buffer原文链接 作者&#xff1a;Jakob Jenkov 译者&#xff1a;airu 校对&#xff1a;丁一 Java NIO中的Buffer用于和NIO通道进行交互。如你所知&#xff0c;数据是从通道读入缓冲区&#xff0c;从缓冲区写入…

Linux程序之触摸,linux 触摸屏驱动编写

早在诺基亚手机还比较流行的时候&#xff0c;那时候触摸屏用的还不多。但是随着触摸屏手机、即智能手机的流行&#xff0c;触摸屏基本成了手机的标配。所以&#xff0c;今天可以看看触摸屏驱动在linux上是如何进行的。1、驱动目录drivers/input2、看看这个目录的Makefile如何设…

跨站请求伪造(CSRF/XSRF)

简介 CSRF&#xff08;Cross-site request forgery跨站请求伪造&#xff0c;也被称为“One Click Attack”或者Session Riding&#xff0c;通常缩写为CSRF或者XSRF&#xff0c;是一种对网站的恶意利用。尽管听起来像跨站脚本&#xff08;XSS&#xff09;&#xff0c;但它与XSS非…

Java NIO系列教程(四) Scatter/Gather

转载自 Java NIO系列教程&#xff08;四&#xff09; Scatter/Gather译文地址 作者&#xff1a;Jakob Jenkov 译者&#xff1a;郭蕾 Java NIO开始支持scatter/gather&#xff0c;scatter/gather用于描述从Channel&#xff08;译者注&#xff1a;Channel在中文经常翻译为…

Linux获取本机hostname函数,Linux下获得主机与域名-gethostbyname和gethostbyaddr

1.数据结构hostent和servent:struct hostent{char *h_name;/* official domain name of host */char **h_aliases;/* null-terminated array of domain names */int h_addrtype;/* host address type (AF_INET) */int h_length;/* length of an address, in bytes */char **h_a…

ASP.NET Core Docker部署

前言 在前面文章中&#xff0c;介绍了 ASP.NET Core在 macOS&#xff0c;Linux 上基于Nginx和Jexus的发布和部署&#xff0c;本篇文章主要是如何在Docker容器中运行ASP.NET Core应用程序。 Asp.Net Core 发布和部署&#xff08; MacOS Linux Nginx &#xff09; Asp.Net Core…

Java NIO系列教程(五) 通道之间的数据传输

转载自 Java NIO系列教程&#xff08;五&#xff09; 通道之间的数据传输译文地址 作者&#xff1a;Jakob Jenkov 译者&#xff1a;郭蕾 校对&#xff1a;周泰 在Java NIO中&#xff0c;如果两个通道中有一个是FileChannel&#xff0c;那你可以直接将数据从一个chan…

linux下单点故障的软件,KeepAlived防止单点故障

负载均衡器里面&#xff0c;HAProxy比较出名了&#xff0c;但是如果只用一台HAProxy,则会出现单点故障。这个时候&#xff0c;该KeepAlived出马了。环境介绍OS: Ubuntu 12.04虚拟IP: 192.168.56.2KeepAlived HaProxy : 192.168.56.101 (master)KeepAlived HaProxy : 192.168.…

当当网上书店购物车——JS源码

$(function($){//根据您挑选的商品&#xff0c;当当为您推荐部分的显示和隐藏$("#shopping_commend_arrow").click(function(){if($("#shopping_commend_sort").css("display")"none"){$(this).attr("src","images/sho…

开放重定向(Open Redirection)

简介 那些通过请求&#xff08;如查询字符串和表单数据&#xff09;指定重定向URL的Web程序可能会被篡改&#xff0c;而把用户重定向到外部的恶意URL。这种篡改就被称为开发重定向攻击。 场景分析 假设有一个正规网站http://nerddinner.com/&#xff0c;还有一个恶意网站或钓鱼…

linux ssh密钥对,Mac使用ssh密钥登录Linux

ssh登录Linux通常有两种方法&#xff1a;用户名密码登录、用户名密钥登录&#xff1b;使用用户名密码登录每次都要输入密码&#xff0c;相当麻烦&#xff0c;而使用用户名密钥登录则可以避免这个问题。创建密钥对文件打开本地终端&#xff0c;执行 ssh-keygen 命令创建密钥对&a…

ASP.NET Core quot;完整发布,自带运行时quot; 到jexus

一、阅读前须知 1.使用 jexus整合asp.net core的优点&#xff1a; 1)支持多站点&#xff0c;同一端口可以同时支持任何多的asp.net core应用程序&#xff1b; 2)应用程序启动、停止、重启与站点的启动、停止、重启等操作一致&#xff0c;无需手工管理asp.net core应用程序…

当当网头部和尾部——源码

头部&#xff1a; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns"http://www.w3.org/1999/xhtml"> <head><meta http-equiv&…

linux 文档操作,Linux学习之文档操作

8种机械键盘轴体对比本人程序员&#xff0c;要买一个写代码的键盘&#xff0c;请问红轴和茶轴怎么选&#xff1f;The Linux Command Line 学习翻译mkdirThe mkdir command is used to create directories.It works like this:mkdir命令是用来创建目录的&#xff0c;这样使用&am…

过多提交(Over Posting)

简介 过多提交的内容相对比较简单&#xff0c;因此&#xff0c;我只打算把原文中的一些关键信息翻译一下。原文链接如下&#xff1a; http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-ent…

关于ByteBuffer使用解释

转载自 关于ByteBuffer使用解释之前看过相关的ByteBuffer的使用&#xff0c;但是问题是那时还年轻&#xff0c;所以现在有点老了&#xff0c;因此&#xff0c;忘记了&#xff0c;所以决心看源代码了解一番----故作此篇文章。查看ByteBuffer的API&#xff0c;看的我是一头雾水&…