partedを使用してCentOS 7サーバーを分割する方法は?

partedを使用してCentOS 7サーバーを分割する方法は?

私はCentOS 7サーバーを使用してハードドライブの最大のパーティションを4つの小さなパーティションに分割する予定ですparted。新しいパーティションの3つのサイズはそれぞれ300GBで、4番目のパーティションは残りを占めます。以下にドライブに関するレポートを示し、parted printその後に私が使用すると思うコマンド構文を示します。 ハードドライブを正しく分割するには、次のコードをどのように変更しますか?

print報告された結果は次のとおりですparted

[root@localhost ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA WDC WD20EZRX-22D (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  211MB   210MB   fat16           EFI System Partition  boot
 2      211MB   735MB   524MB   ext4
 3      735MB   1938GB  1938GB  ext4
 4      1938GB  1992GB  53.7GB  ext4
 5      1992GB  2000GB  8187MB  linux-swap(v1)

だから端末コマンドは簡単だと思います。

rm 3
mkpart    ext4    735MB    300GB
mkpart    ext4    300GB    600GB  
mkpart    ext4    600GB    900GB  
mkpart    ext4    900GB    1938GB  

パーティションを正しく作成するには、上記のコードをどのように変更する必要がありますか?

参考までに、fdisk -lドライブのわずかに異なる画像を以下に示します。

[root@localhost ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
#         Start          End    Size  Type            Name
 1         2048       411647    200M  EFI System      EFI System Partition
 2       411648      1435647    500M  Microsoft basic 
 3      1435648   3786041343    1.8T  Microsoft basic 
 4   3786041344   3890898943     50G  Microsoft basic 
 5   3890898944   3906889727    7.6G  Linux swap   

編集する:


@Anthonの提案を使用しようとしましたが、結果は異なります。 CentOSを再インストールすると、もう少し異なる環境になりますが、基本的な概念は同じであるため、再現可能でなければなりませんfdisk -l。既存のパーティションをすべてparted ... print入力するとselect /dev/dm-1ペアが表示されないようですが、partedスキップするとselect /dev/dm-1エラーが発生します。実際の端末ログは次のとおりです。

[root@localhost ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt

#         Start          End    Size  Type            Name
 1         2048       411647    200M  EFI System      EFI System Partition
 2       411648      1435647    500M  Microsoft basic 
 3      1435648    105850879   49.8G  Microsoft basic 
 4    105850880    121841663    7.6G  Linux swap      

Disk /dev/mapper/luks-fb2eda94-fcff-4624-8b04-a9786845504a: 53.5 GB, 53458501632 bytes, 104411136 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mapper/luks-08f8bdb9-85bf-45ef-9519-3f38906c489a: 1938.0 GB, 1938005426176 bytes, 3785166848 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

[root@localhost ~]# df -T -h
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/dm-0      ext4       49G  1.1G   46G   3% /
devtmpfs       devtmpfs  3.8G     0  3.8G   0% /dev
tmpfs          tmpfs     3.8G     0  3.8G   0% /dev/shm
tmpfs          tmpfs     3.8G  8.7M  3.8G   1% /run
tmpfs          tmpfs     3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/sda2      ext4      477M  110M  338M  25% /boot
/dev/sda1      vfat      200M  9.8M  191M   5% /boot/efi
/dev/dm-1      ext4      1.8T   77M  1.7T   1% /home

[root@localhost ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA WDC WD20EZRX-00D (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  211MB   210MB   fat16           EFI System Partition  boot
 2      211MB   735MB   524MB   ext4
 3      735MB   54.2GB  53.5GB
 4      54.2GB  62.4GB  8187MB  linux-swap(v1)
 5      62.4GB  2000GB  1938GB

(parted) unit compact
(parted) select /dev/dm
Error: Could not stat device /dev/dm - No such file or directory.
Retry/Cancel? cancel                                                      
(parted) select /dev/dm-1                                                 
Using /dev/dm-1
(parted) rm 5
Error: Partition doesn't exist.
(parted) print                                                            
Model: Linux device-mapper (crypt) (dm)
Disk /dev/dm-1: 1938GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  1938GB  1938GB  ext4

(parted) quit                                                             
[root@localhost ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA WDC WD20EZRX-00D (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  211MB   210MB   fat16           EFI System Partition  boot
 2      211MB   735MB   524MB   ext4
 3      735MB   54.2GB  53.5GB
 4      54.2GB  62.4GB  8187MB  linux-swap(v1)
 5      62.4GB  2000GB  1938GB

(parted) unit compact                                                     
(parted) rm 5                                                             
Error: Partition(s) 5 on /dev/sda have been written, but we have been  
unable to inform the kernel of the change, probably because it/they are  
in use.  As a result, the old partition(s) will remain in use.  You  
should reboot now before making further changes.
Ignore/Cancel?  ancel                                                     
(parted) quit
Information: You may need to update /etc/fstab.

では、このドライブをどのように分割しますか?

ベストアンサー1

まず、少なくともパーティション 1、2、4、MBR をバックアップします。 55GBしかないので、それほど時間はかかりません。

このmkpartコマンドは、目的のパーティション・タイプの後にファイル・システム・タイプをオプションのパラメーターとして使用します。

mkpart PART-TYPE [FS-TYPE] START END     make a partition

ext4そして、パーティションタイプがファイルシステムタイプ()のようです。私は通常ファイルシステムの種類を提供しません。後でパーティションをフォーマットするとそれを処理します。

私はそれをします:

$ parted
unit compact    
select /dev/sda
rm 3
mkpart  " "    735MB    300GB
mkpart  " "    300GB    600GB  
mkpart  " "    600GB    900GB  
mkpart  " "    900GB    1938GB

開始番号と終了番号がよさそうです。

/dev/sdaコンピュータにドライブが1つしかない場合は、デバイスを明示的に選択する必要はありません。これにより、次のような質問が発生します。実際、どのような攻撃もせずにサーバーを実行していますか?これを行うには、上記の作業を試みる前に、少なくともバックアップできる完全な交換デバイスが必要です。

はっきりしないのはなぜあなたはこれをしたいです。パーティションが小さければ小さいほど柔軟性が低くなり、簡単に埋められます。達成する目的に応じて、パーティション化されていないパーティションの上にLVMを使用することを検討する必要があります。 4つの論理ボリュームを含むボリュームグループを作成する場合は、4つのファイルシステムも作成できますが、サイズを変更して割り当てる方が簡単です。

おすすめ記事