При использовании FreeBSD на виртуальной машине, иногда возникает необходимость увеличить размер диска, для этого можно воспользоваться инструментом gpart.
Если FreeBSD установлена на виртуальной машине VMWare перед работой с gpart нужно выполнить следующие действия.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
fdisk -u /dev/da0 ******* Working on device /dev/da0 ******* parameters extracted from in-core disklabel are: cylinders=233430 heads=255 sectors/track=63 (16065 blks/cyl) Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are: cylinders=233430 heads=255 sectors/track=63 (16065 blks/cyl) Do you want to change our idea of what BIOS thinks ? [n] Media sector size is 512 Warning: BIOS sector numbering starts with sector 1 Information from DOS bootblock is: The data for partition 1 is: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD) start 63, size 3125044125 (1525900 Meg), flag 80 (active) beg: cyl 0/ head 1/ sector 1; end: cyl 989/ head 0/ sector 63 Do you want to change it? [n] y Supply a decimal value for "sysid (165=FreeBSD)" [165] Supply a decimal value for "start" [63] Supply a decimal value for "size" [-1169923171] 3750067967 fdisk: WARNING: partition does not end on a cylinder boundary fdisk: WARNING: this may confuse the BIOS or some operating systems Correct this automatically? [n] y fdisk: WARNING: adjusting size of partition to 3750052887 Explicitly specify beg/end address ? [n] sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD) start 63, size 3750052887 (1831080 Meg), flag 80 (active) beg: cyl 0/ head 1/ sector 1; end: cyl 981/ head 254/ sector 63 Are we happy with this entry? [n] y The data for partition 2 is: <UNUSED> Do you want to change it? [n] The data for partition 3 is: <UNUSED> Do you want to change it? [n] The data for partition 4 is: <UNUSED> Do you want to change it? [n] Partition 1 is marked active Do you want to change the active partition? [n] We haven't changed the partition table yet. This is your last chance. parameters extracted from in-core disklabel are: cylinders=233430 heads=255 sectors/track=63 (16065 blks/cyl) Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are: cylinders=233430 heads=255 sectors/track=63 (16065 blks/cyl) Information from DOS bootblock is: 1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD) start 63, size 3750052887 (1831080 Meg), flag 80 (active) beg: cyl 0/ head 1/ sector 1; end: cyl 981/ head 254/ sector 63 2: <UNUSED> 3: <UNUSED> 4: <UNUSED> Should we write new partition table? [n] y fdisk: Geom not found |
1 2 3 |
Filesystem Size Used Avail Capacity Mounted on /dev/da0p2 38G 37G 1G 99% / devfs 1.0K 1.0K 0B 100% /dev |
Нужно увеличить раздел /dev/da0p2
1 2 3 4 5 6 |
# gpart show da0 => 34 83886013 da0 GPT (48G) [CORRUPT] 34 128 1 freebsd-boot (64k) 162 79691648 2 freebsd-ufs (38G) 79691810 4194236 3 freebsd-swap (2G) 83886046 1 - free - (512B) |
Если диск был отформатирован по схеме GPT, он может быть в статусе «corrupted», т.к. таблица разделов GPT резервного копирования больше не в конце привода. Решить эту проблему можно следующим образом
1 2 |
# gpart recover da0 da0 recovered |
1 2 3 4 5 6 |
# gpart show da0 => 34 83886013 da0 GPT (48G) 34 128 1 freebsd-boot (64k) 162 79691648 2 freebsd-ufs (38G) 79691810 4194236 3 freebsd-swap (2G) 83886046 1 - free - (512B) |
Отключаем и удаляем SWAP раздел
1 2 3 4 5 6 7 8 |
# swapoff /dev/da0p3 # gpart delete -i 3 da0 da0p3 deleted # gpart show da0 => 34 102399933 da0 GPT (48G) 34 128 1 freebsd-boot (64k) 162 79691648 2 freebsd-ufs (38G) 79691810 22708157 - free - (10G) |
Внимание! Существует риск потерять данные, поэтому, следует производить изменение размера раздела с Live-CD или Live-USB.
Изменяем размер раздела
1 2 3 4 5 6 7 |
# gpart resize -i 2 -a 4k -s 47G da0 da0p2 resized # gpart show da0 => 34 102399933 da0 GPT (48G) 34 128 1 freebsd-boot (64k) 162 98566144 2 freebsd-ufs (47G) 98566306 3833661 - free - (1.8G) |
Создаем раздел SWAP и делаем его активным
1 2 3 4 5 6 7 8 |
# gpart add -t freebsd-swap -a 4k da0 ada0p3 added # gpart show da0 => 34 102399933 da0 GPT (48G) 34 128 1 freebsd-boot (64k) 162 98566144 2 freebsd-ufs (47G) 98566306 3833661 3 freebsd-swap (1.8G) # swapon /dev/da0p3 |
Последние приготовления
1 2 3 4 5 6 7 |
# growfs /dev/da0p2 Device is mounted read-write; resizing will result in temporary write suspension for /. It's strongly recommended to make a backup before growing the file system. OK to grow file system on /dev/da0p2, mounted on /, from 38GB to 47GB? [Yes/No] Yes super-block backups (for fsck -b #) at: 80781312, 82063552, 83345792, 84628032, 85910272, 87192512, 88474752, 89756992, 91039232, 92321472, 93603712, 94885952, 96168192, 97450432 |
Готово, размер диска успешно изменен.