parted命令修改及新增分区

parted命令修改及新增分区

fdisk不能直接修改分区起始
root@ubuntu18:~# parted 
在虚拟机中选择U盘
(parted) select /dev/sdb
打印现有分区
(parted) print
Model: Teclast CoolFlash USB3.0 (scsi)
Disk /dev/sdb: 126GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End    Size   Type     File system  Flags
 1      32.8kB  126GB  126GB  primary  ntfs         boot
规划boot分区为fat,rootfs为ext3
  resizepart NUMBER END                    resize partition NUMBER
修改第一个分区大小
(parted) resizepart 1 1GB
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?
Yes/No? Yes
(parted) print
Model: Teclast CoolFlash USB3.0 (scsi)
Disk /dev/sdb: 126GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      32.8kB  1000MB  1000MB  primary  ntfs         boot


 查看帮助,只能修改标记,不能修改分区(文件系统)格式
(parted) help set
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER

        NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the primary partitions number from 1 to 4, logical
        partitions from 5 onwards.
        FLAG is one of: boot, root, swap, hidden, raid, lvm, lba, hp-service, palo, prep, msftres, bios_grub, atvrecv, diag, legacy_boot,
        msftdata, irst, esp
        STATE is one of: on, off
再创建另外一个分区
(parted) help mkpart
  mkpart PART-TYPE [FS-TYPE] START END     make a partition

        PART-TYPE is one of: primary, logical, extended
        FS-TYPE is one of: zfs, btrfs, nilfs2, ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, swsusp, linux-swap(v1),
        linux-swap(v0), ntfs, reiserfs, freebsd-ufs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1,
        amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0, linux-swap, linux-swap(new), linux-swap(old)
        START and END are disk locations, such as 4GB or 10%.  Negative values count from the end of the disk.  For example, -1s specifies
        exactly the last sector.

        'mkpart' makes a partition without creating a new file system on the partition.  FS-TYPE may be specified to set an appropriate
        partition ID.
(parted) mkpart primary ext3 1001MB -1s
(parted) print
Model: Teclast CoolFlash USB3.0 (scsi)
Disk /dev/sdb: 126GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      32.8kB  1000MB  1000MB  primary  ntfs         boot
 2      1001MB  126GB   125GB   primary  ext3         lba

(parted) quit  退出就直接保存分区表了。
Information: You may need to update /etc/fstab.
用fdisk验证分区表已生效
root@ubuntu18:~# fdisk -l /dev/sdb
Disk /dev/sdb: 117.2 GiB, 125829120000 bytes, 245760000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00737281

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sdb1  *         64   1953125   1953062 953.7M  7 HPFS/NTFS/exFAT
/dev/sdb2       1955840 245759999 243804160 116.3G 83 Linux
格式化2个分区
root@ubuntu18:~# mkfs.fat /dev/sdb1
mkfs.fat 4.1 (2017-01-24)
格式化之后,fdisk查看Type不会变化
root@ubuntu18:~# mkfs.ext3 /dev/sdb2
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 30475520 4k blocks and 7626752 inodes
Filesystem UUID: 0ba05cdb-f604-4ef7-b76f-660412a152e9
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information:
这个格式化特别慢,在虚拟机下拔了几次U盘,最终在windows下用diskGenius完成格式化,也差点拔U盘。
测试挂载正常
root@ubuntu18:~# mkdir /mnt/rootfs /mnt/boot
root@ubuntu18:~# mount /dev/sdb1 /mnt/boot
root@ubuntu18:~# mount /dev/sdb2 /mnt/rootfs
root@ubuntu18:~#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值