Partition Resize: различия между версиями

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску
(Новая страница: «Категория:Linux Категория:ext4 Категория:Block Device =Как склонировать диск большего разме...»)
 
 
(не показано 5 промежуточных версий этого же участника)
Строка 29: Строка 29:
 
/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****
 
/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****
 
/dev/sdb2: 83197/15327232 files (0.2% non-contiguous), 3132934/61278464 blocks
 
/dev/sdb2: 83197/15327232 files (0.2% non-contiguous), 3132934/61278464 blocks
  +
</PRE>
root@blade1:~# resize2fs /dev/sdb2 80G
 
  +
  +
  +
Новый размер ФС - можно указывать в разных единицах
  +
* S - 512 byte sectors
  +
* K - kilobytes
  +
* M - megabytes
  +
* G - gigabytes
  +
<PRE>
  +
# resize2fs /dev/sdb2 80G
 
resize2fs 1.46.5 (30-Dec-2021)
 
resize2fs 1.46.5 (30-Dec-2021)
 
Resizing the filesystem on /dev/sdb2 to 20971520 (4k) blocks.
 
Resizing the filesystem on /dev/sdb2 to 20971520 (4k) blocks.
Строка 35: Строка 44:
 
</PRE>
 
</PRE>
   
  +
Проверить результат: Подмонтировать
 
  +
<PRE>
  +
mount /dev/sdb2 /mnt/
  +
</PRE>
   
 
<PRE>
 
<PRE>
  +
df -h .
  +
Filesystem Size Used Avail Use% Mounted on
  +
/dev/sdb2 78G 7.3G 67G 10% /mnt
  +
</PRE>
  +
и проверить полученный размер
   
  +
=Уменьшить размер партиции=
  +
<PRE>
  +
tune2fs -l /dev/sdb2
  +
tune2fs 1.46.5 (30-Dec-2021)
  +
Filesystem volume name: <none>
  +
Last mounted on: /
  +
Filesystem UUID: bfc54566-94ff-418d-96f6-2231e8114932
  +
Filesystem magic number: 0xEF53
  +
Filesystem revision #: 1 (dynamic)
  +
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
  +
Filesystem flags: signed_directory_hash
  +
Default mount options: user_xattr acl
  +
Filesystem state: clean
  +
Errors behavior: Continue
  +
Filesystem OS type: Linux
  +
Inode count: 5242880
  +
Block count: 20971520
  +
Reserved block count: 1048575
  +
Free blocks: 18472633
  +
Free inodes: 5159683
  +
First block: 0
  +
Block size: 4096
  +
Fragment size: 4096
  +
Group descriptor size: 64
  +
Reserved GDT blocks: 1024
  +
Blocks per group: 32768
  +
Fragments per group: 32768
  +
Inodes per group: 8192
  +
Inode blocks per group: 512
  +
Flex block group size: 16
  +
Filesystem created: Mon Dec 25 14:29:52 2023
  +
Last mount time: Fri Dec 29 12:12:41 2023
  +
Last write time: Fri Dec 29 12:12:41 2023
  +
Mount count: 1
  +
Maximum mount count: -1
  +
Last checked: Fri Dec 29 12:10:35 2023
  +
Check interval: 0 (<none>)
  +
Lifetime writes: 12 GB
  +
Reserved blocks uid: 0 (user root)
  +
Reserved blocks gid: 0 (group root)
  +
First inode: 11
  +
Inode size: 256
  +
Required extra isize: 32
  +
Desired extra isize: 32
  +
Journal inode: 8
  +
Default directory hash: half_md4
  +
Directory Hash Seed: e8656586-b6c5-483d-baa2-b38231103618
  +
Journal backup: inode blocks
  +
Checksum type: crc32c
  +
Checksum: 0xbac09600
 
</PRE>
 
</PRE>
   
   
<PRE>
 
   
</PRE>
 
   
 
<PRE>
 
<PRE>
  +
Block count: 20971520
 
  +
...
  +
Block size: 4096
 
</PRE>
 
</PRE>
  +
20971520 (blocks) * 4096 (bytes per block) = 85899345920 bytes
  +
  +
  +
 
<PRE>
 
<PRE>
  +
disk -l /dev/sdb
  +
GPT PMBR size mismatch (490234751 != 3907029167) will be corrected by write.
  +
The backup GPT table is not on the end of the device.
  +
Disk /dev/sdb: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
  +
Disk model: TOSHIBA DT01ACA2
  +
Units: sectors of 1 * 512 = 512 bytes
  +
Sector size (logical/physical): 512 bytes / 4096 bytes
  +
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
  +
Disklabel type: gpt
  +
Disk identifier: 36E6D5A9-BDEB-4DB7-BB57-2DF52482C79F
   
  +
Device Start End Sectors Size Type
  +
/dev/sdb1 2048 4095 2048 1M BIOS boot
  +
/dev/sdb2 4096 490231807 490227712 233.8G Linux filesystem
 
</PRE>
 
</PRE>
  +
Units: sectors of 1 * 512 = 512 bytes
  +
  +
  +
85899345920 bytes / 512 bytes sector size = 167772160 sectors
  +
  +
  +
Далее раздел сделать чуть более чем 167772160 и после чего расширить ФС вверх
  +
 
<PRE>
 
<PRE>
  +
parted
  +
GNU Parted 3.4
  +
Using /dev/sda
  +
Welcome to GNU Parted! Type 'help' to view a list of commands.
  +
(parted) unit s
  +
(parted) select /dev/sdb
  +
Using /dev/sdb
  +
(parted) p
  +
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 3416794416 blocks) or continue with the current setting?
  +
Fix/Ignore? I
  +
Model: ATA TOSHIBA DT01ACA2 (scsi)
  +
Disk /dev/sdb: 3907029168s
  +
Sector size (logical/physical): 512B/4096B
  +
Partition Table: gpt
  +
Disk Flags:
  +
  +
Number Start End Size File system Name Flags
  +
1 2048s 4095s 2048s bios_grub
  +
2 4096s 167772161s 167768066s ext4
  +
  +
(parted) resizepart 2 167772162
  +
(parted) p
  +
Model: ATA TOSHIBA DT01ACA2 (scsi)
  +
Disk /dev/sdb: 3907029168s
  +
Sector size (logical/physical): 512B/4096B
  +
Partition Table: gpt
  +
Disk Flags:
   
  +
Number Start End Size File system Name Flags
  +
1 2048s 4095s 2048s bios_grub
  +
2 4096s 167772162s 167768067s ext4
 
</PRE>
 
</PRE>

Текущая версия на 15:07, 29 декабря 2023

Как склонировать диск большего размера на меньший

Нужно скопировать систему целиком на меньший диск (на том диске с которого производится копирование есть свободное место)

Уменьшить размер файловой системы

Первым делом при необходимости отмонтировать ФС, затем принудительно проверить:

e2fsck -f /dev/sdb2

e2fsck 1.46.5 (30-Dec-2021)
Superblock needs_recovery flag is clear, but journal has data.
Run journal anyway<y>? yes
/dev/sdb2: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (58146063, counted=58145530).
Fix<y>? yes
Free inodes count wrong (15244150, counted=15244035).
Fix<y>? yes

/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb2: 83197/15327232 files (0.2% non-contiguous), 3132934/61278464 blocks


Новый размер ФС - можно указывать в разных единицах

  • S - 512 byte sectors
  • K - kilobytes
  • M - megabytes
  • G - gigabytes
# resize2fs /dev/sdb2 80G
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/sdb2 to 20971520 (4k) blocks.
The filesystem on /dev/sdb2 is now 20971520 (4k) blocks long.

Проверить результат: Подмонтировать

mount /dev/sdb2 /mnt/
df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb2        78G  7.3G   67G  10% /mnt

и проверить полученный размер

Уменьшить размер партиции

tune2fs -l /dev/sdb2
tune2fs 1.46.5 (30-Dec-2021)
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          bfc54566-94ff-418d-96f6-2231e8114932
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              5242880
Block count:              20971520
Reserved block count:     1048575
Free blocks:              18472633
Free inodes:              5159683
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Mon Dec 25 14:29:52 2023
Last mount time:          Fri Dec 29 12:12:41 2023
Last write time:          Fri Dec 29 12:12:41 2023
Mount count:              1
Maximum mount count:      -1
Last checked:             Fri Dec 29 12:10:35 2023
Check interval:           0 (<none>)
Lifetime writes:          12 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      e8656586-b6c5-483d-baa2-b38231103618
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0xbac09600



Block count:              20971520
...
Block size:               4096

20971520 (blocks) * 4096 (bytes per block) = 85899345920 bytes


disk -l /dev/sdb
GPT PMBR size mismatch (490234751 != 3907029167) will be corrected by write.
The backup GPT table is not on the end of the device.
Disk /dev/sdb: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: TOSHIBA DT01ACA2
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 36E6D5A9-BDEB-4DB7-BB57-2DF52482C79F

Device     Start       End   Sectors   Size Type
/dev/sdb1   2048      4095      2048     1M BIOS boot
/dev/sdb2   4096 490231807 490227712 233.8G Linux filesystem

Units: sectors of 1 * 512 = 512 bytes


85899345920 bytes / 512 bytes sector size = 167772160 sectors


Далее раздел сделать чуть более чем 167772160 и после чего расширить ФС вверх

parted
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) select /dev/sdb
Using /dev/sdb
(parted) p
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 3416794416 blocks) or continue with the current setting?
Fix/Ignore? I
Model: ATA TOSHIBA DT01ACA2 (scsi)
Disk /dev/sdb: 3907029168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start  End         Size        File system  Name  Flags
 1      2048s  4095s       2048s                          bios_grub
 2      4096s  167772161s  167768066s  ext4

(parted) resizepart 2 167772162
(parted) p
Model: ATA TOSHIBA DT01ACA2 (scsi)
Disk /dev/sdb: 3907029168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start  End         Size        File system  Name  Flags
 1      2048s  4095s       2048s                          bios_grub
 2      4096s  167772162s  167768067s  ext4