前面介绍了[使用fdisk命令对linux硬盘进行操作] ,除了fdisk命令,在linux下还有一个功能也非常强大的磁盘管理工具parted。这里继续沿用[使用fdisk命令对linux硬盘进行操作] 中的环境对parted命令进行一些介绍。

parted的基本操作

输入parted命令,进入parted管理界面,如果没有指定硬盘,parted命令会默认选择第一个硬盘为当前操作硬盘。

[root@a ~]# parted
GNU Parted 1.8.1
使用 /dev/hda
Welcome to GNU Parted! Type 'help' to view a list of commands.

输入help查看可进行的操作

(parted) help                                                             
  check NUMBER                             do a simple check on the file system
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
  help [COMMAND]                           prints general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on partititon NUMBER
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system
  move NUMBER START END                    move partition NUMBER
  name NUMBER NAME                         name partition NUMBER as NAME
  print [free|NUMBER|all]                  display the partition table, a partition, or all devices
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resize NUMBER START END                  resize partition NUMBER and its file system
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  displays the current version of GNU Parted and copyright
        information
(parted)  

选择/dev/sdb硬盘进行操作

(parted) select /dev/sdb
使用 /dev/sdb

输入print查看当前磁盘分区情况

(parted) print     

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 3221MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  标志
 1      32.3kB  823MB   822MB   主分区    ext2            
 2      823MB   1028MB  206MB   主分区                    
 3      1028MB  3216MB  2188MB  扩展分区                  
 5      1028MB  1439MB  411MB   逻辑分区                  
 6      1439MB  3216MB  1777MB  逻辑分区  ext3            

parted实验:

这里我们想减少主分区1的容量到500M,然后再将主分区2合并到主分区1中,并且主分区1的数据保持不变

在这个环境中我们已经将/dev/sdb1挂载到/oracle目录上,因此首先要将主分区从系统中卸载

[root@a ~]# umount /oracle/

调整主分区1的容量从822M到500M

(parted) resize 1                                                        
起始点?  [32.3kB]?                                                      
结束点?  [823MB]? 500M                                                  
(parted) 

删除分区2,将分区2的空间加入到分区1。

首先删除分区2

(parted) rm 2

查看删除后的分区情况

(parted) print                                                           

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 3221MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  标志
 1      32.3kB  500MB   500MB   主分区    ext2            
 3      1028MB  3216MB  2188MB  扩展分区                  
 5      1028MB  1439MB  411MB   逻辑分区                  
 6      1439MB  3216MB  1777MB  逻辑分区  ext3            

调整分区1的容量,将分区2释放的空间划入分区1

(parted) resize 1
起始点?  [32.3kB]?                                                      
结束点?  [500MB]? 1027M           

确认分区调整成功

(parted) print                                                           

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 3221MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  标志
 1      32.3kB  1027MB  1027MB  主分区    ext2             
 3      1028MB  3216MB  2188MB  扩展分区                  
 5      1028MB  1439MB  411MB   逻辑分区                  
 6      1439MB  3216MB  1777MB  逻辑分区  ext3            

分享条

转载请注明:

本文转自:http://www.liusuping.com/ubuntu-linux/linux-disk-parted.html

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐