磁盘管理 -- parted
简述
- 划分大小超过 2T 的硬盘, 也适用于小容量硬盘的划分;
- parted [选项] [分区设备]
- 交互式常用命令:
- ?/和老婆?--help : 帮助
- quit/q : 保存退出
- print/p : 打印
- mklabel : 改变硬盘的文件类型
- mkpart : 分区
- rm : 删除某分区, 后面跟分区号, 如 rm 5
parted 分区操作
// 模拟使用 100G 的硬盘使用 parted 命令进行分区 /dev/sdb // 查看新硬盘是否正常; 设备 /dev/sdb parted -l Model: VMware Virtual disk (scsi) Disk /dev/sda: 161GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 211MB 210MB primary ext4 boot 2 211MB 2358MB 2147MB primary linux-swap(v1) 3 2358MB 161GB 159GB primary lvm Model: VMware Virtual disk (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags ... ... // 以下是 逻辑分区 的各种信息 // 使用 parted 进行分区; parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel // 使用 help 查看; New disk label type? gpt // 两次 tab 键可以查看标签类型; Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? y (parted) mkpart // 分区命令 Partition name? []? sdb1 // 分区名称 File system type? [ext2]? ext4 // 分区格式化类型 Start? 1 // 分区开始 End? 20G // 分区结束大小 (parted) mkpart Partition name? []? sdb2 File system type? [ext2]? ext4 Start? 20G End? -1 (parted) p // 打印, 查看分区状态 Model: VMware Virtual disk (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 20.0GB 20.0GB sdb1 2 20.0GB 107GB 87.4GB sdb2 (parted) quit // 保存,退出 Information: You may need to update /etc/fstab.
格式化分区 mkfs.ext4 或者 逻辑分区, 请看 https://www.cnblogs.com/haorong/p/10594841.html
误删分区恢复
// 使用上面建立的 sbd2 分区作为测试分区; // 进行格式化 ext4 mkfs.ext4 /dev/sdb2 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 5332992 inodes, 21331456 blocks 1066572 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 651 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 29 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. // 创建测试挂载点, 并进行挂载, 创建有内容的目录文件 mkdir /tian mount /dev/sdb2 /tian/ mkdir /tian/zong echo 123456 > /tian/zong/hao umount /tian // 卸载挂载 parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p // 打印分区 Model: VMware Virtual disk (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 20.0GB 20.0GB ext4 sdb1 2 20.0GB 107GB 87.4GB ext4 sdb2 (parted) rm 2 // 删除分区 2 (parted) p // 打印分区 Model: VMware Virtual disk (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 20.0GB 20.0GB ext4 sdb1 (parted) rescue // ************************* 救援误删除的分区 *************************** Start? 20G // 开始的大小 End? -1 // 结束时的大小, -1 表示以后全部; Information: A ext4 primary partition was found at 20.0GB -> 107GB. Do you want to add it to the partition table? Yes/No/Cancel? y (parted) p Model: VMware Virtual disk (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 20.0GB 20.0GB ext4 sdb1 2 20.0GB 107GB 87.4GB ext4 (parted) quit Information: You may need to update /etc/fstab. // 挂载恢复的分区, 并查看文件内容, 一样, 表示已恢复 mount /dev/sdb2 /tian/ cat /tian/zong/hao 123456
作者:TZHR —— 世间一散人
出处:https://www.cnblogs.com/haorong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明