回覆回應

parted

最後更新: 2017-05-15

介紹

 

parted 是 Linux 上修改 partion 的利器來.

它可以建立(mkpart), 刪除(rm), 檢查(check) Partion.

而且還可以 更改容量(resize) 及 救回(rescue) 誤刪的 partion !!!

注意: resize partion  唔等於 resize file system !!

目錄

 

 


自助

help <cmd>

help set

 


Tips

Modern HDD starting after about 1TB can use 4kB physical sectors.

Its important for performance that filesystems are aligned on 4kB boundaries, as the drive will do read/modify/write to fake 512B physical sectors.

-a alignment-type

alignment-type:

  • optimal
  • minimal
  • cylinder

用 parted 的 "optimal" 或 "minimal" 就沒有 align 的問題

P.S.

 fdisk -b 4096 /dev/sda

switched off DOS compatibility of fdisk ("c") and changed view mode to sectors ("u")

HardDisk Format 的要求:

Partitions:

Make sure that all partitions start on a multiple of 8 sectors (8x 512B = 4KB)
and that partition sizes are multiples of 8 sectors.

所以:

The first partition starting at sector 63 is done automatically by the partitioning program to optimize read/write performance.

FS:

The file system defaults on most Linux systems are to use blocks of 4KB data.
Typically no specific actions are needed to configure block sizes for WD Advanced Format drives.

 


用法

 

查看本機上所有的 block device 的資訊

parted -l

Model: WDC WD800JB-00FSA0 (ide)
Disk /dev/hda: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      32.3kB  8003MB  8003MB  primary   ext3         boot
 2      8003MB  10.0GB  1999MB  primary   linux-swap
 3      10.0GB  20.0GB  10.0GB  primary   ext3
 4      20.0GB  80.0GB  60.0GB  extended
 5      20.0GB  40.0GB  20.0GB  logical                lvm
 6      40.0GB  60.0GB  20.0GB  logical                lvm
 7      60.0GB  80.0GB  20.0GB  logical   ext3

進入 interactive mode

parted

在 interactive mode 看本看資料

print all = parted -l
print free
print <n>

<n> 是指 print 時的 Number, 如

Model: ST362021 C " " " " " " " (scsi)
Disk /dev/sda: 60.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  30.0GB  30.0GB  primary  ntfs
 2      30.0GB  60.0GB  30.0GB  primary

 


建立 Partation Table

 

mklabel  <label-type>

label-type:

  • loop (raw disk access)
  • msdos
  • gpt

例子: 在 Device 上建立兩個 partiion

選擇要進行操作的 Device

select DEVICE

i.e. select /dev/sda

在 Device 上建立兩個 partiion

第一個

(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext3
Start? 0%
End? 33%

Start 及 END 的表達方式可以是容量或%, 如
4GB or 10%

P.S.

File system type:

swap = linux-swap

第二個

(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext3
Start? 15%
End? 100%
Warning: You requested a partition from 9003MB to 60.0GB.
The closest location we can manage is 30.0GB to 60.0GB.  Is this still
acceptable to you?
Yes/No?yes

第三個

Default 單位 megabytes

Start=34s   <-- (units in sectors)
End=Total sectors - 34s

第4個

mkpart primary 2200 100%

當沒有 partation table 時:

(parted) mkpart
Error: /dev/sda: unrecognised disk label

unrecognised disk label

 


unit

 

"s" (sectors),

"B" (bytes),

"MB"  <- megabyte (10^n)

"MiB" <- mebibyte (2^n)

"%" (percentage of device size),

"compact"  (megabytes for input, and a human-friendly form for output)

 

 


Set Flags

 

set minor flag state

  • boot
  • root
  • swap
  • hidden
  • raid
  • lvm
  • lba

Example:

set 1 boot on

set 1 raid off

說明

lba

this flag can be enabled to tell MS DOS, MS Windows 9x and MS Windows ME based operating systems to use Linear (LBA) mode.

 


Rescue 測試

刪除 Number 為 1 的 partion

rm 1

!!!!!!!! 沒有再問一次的 !!!!!!!!

拯救:

(parted) rescue
Start? 0
End? 100%

searching for file systems... 0%        (time left 179:30)
Information: A ntfs primary partition was found at 32.3kB -> 60.0GB.  Do you
want to add it to the partition table?
Yes/No/Cancel?yes

 


Resize

 

方案 1:

(parted) resize 1 0.00B 100%

 

OR

方案 1:

parted /dev/sdc

(parted) unit s

(parted) print

Number  Start  End         Size        Type     File system  Flags
 1      2048s  488386559s  488384512s  primary  ext4         boot

(parted) rm 1

(parted) mkpart pri ext4 2048s 100%

 


parted 錯地方

 

parted /dev/sdc1

(parted) unit s

Number  Start  End         Size        File system  Flags
 1      0s     488384511s  488384512s  ext4

parted /dev/sdc

(parted) unit s

(parted) print

Number  Start  End         Size        Type     File system  Flags
 1      2048s  488386559s  488384512s  primary  ext4         boot

 


 

 

回應

此欄位內容將保密,不會公開顯示出來。