parted命令修改及新增分割槽

2021-10-22 08:50:43 字數 4357 閱讀 6850

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

setset 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.

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:~#

分割槽命令Parted詳解

三 例項 通常劃分分割槽工具我們用的比較多是fdisk命令,但是現在由於磁碟越來越廉價,而且磁碟空間越來越大。而fdisk工具他對分割槽是有大小限制的,它只能劃分小於2t的磁碟。現在的磁碟空間已經遠遠大於2t,有兩個方法來解決這個問題 其一是通過卷管理來實現,其二就是通過parted工具來實現對2t...

Linux命令 parted分割槽命令

parted是乙個比fdisk更高階的工具,它支援多種分割槽 式,包括ms dos和gpt。它允許使用者建立,刪除,調整大小,縮小,移動和複製分割槽,重新組織磁碟使用,以及將資料複製到新硬碟,但在縮小分割槽時它沒有按預期工作,我大部分時間都得到了錯誤,所以我建議使用者不要縮小分割槽,gparted是...

oracle新增分割槽

create table test msg id varchar2 16 result integer,ts varchar2 17 ts time timestamp 6 insert time date partition by range ts time partition p20180110...