Linux 使用fdisk添加新分区

Linux系统由于数据累计增长、前期存储规划不合理等诸多因素,出现存储不够用的情况时,此时就需要扩展逻辑分区或添加新的逻辑分区。下面介绍一下通过使用fdsik添加新的逻辑分区。

 

首先使用df命令检查文件系统的磁盘空间占用情况

[root@DB-ONE-SERVER~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-sda3
                       30G  2.4G   26G   9% /
/dev/sda1              99M   23M   71M  25% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm
You have new mail in /var/spool/mail/root

然后使用fdisk -l查看分区表信息

[root@DB-ONE-SERVER~]# fdisk -l
 
 
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        5221    41833260   8e  Linux LVM
 
 
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
Disk /dev/sdb doesn't contain a valid partition table
 
 
Disk /dev/dm-0: 32.3 GB, 32346472448 bytes
255 heads, 63 sectors/track, 3932 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
Disk /dev/dm-0 doesn't contain a valid partition table
 
 
Disk /dev/dm-1: 10.4 GB, 10468982784 bytes
255 heads, 63 sectors/track, 1272 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
Disk /dev/dm-1 doesn't contain a valid partition table

fdisk命令参数介绍

     p、打印分区表。

     n、新建一个新分区。

     d、删除一个分区。

     m、输出菜单

     q、退出不保存。

     w、把分区写进分区表,保存并退出。

[root@DB-ONE-SERVER~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
 
 
 
 
The number of cylinders for this disk is set to 2610.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
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)
 
 
 
 
Command (m for help): p
 
 
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
   Device Boot      Start         End      Blocks   Id  System
 
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 
Using default value 2610
 
 
Command (m for help): p
 
 
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux
 
 
Command (m for help): w
The partition table has been altered!
 
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@DB-ONE-SERVER~]#  fdisk -l /dev/sdb
 
 
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

使用 mkfs.ext4 命令格式化磁盘成格式化成ext4各式的文件系统。

[root@DB-ONE-SERVER~]# mkfs.ext4 /dev/sdb1
mke4fs 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
1310720 inodes, 5241198 blocks
262059 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
 
 
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
 
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune4fs -c or -i to override.

系统启动时自动挂载/dev/sdb1,编辑/etc/fstab文件,指定挂载目录为/u02

[root@DB-ONE-SERVER~]# vi /etc/fstab
 
 
/dev/VolGroup00/sda3    /                       ext3    defaults        1 1
/dev/sdb1               /u02                    ext4    defaults        1 2
LABEL=/boot             /boot                   ext3    defaults        1 2
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/VolGroup00/sda4    swap                    swap    defaults        0 0
~
 
[root@DB-ONE-SERVER~]# cd /
[root@DB-ONE-SERVER/]# mkdir u02
[root@DB-ONE-SERVER/]# mount -a
[root@DB-ONE-SERVER/]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-sda3
                       30G  2.4G   26G   9% /
/dev/sda1              99M   23M   71M  25% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm
/dev/sdb1              20G  172M   19G   1% /u02
[root@DB-ONE-SERVER/]# 

 

下面来看看虚拟上Linux的添加新的逻辑分区的步骤,其实操作是一样的,只是顺带介绍一下虚拟机如何添加硬盘

 
[root@oracle_server ~]# fdisk -l
 
Disk /dev/sda: 584.6 GB, 584646328320 bytes
255 heads, 63 sectors/track, 71079 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       19441   156151808   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2           19441       44937   204796672   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3           44937       57685   102398336   83  Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4           57685       71080   107595584    5  Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5           57685       70433   102398336   83  Linux
/dev/sda6           70433       70949     4144768   82  Linux swap
/dev/sda7           70949       71080     1052288   83  Linux
 
Disk /dev/sdb: 146.1 GB, 146156158976 bytes
2 heads, 24 sectors/track, 5947109 cylinders
Units = cylinders of 48 * 512 = 24576 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               3     5947064   142729472   83  Linux
[root@oracle_server ~]# 

此时需要选择“添加”选项,增加一个磁盘。

如下所示,我们选择“创建新的虚拟磁盘”

容量选择100G, 磁盘置备我们选择“Thin Provison”,表示用多少分配多少,最大分配100G,而不是一开始就分配100G(厚置被延迟置零)

[root@oracle_server ~]# fdisk -l
 
Disk /dev/sda: 584.6 GB, 584646328320 bytes
255 heads, 63 sectors/track, 71079 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       19441   156151808   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2           19441       44937   204796672   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3           44937       57685   102398336   83  Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4           57685       71080   107595584    5  Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5           57685       70433   102398336   83  Linux
/dev/sda6           70433       70949     4144768   82  Linux swap
/dev/sda7           70949       71080     1052288   83  Linux
 
Disk /dev/sdb: 146.1 GB, 146156158976 bytes
2 heads, 24 sectors/track, 5947109 cylinders
Units = cylinders of 48 * 512 = 24576 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               3     5947064   142729472   83  Linux

此时使用fdisk -l 依然看不到添加的磁盘,此时可以通过重启或执行下面命令

[root@oracle_server ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@oracle_server ~]# fdisk -l
 
Disk /dev/sda: 584.6 GB, 584646328320 bytes
255 heads, 63 sectors/track, 71079 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       19441   156151808   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2           19441       44937   204796672   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3           44937       57685   102398336   83  Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4           57685       71080   107595584    5  Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5           57685       70433   102398336   83  Linux
/dev/sda6           70433       70949     4144768   82  Linux swap
/dev/sda7           70949       71080     1052288   83  Linux
 
Disk /dev/sdb: 146.1 GB, 146156158976 bytes
2 heads, 24 sectors/track, 5947109 cylinders
Units = cylinders of 48 * 512 = 24576 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               3     5947064   142729472   83  Linux
 
Disk /dev/sdc: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Disk /dev/sdc doesn't contain a valid partition table

[root@oracle_server ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
 
 
The number of cylinders for this disk is set to 13054.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
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)
 
Command (m for help): p
 
Disk /dev/sdc: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054): 
Using default value 13054
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
 
[root@oracle_server u04]# mkfs.ext3 /dev/sdc1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
13107200 inodes, 26214055 blocks
1310702 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=29360128
800 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872
 
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
 
[root@oracle_server ~]$ more /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/1                /                       ext3    defaults        1 1
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /dev/shm                tmpfs   defaults        0 0
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
LABEL=/tmp              /tmp                    ext3    defaults        1 2
LABEL=/u01              /u01                    ext3    defaults        1 2
LABEL=/u02              /u02                    ext3    defaults        1 2
LABEL=/u03              /u03                    ext3    defaults        1 2
LABEL=SWAP-sda6         swap                    swap    defaults        0 0
/dev/sdb1               /u03/flash_recovery_area        ext3    defaults        1 2
/dev/hda                /media/cdrecorder       auto    pamconsole,exec,noauto,managed 0 0
/dev/fd0                /media/floppy           auto    pamconsole,exec,noauto,managed 0 0
 
vi
 
[oracle@get-orasvr02 ~]$ vi /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/1                /                       ext3    defaults        1 1
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /dev/shm                tmpfs   defaults        0 0
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
LABEL=/tmp              /tmp                    ext3    defaults        1 2
LABEL=/u01              /u01                    ext3    defaults        1 2
LABEL=/u02              /u02                    ext3    defaults        1 2
LABEL=/u03              /u03                    ext3    defaults        1 2
LABEL=SWAP-sda6         swap                    swap    defaults        0 0
/dev/sdb1               /u03/flash_recovery_area        ext3    defaults        1 2
/dev/sdc1               /u04                            ext3    defaults        1 2
/dev/hda                /media/cdrecorder       auto    pamconsole,exec,noauto,managed 0 0
/dev/fd0                /media/floppy           auto    pamconsole,exec,noauto,managed 0 0
 
[root@oracle_server ~]# mkdir /u04
[root@oracle_server ~]# mount -a
 
[root@oracle_server  ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             147G   86G   54G  62% /
/dev/sda7            1012M   34M  927M   4% /tmp
/dev/sda5              97G   73G   19G  80% /u01
/dev/sda3              97G   84G  7.6G  92% /u02
/dev/sda2             193G  133G   51G  73% /u03
/dev/sdb1             134G   74G   54G  59% /u03/flash_recovery_area
/dev/sdc1              99G   93M   94G   1% /u04
时间: 2024-09-20 00:09:02

Linux 使用fdisk添加新分区的相关文章

如何在现有的Linux系统上添加新的磁盘

作为一个系统管理员,我们会有这样的一些需求:作为升级服务器容量的一部分,或者有时出现磁盘故障时更换磁盘,我们需要将新的硬盘配置到现有服务器. 在这篇文章中,我会向你逐步介绍添加新硬盘到现有 RHEL/CentOS 或者 Debian/Ubuntu Linux 系统的步骤. 重要:请注意这篇文章的目的只是告诉你如何创建新的分区,而不包括分区扩展或者其它选项. 我使用 fdisk 工具 完成这些配置. 我已经添加了一块 20GB 容量的硬盘,挂载到了 /data 分区. fdisk 是一个在 Lin

麒麟Linux系统怎么添加新账户

  惠普电脑麒麟Linux系统如何创建账户 1.点击开始-控制面板 2.选择系统中的用户账户 3.点击添加用户,然后在弹出的对话框中输入新创建的用户名称,密码.输入完毕点击确定后新用户即可创建成功.

空闲空间添加新分区

#parted #parted>p #parted>mkpart primary 4411G -1 #quit #partporbe #init 6

Linux下添加新硬盘及分区格式化要点

Linux下添加新硬盘及分区格式化要点 预备知识 在为主机添加硬盘前,首先要了解linux系统下对硬盘和分区的命名方法. 在Linux下对IDE的设备是以hd命名的,第一个ide设备是hda,第二个是hdb.依此类推 一般主板上有两个IDE接口,一共可以安装四个IDE设备.主IDE上的两个设备分别对应hda和hdb,第二个IDE口上的两个设备对应hdc和hdd. 一般硬盘安装在主IDE的主接口上,所以是hda 光驱一般安装在第二个IDE的主接口上,所以是hdc(应为hdb是用来命名主IDE上的从

fdisk添加分区引起的Linux Error: 22: Invalid argument

在Linux服务器(虚拟机)上使用fdisk添加分区.格式化分区后,遇到了Linux Error: 22: Invalid argument错误,操作步骤如下所示 [root@oracle-server ~]# echo "- - -" > /sys/class/scsi_host/host0/scan [root@oracle-server ~]# fdisk -l   Disk /dev/sda: 584.6 GB, 584646328320 bytes 255 heads,

《Linux From Scratch》第二部分:准备构建 第二章:准备新分区- 2.2. 创建新分区

与绝大多数其它操作系统相同,安装 LFS 通常需要专门的分区.构建 LFS 系统比较推荐的方法是使用可用的空分区,或者如果条件允许,最好是在未分区的空间里新建分区. 最小化的系统需要大约 4 GB 的分区,这足以存储所有的源码包及满足编译的需求.但如果要将 LFS 作为主要的 Linux 系统,可能需要安装其它附加的软件,这将需要额外的空间.考虑到了日后所需的空间,一个 10 GB 的分区是比较合理的.LFS 系统本身并不会占用这么多的空间.但满足此要求的大分区将能提供足够大的临时储存空间.编译

linux中fdisk分区命令使用详解

在linux下,使用fdisk对硬盘分区:先删除原有分区,然后创建新的分区 1) 删除分区  代码如下 复制代码 [root@standby root]# fdisk /dev/sdc The number of cylinders for this disk is set to 4425. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause probl

Linux中fdisk分区使用方法

实例解说Linux中fdisk分区使用方法 一.fdisk 的介绍 fdisk - Partition table manipulator for Linux ,译成中文的意思是磁盘分区表操作工具:本人译的不太好,也没有看中文文档:其实就是分区工具. fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统,比如linux .fat32. linux .linux swap .fat16 以及其实类Unix类操作系统的文件系统等:当然我们用fdisk 对磁盘操作分区时,并不是一个

Linux环境中MySQL主从同步--添加新的从库

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://dgd2010.blog.51cto.com/1539422/1689171 当前我认为数据库主从有两大应用价值: 1.从库相当于主库的备份.虽然数据库的主从并不能代替/取代备份,例如错误的数据可能毁掉所有的数据库,但主从也是在一种可读的状态下保持备份的一种实现方式. 2.从库可以缓解主库的压力,能提高性能.由于从库是只读的,因此在读取查询方面,从库可以代替主库,承担一定的压力,