当前位置: 澳门新濠3559 > 操作系统 > 正文

查看现有分区情况,新加的硬盘需要重启服务器

时间:2019-11-09 19:36来源:操作系统
提示两点: *新加的硬盘需要重启服务器fdisk -l才能看到 *下面操作要用root账户 大概是这样的,查看-分区-格式化-挂载-重启自动挂载 1、加硬盘后重启服务器查看 [root@test199 ~]# fdisk -l 操

提示两点:
*新加的硬盘需要重启服务器fdisk -l才能看到
*下面操作要用root账户
大概是这样的,查看-分区-格式化-挂载-重启自动挂载
1、加硬盘后重启服务器查看
[root@test199 ~]# fdisk -l

操作环境:
[[email protected] ~]# uname -a
Linux bkjia 2.6.32-358.18.1.el6.x86_64#1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
现状分析:
系统有两个硬盘,第一个硬盘107G,“/”分区空间当时分区时只给了7.7G过小,空间马上占完。现在系统有第二个硬盘sdb大小为16GB,希望把sdb的所有空间加入到“/”分区中,是其空间容量从7.7GB变成7.7GB+16GB(约2.4GB)。(当然如果这里只有一个硬盘sda,有很多空间尚未使用可以进行同样的操作)
操作步骤如下:
第一步、查看本机现有分区情况
[[email protected] ~]# df -h
文件系统容量已用可用已用%% 挂载点
/dev/mapper/VolGroup-lv_root
                    7.7G  7.1G 155M  98% /
tmpfs                3.9G  296K 3.9G  1% /dev/shm
/dev/sda1            485M  64M 396M  14% /boot
/dev/sda3              83G  350M  79G  1% /media
第二步、查看本机的磁盘情况
[[email protected] ~]# fdisk -l

CentOS新添加一块硬盘并设置自动挂载到某个盘中

[[email protected] ~]# df -h /*查看现有分区情况*/

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_admin-lv_root 18G 2.0G 16G 12% /

tmpfs 495M 228K 495M 1% /dev/shm

/dev/sda1 485M 35M 425M 8% /boot

[[email protected] ~]# fdisk -l/*查看现有DISK*/

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x0007b51c

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/vg_admin-lv_root: 18.9 GB, 18865979392 bytes

255 heads, 63 sectors/track, 2293 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: 0x00000000

Disk /dev/mapper/vg_admin-lv_swap: 2080 MB, 2080374784 bytes

255 heads, 63 sectors/track, 252 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: 0x00000000

  [[email protected] ~]# fdisk /dev/sdb/*打开fdisk分区工具对磁盘分区,如果默认一个分区,也可以跨过此步奏*/

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building anewDOS disklabel with disk identifier 0x264c68f0.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

  Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

  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):m

Command action

a toggle a bootable flag

b editbsddisklabel

c toggle the dos compatibilityflag

d delete a partition

l list known partition types

m print this menu

nadda new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create anewempty 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)

  Command (m for help):n

Command action

e extended

p primary partition (1-4)

e

Partition number (1-4):1

First cylinder (1-416101, default 1):

Using default value 1

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

Using default value 416101

  Command (m for help):w

The partition table has been altered!

  Calling ioctl() to re-read partition table.

Syncing disks.

[[email protected] ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x0007b51c

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x26128f57

Device Boot Start End Blocks Id System

Disk /dev/mapper/vg_admin-lv_root: 18.9 GB, 18865979392 bytes

255 heads, 63 sectors/track, 2293 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: 0x00000000

Disk /dev/mapper/vg_admin-lv_swap: 2080 MB, 2080374784 bytes

255 heads, 63 sectors/track, 252 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: 0x00000000

[[email protected] ~]# mkfs -t ext4 -c /dev/sdb/*格式化磁盘分区*/

mke2fs 1.41.12 (17-May-2010)

/dev/sdb is entire device, not just one partition!

Proceed anyway? (y,n) y

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5242880 blocks

262144 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000

Checking for bad blocks (read-only test): done

Writing inode tables: done

Creating journal (32768 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.

[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_admin-lv_root 18G 2.0G 16G 12% /

tmpfs 495M 224K 495M 1% /dev/shm

/dev/sda1 485M 35M 425M 8% /boot

[[email protected] ~]# mount /dev/sdb /home/admin/storage20/ /*挂载/dev/sdb到/home/admin/storage20/*/
[[email protected] ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_admin-lv_root 18G 2.0G 16G 12% /

tmpfs 495M 224K 495M 1% /dev/shm

/dev/sda1 485M 35M 425M 8% /boot

/dev/sdb 20G 172M 19G 1% /home/admin/storage20

[[email protected] ~]# vi /etc/fstab

# /etc/fstab

# Created by anaconda on Wed Mar 14 09:30:48 2012

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=a779e5e4-e34a-4a96-b01a-dbc5cc348958 / ext4 defaults 1 1

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

/dev/sdb /home/admin/storage20 ext4 defaults 0 0 /

*重启后/dev/vdb自动挂载到/mnt目录*/

[[email protected] ~]# df -h /*查看现有分区情况*/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_adm...

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 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: 0x00000000

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x000dc0ad

Disk /dev/sdb doesn't contain a valid partition table

 Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          64      512000  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2089  16264192  8e  Linux LVM
/dev/sda3            2090      13054  88076362+  83  Linux

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x000cd039

Disk /dev/mapper/VolGroup-lv_root: 8325 MB,8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 536 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 536 10444 79584256 83 Linux
2、分区
fdisk可以用m命令来看fdisk命令的内部命令;
a:命令指定启动分区;
d:命令删除一个存在的分区;
l:命令显示分区ID号的列表;
m:查看fdisk命令帮助;
n:命令创建一个新分区;
p:命令显示分区列表;
t:命令修改分区的类型ID号;
w:命令是将对分区表的修改存盘让它发生作用。

 

[root@test199 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x515ae162.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Disk /dev/mapper/VolGroup-lv_swap: 8325 MB,8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
注意:此时还没有在EXSI5.0中添加第二块硬盘
[[email protected] ~]#
第三步、添加第二块硬盘

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

查看此时系统磁盘情况
[email protected] ~]# fdisk -l

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').

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x000dc0ad

Command (m for help): n
Command action
e extended //输入e为创建扩展分区
p primary partition (1-4) //输入p为创建逻辑分区
p
Partition number (1-4): 1 //在这里输入l,就进入划分逻辑分区阶段了
First cylinder (1-26108, default 1): //注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-26108, default 26108): 我这直接回车了全部用上。注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ;
Using default value 26108

 Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          64      512000  83  Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2              64        2089  16264192  8e  Linux LVM
/dev/sda3            2090      13054  88076362+  83  Linux

Command (m for help): w //最后输入w回车保存
The partition table has been altered!

Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000

Calling ioctl() to re-read partition table.
Syncing disks.
保存后查看一下
[root@test199 ~]# fdisk -l

 

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 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: 0x515ae162

Disk /dev/mapper/VolGroup-lv_root: 8325 MB,8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 1 26108 209712478+ 83 Linux

 

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x000cd039

Disk /dev/mapper/VolGroup-lv_swap: 8325 MB,8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 536 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 536 10444 79584256 83 Linux
3、格式化
[root@test199 ~]# mkfs.ext3 /dev/sdb1 //注:将/dev/sdb1格式化为ext3类型,确认好,我上面/dev/sdb1是新加的200GB硬盘,这一步直接回车就可以了,格式化完会自动跳出来
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428119 blocks
2621405 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

可以看到我们新添加的硬盘sdb

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[[email protected] ~]#
第四步、对第二块硬盘sdb进行分区

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
4、挂载
--先创建个目录、再挂载到目录上
[root@test199 ~]# mkdir /data
[root@test199 ~]# mount /dev/sdb1 /data
[root@test199 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 75G 21G 51G 29% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sdb1 197G 188M 187G 1% /data
5、重启开机自动挂载,要写到fstab里面(就是最后一行了),否则重启后找不到那个新家的硬盘了
[root@test199 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Apr 16 01:33:57 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f87d8e1f-9a62-4cb8-93a8-a4793465eb23 / ext4 defaults 1 1
UUID=cdb27acf-3bbb-4f03-b20c-cfbc9d8450b9 /boot ext4 defaults 1 2
UUID=63399012-86b0-43e7-8cee-a0ace153dd7e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sdb1 /data ext3 defaults 0 0
澳门新濠3559,至此OK!

[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0xfa4abbdc.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon't be recoverable.

Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)

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): m
Command action
 a  toggle a bootable flag
 b  edit bsd disklabel
 c  toggle the dos compatibilityflag
 d  delete a partition
 l  list known partition types
 m  print this menu
 n  add a new partition
 o  create a new empty DOSpartition table
 p  print the partition table
 q  quit without saving changes
 s  create a new empty Sundisklabel
 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 (expertsonly)

Command (m for help): n
Command action
 e  extended
 p  primary partition (1-4)

Partition number (1-4): 4
First cylinder (1-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-2088, default 2088):
Using default value 2088

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

说明:上面操作对sdb硬盘进行了分区操作,设为sdb4分区了(当然上面建立的主分区可以为1-4中的任意一个,我这里选择的4)。

第五步、对新建立的sdb4分区进行格式

[[email protected] ~]# mkfs.ext4 /dev/sdb4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1048576 inodes, 4192957 blocks
209647 blocks (5.00%) reserved for thesuper user
第一个数据块=0
Maximum filesystem blocks=4294967296
128 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
      32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
      4096000

正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystemaccounting information: done完成

This filesystem will be automaticallychecked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

说明:将sdb4分区格式化为ext4格式,因为CentOS安装是系统的格式ext4,所以这里要注意一下。

第六步、格式后的sdb4分区添加为物理卷
[[email protected] ~]# pvcreate /dev/sdb4
Physical volume "/dev/sdb4" successfully created

更多详情见请继续阅读下一页的精彩内容:

利用LVM增加根分区大小

扩展Fedora 16虚拟机的根分区磁盘容量

Linux根分区扩容

在安装红帽企业版Linux 5之后缩减根分区

Linux查看分区命令和根分区扩容方法

Ubuntu Linux移动根分区

Ubuntu 7.04根分区大小的改变  

  • 1
  • 2
  • 下一页

[[email protected] ~]# uname -a Linux bkjia 2.6.32-358.18.1.el6.x86_64#1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux 现状分析: 系统有两个硬盘...

编辑:操作系统 本文来源:查看现有分区情况,新加的硬盘需要重启服务器

关键词: