资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

linux扩区命令 linux扩展命令

怎么样扩大linux 分区

这里以Red hat AS4 为例。当磁盘分区发现不够用时,能想道的第一个做法就是增加分区大小。但是一般Linux如果没有采用逻辑卷管理,则动态增加分区大小很困难,一个能想道的办法就是,备份分区文件系统数据,删除分区,然后再重新创建分区,恢复备份的文件系统,这个做法比较玄,可能删除分区后导致系统无法启动。

“只有客户发展了,才有我们的生存与发展!”这是成都创新互联的服务宗旨!把网站当作互联网产品,产品思维更注重全局思维、需求分析和迭代思维,在网站建设中就是为了建设一个不仅审美在线,而且实用性极高的网站。创新互联对做网站、网站制作、网站制作、网站开发、网页设计、网站优化、网络推广、探索永无止境。

第二个做法就是,创建一个新的逻辑分区(当然必须有未使用的磁盘空间能分配),将文件系统从老分区拷贝到新分区,然后修改fstab,使用新分区/文件系统替换老的分区/文件系统

第三种做法是,创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用。

这里采用的是第三种方式:

sdb为第二个SCSI硬盘。

[root@hdp0 hadoop]# /sbin/fdisk /dev/sdb

The number of cylinders for this disk is set to 8942.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdb: 73.5 GB, 73557090304 bytes

255 heads, 63 sectors/track, 8942 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdb1 * 1 130 1044193+ 83 Linux

/dev/sdb2 131 391 2096482+ 82 Linux swap

/dev/sdb3 392 521 1044225 83 Linux

/dev/sdb4 522 8942 67641682+ 5 Extended

/dev/sdb5 522 586 522081 83 Linux

/dev/sdb6 587 651 522081 83 Linux

/dev/sdb7 652 1173 4192933+ 83 Linux

可以看出sdb1,2,3为主分区,sdb4为扩展分区。后面的sdb5,6,7则为逻辑分区。柱面编号(Start,End)是连续的,sdb7只用道了1173,而从扩展分区看最大到8942,也就是说,还有7769个柱面是空闲的,一个柱面大小为8225280,约为8M大小。还剩7769*8225280bytes,约62G未使用。

新增加一个逻辑分区(注:若涉及到主分区和扩展分区,实际情况可能比这个复杂,这里4个主分区(包括扩展分区)都分过了,所以只能分逻辑分区)

Command (m for help): n

First cylinder (1174-8942, default 1174):

Using default value 1174

增加大小为10G

Last cylinder or +size or +sizeM or +sizeK (1174-8942, default 8942): +10240M

增加后看一下,多了一个逻辑分区/dev/sdb8

Command (m for help): p

Disk /dev/sdb: 73.5 GB, 73557090304 bytes

255 heads, 63 sectors/track, 8942 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdb1 * 1 130 1044193+ 83 Linux

/dev/sdb2 131 391 2096482+ 82 Linux swap

/dev/sdb3 392 521 1044225 83 Linux

/dev/sdb4 522 8942 67641682+ 5 Extended

/dev/sdb5 522 586 522081 83 Linux

/dev/sdb6 587 651 522081 83 Linux

/dev/sdb7 652 1173 4192933+ 83 Linux

/dev/sdb8 1174 2419 10008463+ 83 Linux

可以看到,增加了一个sdb8的分区,柱面号从1174到2419.

写入分区表,执行分区操作

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

分区完后,是看不到文件系统的

[root@hdp0 hadoop]# df -m

Filesystem 1M-块 已用 可用 已用% 挂载点

/dev/sdb1 1004 582 372 62% /

none 1014 0 1014 0% /dev/shm

/dev/sdb3 1004 807 147 85% /home

/dev/sdb5 494 11 458 3% /opt

/dev/sdb7 4031 3272 554 86% /usr

/dev/sdb6 494 87 382 19% /var

重启机器

reboot

格式化文件系统

[root@hdp0 hadoop]#/sbin/mkfs.ext3 /dev/sdb8

mount文件系统,/home/develop 为/home下一目录

[root@hdp0 hadoop]#mount /dev/sdb8 /home/develop

查看文件系统,可以看到新建立的分区/文件系统已经挂载上,能够使用了。

[root@hdp0 hadoop]# df -m

Filesystem 1M-块 已用 可用 已用% 挂载点

/dev/sdb1 1004 582 372 62% /

none 1014 0 1014 0% /dev/shm

/dev/sdb3 1004 807 147 85% /home

/dev/sdb5 494 11 458 3% /opt

/dev/sdb7 4031 3272 554 86% /usr

/dev/sdb6 494 87 382 19% /var

/dev/sdb8 9621 54 9079 1% /home/develop

在LINUX系统中,分区与格式化硬盘的命令是什么?

Linux下常用的分区工具:

fdisk/sfdisk:命令行工具,各种版本和环境都能使用,包含在软件包util-linux中

diskdruid:图形化分区工具,只能在安装REDHAT系统时使用。

第一步:fdisk

[root@novice ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 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: 0x00000000

Device Boot Start End Blocks Id System

[root@novice ~]# fdisk /dev/sdb

Command (m for help): #在输入上面的命令后会出现左边的提示,输入m就会得到一个帮助菜单,如下:

Command (m for help): m

Command action

a toggle a bootable flag

b edit bsd disklabel

c toggle the dos compatibility flag

d delete a partition

l list known partition types

m print this menu

n add a new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create a new empty Sun disklabel

t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

#help虽然是英文的,可都很简单,在这里不再解释。

#现在,我们正式开始分区的操作:

Command (m for help): n #新建分区

Command action

e extended

p primary partition (1-4)

#e/p分别对应扩展分区 /主分区;我们先分四个主分区,每个50M;然后再来增加主分区或扩展分区,看会出现怎样的状况,嘿嘿。

p #分区类型为主分区

Partition number (1-4, default 1): 1 #分区号,在这里我们依次选择1、2、3、4

First sector (2048-496127, default 2048): #指定分区的起始扇区,一般默认,按enter键即可。

Last sector, +sectors or +size{K,M,G} (2048-496127, default 496127): +50M #指定分区的终止扇区,根据前面的提示我们可以做出相应的选择+sectors 或 +size{K,M,G}

Command (m for help): p #用p打印出已建好的分区列表

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 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: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

#剩下的三个分区的建立操作同上

#分好四个主分区后的情况如下

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 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: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 309298 25+ 83 Linux

#已经建好四个主分区啦,现在我们来看看如果再建主分区或是扩展分区的话会出现怎样的情况:

Command (m for help): n

You must delete some partition and add an extended partition first

#看到了吧,不能再建分区啦!要再建分区的话必须删除some分区,再新建一个扩展分区才行。

#现在,我们删掉一个主分区,来新建扩展分区

Command (m for help): d #删除分区

Partition number (1-4): 4 #选择要删除分区的分区号,我们选第四个

Command (m for help): p #打印,如下,四个分区变成了三个!

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 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: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

#新建一个扩展分区

#如果在没有建满三个主分的区的情况下建立扩展分区,相关选项会有些不同。

Command (m for help): n

Command action

e extended

p primary partition (1-4)

e

Selected partition 4

First sector (309248-496127, default 309248): #enter,默认

Using default value 309248

Last sector, +sectors or +size{K,M,G} (309248-496127, default 496127): #enter,默认,使用剩余空间

Using default value 496127

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 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: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 496127 93440 5 Extended

#接下来,我们在新建的扩展分区里再新建两个逻辑分区,因为已经有了三个主分区,这里不会再显示是建立逻辑分区还是主分区的提示!

Command (m for help): n

First sector (311296-496127, default 311296): #enter

Using default value 311296

Last sector, +sectors or +size{K,M,G} (311296-496127, default 496127): +50M

Command (m for help): n

First sector (415744-496127, default 415744): #enter

Using default value 415744

Last sector, +sectors or +size{K,M,G} (415744-496127, default 496127): #enter

Using default value 496127

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes

8 heads, 61 sectors/track, 1016 cylinders, total 496128 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: 0x00000000

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 83 Linux

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 496127 93440 5 Extended

/dev/sdb5 311296 413695 51200 83 Linux

/dev/sdb6 415744 496127 40192 83 Linux

#上面的列表,就是我们今天分区的成果啦!接下来保存退出,重启计算机,就可以进行下一步的mkfs操作啦!如果忘记了相关的操作命令,记得按m!!!

Command (m for help): w #保存

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

另:在建好分区后,我们还可以更改相关分区的文件系统类型

#如,我们要把第二个主分区改成Linux下的交换分区,操作如下

Command (m for help): t #更改文件系统类型

Partition number (1-6): 2 #选择第二个分区

Hex code (type L to list codes): L #选择要更改的文件系统编码,可以按L来查看相关编码信息。

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris

1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-

2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-

3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-

............

16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS

17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE

18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto

1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep

1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT

1e Hidden W95 FAT1

Hex code (type L to list codes): 82 #查找到linux swap的编码为82

Changed system type of partition 2 to 82 (Linux swap / Solaris)

Command (m for help): p

..............

Device Boot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 206847 51200 82 Linux swap / Solaris

/dev/sdb3 206848 309247 51200 83 Linux

/dev/sdb4 309248 496127 93440 5 Extended

/dev/sdb5 311296 413695 51200 83 Linux

/dev/sdb6 415744 496127 40192 83 Linux

#最后别忘了保存!如果你须要的话!

#扩展分区不能直接使用,逻辑分区只能建立在扩展分区上!

第二步:mkfs(mkfs时分区的格式最好与fdisk设定的分区格式一致,不然.......)

mkfs支持ext2 ext3 vfa msdos jfs reiserfs等文件系统。

用法1:mkfs -t

例: mkfs -t ext3 /dev/sdb2

用法2:mkfs.

例:mkfs,vfat /dev/sdb3

mke2fs支持ext2/ext3文件系统

用法:mke2fs [-j]

例:mke2fs -j /dev/sdb5

# 更多更具体的用法请参照相关命令的man手册

下面,接着实验:

例一

[root@novice ~]# mkfs -t ext3 /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

12824 inodes, 51200 blocks

2560 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=52428800

7 block groups

8192 blocks per group, 8192 fragments per group

1832 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

第三部:挂载

挂载:mount

例:mount /dev/sdb1 /mnt /sdb1

卸载:umonut

例:umount /dev/sdb1

linux如何对磁盘扩容

利用空余磁盘扩容

1. 首先使用命令fdisk -l 查看磁盘情况,此系统有两块硬盘,/dev/xvda 274.9G,/dev/xvdb 10.7G

Linux系统下用什么命令可以直接扩展磁盘空间

Linux没有什么命令可以直接扩展磁盘空间。

linux下磁盘和目录的概念与WIN不同:比如,分了一个系统分区默认挂载了根(/)目录,根下还有其它目录,比如/user /lib等。如果系统分区不够用,可以再分出分支,把根下其它目录分别挂载出来,例如:

/dev/sda2 29222812 20018256 7739724 73% /

/dev/sda4 3856096800 2802714400 860383796 77% /home

根目录挂载在sda2分区上,/home目录挂载在sda4分区上。/home还在根(/)下,但实际已经不占用sda2分区的空间了。同理也可以把/user /lib这样的分区也分出来,缓解根分区的压力。这样操作的好处是,/home可以作为数据分区,即使系统重装,只要格式化根分区(上例中sda2即可,基本不影响/home),但缺点也有,容易使磁盘分区碎片化,不方便管理。另外,最开始分分区时也是无法预料这个分区最终会使用到多大,慢慢也会有用完的情况(虽然也可以继续把子目录再挂载出来)

于是,还可以使用lvm工具,逻辑卷。这个工具可以动态增加磁盘空间。但这个工具系统默认是不安装的,而且需要先把分区做成逻辑卷后才能使用。具体方法网上可以搜到好多,此处就不赘述了。


网页标题:linux扩区命令 linux扩展命令
转载来于:http://cdkjz.cn/article/dogheop.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220