CenterOS磁盘分区调整,删除,合并分区

目的:将/u2和/u3分区删除后,合并为/u4分区。

1、先取消/u2和/u3分区的挂载
[[email protected] ~]# umount /u2
[[email protected] ~]# umount /u3
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda5 22G 2.0G 19G 10% /
tmpfs 911M 0 911M 0% /dev/shm
/dev/sda1 194M 32M 153M 18% /boot
/dev/sda3 2.0G 35M 1.8G 2% /u1

2、进入fdisk /dev/sda磁盘删除分区格式
[[email protected] ~]# fdisk /dev/sda

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/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0007403b

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 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 536 2048000 83 Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4 536 3917 27155456 5 Extended
/dev/sda5 1046 3917 23056384 83 Linux
/dev/sda6 536 736 1610064+ 83 Linux
/dev/sda7 737 1045 2482011 83 Linux #这两个虽然取消挂载,但是分区要进一步删除。

Partition table entries are not in disk order

Command (m for help): d
Partition number (1-7): 7 #这个标号是要删除的磁盘编号

Command (m for help): p #建议删一次分区,用一次p选项,避免删错

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0007403b

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 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 536 2048000 83 Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4 536 3917 27155456 5 Extended
/dev/sda5 1046 3917 23056384 83 Linux
/dev/sda6 536 736 1610064+ 83 Linux

Partition table entries are not in disk order

Command (m for help): d
Partition number (1-6): 6 #这个标号是要删除的磁盘编号

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0007403b

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 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 536 2048000 83 Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4 536 3917 27155456 5 Extended
/dev/sda5 1046 3917 23056384 83 Linux
#/dev/sda6和/dev/sda7被彻底删除
Command (m for help): w #之前删除分区后,要记得用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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
[[email protected] ~]#

3、进入/etc/fstab将/u2和/u3的启动项挂载删除掉,避免启动的时候挂载失败,造成系统无法正常启动。

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

/etc/fstab

Created by anaconda on Mon Jan 29 15:17:42 2018

#

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=ec79fc9b-37a3-4569-a6d2-e4f3ddbf9564 / ext4 defaults 1 1
UUID=ddfde3c8-d179-4773-b506-9b8d37c869b8 /boot ext4 defaults 1 2
UUID=2f8686bb-d6e9-4b9d-846a-4459d5359b28 /u1 ext4 defaults 1 2
#UUID=e9f9034f-3d55-4c71-b7fc-ac6811bfc5bc /u2 ext4 defaults 1 2
#UUID=7d32325e-b21c-42b6-9766-20600527113f /u3 ext4 defaults 1 2

UUID=f84bdd88-71b8-4143-aec4-a9ceae8d8a0a 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

4、出现以上的“WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.”提示是无关紧要的,直接重启服务器就可以正式生效了。
[[email protected] ~]# reboot

Broadcast message from [email protected]
(/dev/pts/0) at 9:17 ...
The system is going down for reboot NOW!

5、重启完成后建立/u4目录
[[email protected] ~]# mkdir -p /u4

6、将之前的/u2和/u3的清空下来的空间用fdisk建立新的分区。
[[email protected] ~]# fdisk /dev/sda

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/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0007403b

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 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 536 2048000 83 Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4 536 3917 27155456 5 Extended
/dev/sda5 1046 3917 23056384 83 Linux
#可以看出当前分区只到/dev/sda5
Command (m for help): n #新建分区
First cylinder (536-3917, default 536): #由于要合并,直接回车即可,起始为默认
Using default value 536
Last cylinder, +cylinders or +size{K,M,G} (536-1045, default 1045): #由于要合并,直接回车即可,结束位为默认
Using default value 1045

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0007403b

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 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 536 2048000 83 Linux
Partition 3 does not end on cylinder boundary.
/dev/sda4 536 3917 27155456 5 Extended
/dev/sda5 1046 3917 23056384 83 Linux
/dev/sda6 536 1045 4092107 83 Linux #可以看到/dev/sda6为新建分区

Partition table entries are not in disk order

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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
#以上这步骤完成后,建议重启不然无法格式化/dev/sda6因为识别不到。

7、格式化新建的/dev/sda6分区
[[email protected] ~]# mkfs.ext4 /dev/sda6
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
256000 inodes, 1023026 blocks
51151 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1048576000
32 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

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

7、将/dev/sda6分区挂载到u4分区上
[[email protected] ~]# mount /dev/sda6 /u4
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda5 22G 2.0G 19G 10% /
tmpfs 911M 0 911M 0% /dev/shm
/dev/sda1 194M 32M 153M 18% /boot
/dev/sda3 2.0G 35M 1.8G 2% /u1
/dev/sda6 3.9G 72M 3.6G 2% /u4

8、将/u4分区写入到/etc/fstab启动项里
[[email protected] ~]# cd /dev/disk/by-uuid/ #先找出/dev/sda6对应的uuid标示号
[[email protected] by-uuid]# ll
总用量 0
lrwxrwxrwx. 1 root root 10 1月 30 09:42 2f8686bb-d6e9-4b9d-846a-4459d5359b28 -> ../../sda3
lrwxrwxrwx. 1 root root 10 1月 30 09:46 54013a0e-e30a-4e06-b651-e77dd3d0704d -> ../../sda6
lrwxrwxrwx. 1 root root 10 1月 30 09:42 ddfde3c8-d179-4773-b506-9b8d37c869b8 -> ../../sda1
lrwxrwxrwx. 1 root root 10 1月 30 09:42 ec79fc9b-37a3-4569-a6d2-e4f3ddbf9564 -> ../../sda5
lrwxrwxrwx. 1 root root 10 1月 30 2018 f84bdd88-71b8-4143-aec4-a9ceae8d8a0a -> ../../sda2

[[email protected] by-uuid]# vi /etc/fstab
#

/etc/fstab

Created by anaconda on Mon Jan 29 15:17:42 2018

#

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=ec79fc9b-37a3-4569-a6d2-e4f3ddbf9564 / ext4 defaults 1 1
UUID=ddfde3c8-d179-4773-b506-9b8d37c869b8 /boot ext4 defaults 1 2
UUID=2f8686bb-d6e9-4b9d-846a-4459d5359b28 /u1 ext4 defaults 1 2
#UUID=e9f9034f-3d55-4c71-b7fc-ac6811bfc5bc /u2 ext4 defaults 1 2
#UUID=7d32325e-b21c-42b6-9766-20600527113f /u3 ext4 defaults 1 2
UUID=54013a0e-e30a-4e06-b651-e77dd3d0704d /u4 ext4 defaults 1 2
#新增这个条目,UUID抄cd /dev/disk/by-uuid/目录里的。

UUID=f84bdd88-71b8-4143-aec4-a9ceae8d8a0a 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

至此完成了所有的步骤,重启后也不怕丢失了。

原文地址:http://blog.51cto.com/259845/2066701

时间: 2024-07-30 19:46:33

CenterOS磁盘分区调整,删除,合并分区的相关文章

Linux合并分区详细步骤

需求:将home分区合并到根分区中. -----------合并分区---------- umount /home mkdir /home1 mount  /dev/mapper/VolGroup-lv_home /home1 cd /home1 mv * /home cd .. umount /home1 lvremove  /dev/mapper/VolGroup-lv_home rm -rf /home1 vgs lvextend -L +491.65G /dev/mapper/VolGr

20、磁盘管理—linux磁盘管理详解(分区)

linux磁盘管理 添加磁盘步骤: fdisk 管理磁盘分区 格式化文件系统. 设备挂载 开机自动挂载 UUID挂载 取消挂载点 Parted(gpt大于2G分区) 查看文件系统的使用情况. df 查看挂载信息与磁盘使用量 du 查看使用量 查看分区状况lsblk 查看设备信息blkid linux磁盘管理 当全新安装了一块新的硬盘设备后,为了更充分.安全的利用硬盘空间首先要进行磁盘的分区,然后格式化,最后挂载使用. 添加磁盘步骤: 添加设备->分区->格式化(创建文件系统)-> [起名

MDT 2013 从入门到精通之磁盘分区调整

Task任务创建完成后,我们肯定对Task Sequence选项中涉及到的诸多个性化设置很感兴趣,本章中暂不做细化界面介绍.为了后续部署操作的顺利进行,我们需要对部署系统进行磁盘分区及分区格式化调整.接下来我们就来了解一下对应设置的相关配置步骤及注意事项: 生产环境中,我们一般有两种需求:一种是全盘格式化进行全新安装:另一种是只格式化系统盘数据,保留其他分区资料信息等:其实不管哪种部署方式我们都需要关注数据的安全性,生产环境中永远把数据安全放在第一位才是王道(注:在很多公司做此类项目的时候总有那

磁盘设备的发现、分区原理、普通分区、swap分区、设备加密及加密的删除

1.设备的发现 1.设备的发现 fdisk  -l                                                ##扫瞄磁盘上的分区信息 cat /proc/partitions                                ##系统识别到的设备 blkid                                                    ##系统中被格式化设备 2.磁盘分区的原理 mbr                   

Ubuntu用gparted合并分区

转载:http://www.linuxidc.com/Linux/2010-06/26689.htm 在使用Linux的过程中,随着软件的安装和数据的膨胀,有时候会发现划分给Linux分区需要进行调整.如果直接使用分区命令fdisk调整分区大小,往往意味着分区数据的丢失.LVM技术可以避免分区数据丢失,但在使用中有许多限制.本文介绍一种使用gparted进行Linux分区调整的方法,它比较适合个人计算机中的硬盘分区调整,同时也可避免数据丢失. gparted是一款免费.开源的Linux下的具有图

Win7秘籍 如何用压缩卷调整不合理分区

日前,中关村在线笔记本论坛做了一项调查,新机器入手后,最让网友头疼的几件事分别为装系统,加内存,硬盘分区和系统打补丁四大难题.而名列首位的就是笔记本硬盘分区不合理,相差悬殊的C盘和D盘空间,让很多菜鸟网友不知所措. •十秒钟急速分区秘籍 有没有一种方法,不用使用虚拟机.PE系统盘,只在系统中就能快速把磁盘空间合理分区了呢?答案是有的,正版Windows7系统下提供了一个压缩卷功能,可以非常简单的将不合理分区进行重新调整,如果速度快的话10秒钟生成一个新的驱动器是不成问题的.下面就让我们一起来体验

学习日志---linux 磁盘与内核关系以及分区

文件系统: 操作系统是如何识别磁盘和分区的: MBR: Master Boot Record, 主引导记录,存放磁盘的信息,包括分区信息,操作系统引导程序,标志符号.一个扇区大小 MBR一共512个字节,下面是这些字节的分配: 512bytes: bootloader: 446bytes: 引导加载器程序,加载操作系统的程序,用来启动操作系统的,例如在开机时可以选择启动哪个操作系统,就是这段的信息 fat: (磁盘分区)文件系统分配表,64bytes, 16bytes引导一个分区, 因此只有四个

linux 硬盘分区,分区,删除分区,格式化,挂载,卸载笔记

Linux 虽然一直都有在玩,但是对硬盘操作确实不是很熟悉今天有空,就整理了下. 1, 创建分区 先查看下是否有磁盘没有分区 [html] view plaincopy fdisk -l 其中第一个框和第二个框,是已经分好区的磁盘,第三个硬盘没有分区. 开始分区 [html] view plaincopy fdisk /dev/sdc 输入m,可以查看有哪些操作 输入p 查看当前硬盘分区,目前没有分区. 输入n新建一个分区,输入p 建立分区,输入分区编号 1 然后会让你设置开始扇区(不知道是否这

Windows xp 下删除ubuntu分区后恢复

1. 发生情形 在windows下的计算机管理中删除了一个ubuntu10.04所在分区,结果所有Linux分区变成一片绿色,变成了可用空间.对分区表进行操作尽量不要用磁盘管理,disk Genius(diskman)非常好用,对分区表进行操作可以预览效果,退出时不保存分区信息就不会更新磁盘分区表.当然你也可以用它的备份分区表的功能. 2. 处理思路 之前安装ubuntu时为了腾出空间也曾经发生删除最后一个磁盘别的分区也跟着消失的问题.原因可能是分区链已经错乱.不过现在要处理的问题是如何找回Li