Используется два диска:
sdb был автоматически размечен при
установке с опцией разметки LVM, а второй
- подключен позже и отформатирован ntfs.
Отщипнем 15 Гб от второго для экспериментов.
Изначально:
test@testpc:~$ df -h
Файловая система
Разм Исп Дост Исп% смонтирована на
/dev/mapper/netshara-root
322M 108M 198M
36% /
tmpfs 251M 0 251M
0% /lib/init/rw
udev 246M 160K 246M
1% /dev
tmpfs 251M 0 251M
0% /dev/shm
/dev/sdb1 228M 15M 202M
7% /boot
/dev/mapper/netshara-home
134G 124G 3,3G
98% /home
/dev/mapper/netshara-tmp
368M 11M 339M
3% /tmp
/dev/mapper/netshara-usr
8,3G 715M 7,2G
9% /usr
/dev/mapper/netshara-var
2,8G 614M 2,1G
23% /var
/dev/sda1 150G 40G 110G
27% /media/hdd
Отмонтируем /media/hdd перед
изменением раздела:
test@testpc:~$ sudo umount /media/hdd/
test@testpc:~$ sudo fdisk -l /dev/sda
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 19458
156288000 7 HPFS/NTFS
Узнаем, сколько минимум
можно отпилить:
test@testpc:~$ sudo ntfsresize -i
/dev/sda1
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name : /dev/sda1
NTFS volume version: 3.1
Cluster size : 4096 bytes
Current volume size: 160038908416 bytes
(160039 MB)
Current device size: 160038912000 bytes
(160039 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use : 42107 MB (26,3%)
Collecting resizing constraints ...
You might resize at 42106085376 bytes
or 42107 MB (freeing 117932 MB).
Please make a test run using both the
-n and -s options before real resizing!
Обращаем внимание, что
советуют запускать прогу сначала в
режиме симуляции (-n):
test@testpc:~$ sudo ntfsresize -n
-s140G /dev/sda1
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name : /dev/sda1
NTFS volume version: 3.1
Cluster size : 4096 bytes
Current volume size: 160038908416 bytes
(160039 MB)
Current device size: 160038912000 bytes
(160039 MB)
New volume size : 139999994368 bytes
(140000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use : 42107 MB (26,3%)
Collecting resizing constraints ...
Needed relocations : 345223 (1415 MB)
Schedule chkdsk for NTFS consistency
check at Windows boot time ...
Resetting $LogFile ... (this might take
a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
The read-only test run ended
successfully.
Все ОК, значит, режем:
test@testpc:~$ sudo ntfsresize -s140G
/dev/sda1
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name : /dev/sda1
NTFS volume version: 3.1
Cluster size : 4096 bytes
Current volume size: 160038908416 bytes
(160039 MB)
Current device size: 160038912000 bytes
(160039 MB)
New volume size : 139999994368 bytes
(140000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use : 42107 MB (26,3%)
Collecting resizing constraints ...
Needed relocations : 345223 (1415 MB)
WARNING: Every sanity check passed and
only the dangerous operations left.
Make sure that important data has been
backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed
(y/[n])? y
Schedule chkdsk for NTFS consistency
check at Windows boot time ...
Resetting $LogFile ... (this might take
a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device
'/dev/sda1'.
You can go on to shrink the device for
example with Linux fdisk.
IMPORTANT: When recreating the
partition, make sure that you
1) create it at the same disk sector
(use sector as the unit!)
2) create it with the same partition
type (usually 7, HPFS/NTFS)
3) do not make it smaller than the
new NTFS filesystem size
4) set the bootable flag for the
partition if it existed before
Otherwise you won't be able to access
NTFS or can't boot from the disk!
If you make a mistake and don't have a
partition table backup then you
can recover the partition table by
TestDisk or Parted's rescue mode.
Создаем разделы на
освободившемся месте:
test@testpc:~$ sudo fdisk /dev/sda
WARNING: DOS-compatible mode is
deprecated. It's strongly recommended to
switch off the mode (command
'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility
flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition
table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts
only)
Command (m for help): p
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 19458
156288000 7 HPFS/NTFS
Command (m for help): d
Selected partition 1
Command (m for help): d
No partition is defined yet!
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-19457, default 1): 1
Last cylinder, +cylinders or
+size{K,M,G} (1-19457, default 19457): +140G
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7
(HPFS/NTFS)
Command (m for help): p
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 18277
146809971 7 HPFS/NTFS
Command (m for help): v
Remaining 18959752 unallocated 512-byte
sectors
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition
table.
Syncing disks.
Создаем linux-разделы
test@testpc:~$ sudo fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 18277
146809971 7 HPFS/NTFS
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (18278-19457, default
18278):
Using default value 18278
Last cylinder, +cylinders or
+size{K,M,G} (18278-19457, default 19457): +3G
Command (m for help): v
Remaining 12646207 unallocated 512-byte
sectors
Command (m for help): p
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 18277
146809971 7 HPFS/NTFS
/dev/sda2 18278 18670
3156772+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition
table.
Syncing disks.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (18671-19457, default
18671):
Using default value 18671
Last cylinder, +cylinders or
+size{K,M,G} (18671-19457, default 19457): +3G
Command (m for help): v
Remaining 6332662 unallocated 512-byte
sectors
Command (m for help): p
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 18277
146809971 7 HPFS/NTFS
/dev/sda2 18278 18670
3156772+ 83 Linux
/dev/sda3 18671 19063
3156772+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition
table.
Syncing disks.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (19064-19457, default
19064):
Using default value 19064
Last cylinder, +cylinders or
+size{K,M,G} (19064-19457, default 19457):
Using default value 19457
Command (m for help): v
Remaining 3052 unallocated 512-byte
sectors
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition
table.
Syncing disks.
Итак, разметка второго
диска завершена:
test@testpc:~$ sudo fdisk -l /dev/sda
Disk /dev/sda: 160.0 GB, 160040803840
bytes
255 heads, 63 sectors/track, 19457
cylinders
Units = cylinders of 16065 * 512 =
8225280 bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x0009e367
Device Boot Start End
Blocks Id System
/dev/sda1 1 18277
146809971 7 HPFS/NTFS
/dev/sda2 18278 18670
3156772+ 83 Linux
/dev/sda3 18671 19063
3156772+ 83 Linux
/dev/sda4 19064 19457
3164805 83 Linux
НЕ создаем ФС на них,
т.к. сначала надо создать физические
тома:
test@testpc:~$ sudo pvcreate /dev/sda2
/dev/sda3
Physical volume "/dev/sda2"
successfully created
Physical volume "/dev/sda3"
successfully created
Создаем группу томов
сначала в тестовом режиме:
test@testpc:~$ sudo vgcreate -t -v
toolsvg /dev/sda2 /dev/sda3
Test mode: Metadata will NOT be
updated.
Wiping cache of LVM-capable devices
Wiping cache of LVM-capable devices
Adding physical volume '/dev/sda2'
to volume group 'toolsvg'
Adding physical volume '/dev/sda3'
to volume group 'toolsvg'
Test mode: Skipping archiving of
volume group.
Test mode: Skipping volume group
backup.
Volume group "toolsvg"
successfully created
Test mode: Wiping internal cache
Wiping internal VG cache
Теперь реально:
test@testpc:~$ sudo vgcreate -v
toolsvg /dev/sda2 /dev/sda3
Wiping cache of LVM-capable devices
Wiping cache of LVM-capable devices
Adding physical volume '/dev/sda2'
to volume group 'toolsvg'
Adding physical volume '/dev/sda3'
to volume group 'toolsvg'
Creating directory
"/etc/lvm/archive"
Archiving volume group "toolsvg"
metadata (seqno 0).
Creating volume group backup
"/etc/lvm/backup/toolsvg" (seqno 1).
Volume group "toolsvg"
successfully created
Смотрим, что есть:
test@testpc:~$ sudo vgdisplay -C
--verbose
Finding all volume groups
Finding volume group "netshara"
Finding volume group "toolsvg"
VG Attr Ext #PV #LV #SN
VSize VFree VG UUID
netshara wz--n- 4,00m 1 6 0
148,81g 0 zr6i2P-KImk-pYPP-gAUy-vkkt-Uuw6-AQLVTT
toolsvg wz--n- 4,00m 2 0 0
6,02g 6,02g DtejK2-3nb7-dbdJ-4BR8-4jHx-w4Vg-FGEYz5
Создаем виртуальный
том в тестовом режиме, полностью забиваем
место созданной группы томов:
test@testpc:~$ sudo lvcreate -l
100%FREE -n netboot -t -v toolsvg
Test mode: Metadata will NOT be
updated.
Setting logging type to disk
Finding volume group "toolsvg"
Test mode: Skipping archiving of
volume group.
Creating logical volume netboot
Test mode: Skipping volume group
backup.
Found volume group "toolsvg"
Aborting. Failed to activate new LV
to wipe the start of it.
Found volume group "toolsvg"
Unable to deactivate failed new LV.
Manual intervention required.
Test mode: Wiping internal cache
Wiping internal VG cache
Реально:
test@testpc:~$ sudo lvcreate -l
100%FREE -n netboot -v toolsvg
Setting logging type to disk
Finding volume group "toolsvg"
Archiving volume group "toolsvg"
metadata (seqno 1).
Creating logical volume netboot
Creating volume group backup
"/etc/lvm/backup/toolsvg" (seqno 2).
Found volume group "toolsvg"
Creating toolsvg-netboot
Loading toolsvg-netboot table
(254:6)
Resuming toolsvg-netboot (254:6)
Clearing start of logical volume
"netboot"
Creating volume group backup
"/etc/lvm/backup/toolsvg" (seqno 2).
Logical volume "netboot"
created
Смотрим список логических
томов в системе:
test@testpc:~$ sudo lvdisplay -C
LV VG Attr LSize
Origin Snap% Move Log Copy% Convert
home netshara -wi-ao 135,98g
root netshara -wi-ao 332,00m
swap_1 netshara -wi-ao 980,00m
tmp netshara -wi-ao 380,00m
usr netshara -wi-ao 8,38g
var netshara -wi-ao 2,79g
netboot toolsvg -wi-a- 6,02g
Создаем ФС на новом
томе:
test@testpc:~$ sudo mkfs.ext3
/dev/mapper/toolsvg-netboot
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
394352 inodes, 1576960 blocks
78848 blocks (5.00%) reserved for the
super user
First data block=0
Maximum filesystem blocks=1614807040
49 block groups
32768 blocks per group, 32768 fragments
per group
8048 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376,
294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem
accounting information: done
This filesystem will be automatically
checked every 24 mounts or
180 days, whichever comes first. Use
tune2fs -c or -i to override.
Монтируем:
test@testpc:~$ sudo mount
/dev/mapper/toolsvg-netboot /srv/
Расширим раздел /home
первого диска за счет оставшегося
пустого третьего раздела. Предварительно
его надо отмонтировать без последствий,
поэтому останавливаем все, что использует
файлы на нем:
test@testpc:~$ sudo service
transmission-daemon stop
root@testpc:~# service samba stop
test@testpc:~$ sudo lsof /home/
COMMAND PID USER FD TYPE DEVICE
SIZE/OFF NODE NAME
bash 25063 alex cwd DIR 254,5
4096 7331841 /home/test
sudo 26887 root cwd DIR 254,5
4096 7331841 /home/test
lsof 26888 root cwd DIR 254,5
4096 7331841 /home/test
lsof 26889 root cwd DIR 254,5
4096 7331841 /home/test
Выходим из под обычного
пользователя (убить оболочку не
получилось), разрешаем доступ по ssh от
рута и заходим (уже ничего не будет
мешать для размонтирования домашнего
каталога):
root@testpc:~# lsof /home/
root@testpc:~# umount /home
Создаем физический
том:
root@testpc:~# pvcreate /dev/sda4
Physical volume "/dev/sda4"
successfully created
Расширяем, как обычно,
сначала в тестовом режиме:
root@testpc:~# vgextend -t -v /dev/sda4
netshara
Test mode: Metadata will NOT be
updated.
Checking for volume group "sda4"
Wiping cache of LVM-capable devices
Volume group "sda4" not
found
Test mode: Wiping internal cache
Wiping internal VG cache
root@testpc:~# vgextend -t -v netshara
/dev/sda4
Test mode: Metadata will NOT be
updated.
Checking for volume group
"netshara"
Test mode: Skipping archiving of
volume group.
Wiping cache of LVM-capable devices
Adding physical volume '/dev/sda4'
to volume group 'netshara'
Volume group "netshara"
will be extended by 1 new physical volumes
Test mode: Skipping volume group
backup.
Volume group "netshara"
successfully extended
Test mode: Wiping internal cache
Wiping internal VG cache
Реально:
root@testpc:~# vgextend -v netshara
/dev/sda4
Checking for volume group
"netshara"
Archiving volume group "netshara"
metadata (seqno 7).
Wiping cache of LVM-capable devices
Adding physical volume '/dev/sda4'
to volume group 'netshara'
Volume group "netshara"
will be extended by 1 new physical volumes
Creating volume group backup
"/etc/lvm/backup/netshara" (seqno 8).
Volume group "netshara"
successfully extended
Видим изменения:
root@testpc:~# vgdisplay -C
VG #PV #LV #SN Attr VSize
VFree
netshara 2 6 0 wz--n- 151,82g
3,02g
toolsvg 2 1 0 wz--n- 6,02g
0
На всякий случай
root@testpc:~# vgcfgbackup -v netshara
Using volume group(s) on command
line
Finding volume group "netshara"
Creating volume group backup
"/etc/lvm/backup/netshara" (seqno 8).
Volume group "netshara"
successfully backed up.
root@testpc:~# vgcfgbackup -v toolsvg
Using volume group(s) on command
line
Finding volume group "toolsvg"
Creating volume group backup
"/etc/lvm/backup/toolsvg" (seqno 2).
Volume group "toolsvg"
successfully backed up.
Сначала в тестовом
режиме:
root@testpc:~# lvextend -L +3G -t -v
netshara/home
Test mode: Metadata will NOT be
updated.
Finding volume group netshara
Test mode: Skipping archiving of
volume group.
Extending logical volume home to
138,98 GiB
Found volume group "netshara"
Found volume group "netshara"
Found volume group "netshara"
Test mode: Skipping volume group
backup.
Logical volume home successfully
resized
Test mode: Wiping internal cache
Wiping internal VG cache
Реально:
root@testpc:~# lvextend -L +3G -v
netshara/home
Finding volume group netshara
Archiving volume group "netshara"
metadata (seqno 8).
Extending logical volume home to
138,98 GiB
Found volume group "netshara"
Found volume group "netshara"
Loading netshara-home table (254:5)
Suspending netshara-home (254:5)
with device flush
Found volume group "netshara"
Resuming netshara-home (254:5)
Creating volume group backup
"/etc/lvm/backup/netshara" (seqno 9).
Logical volume home successfully
resized
Надо увеличить размер
ФС:
root@testpc:~# fsck -n
/dev/mapper/netshara-home
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/netshara-home: clean,
3995/8912896 files, 33105822/35647488 blocks
root@testpc:~# fdisk -s
/dev/mapper/netshara-home
145735680
root@testpc:~# resize2fs -P
/dev/mapper/netshara-home
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f
/dev/mapper/netshara-home' first.
root@testpc:~# e2fsck -f
/dev/mapper/netshara-home
e2fsck 1.41.12 (17-May-2010)
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
/dev/mapper/netshara-home: 3995/8912896
files (43.3% non-contiguous), 33105822/35647488 blocks
root@testpc:~# resize2fs -P
/dev/mapper/netshara-home
resize2fs 1.41.12 (17-May-2010)
Estimated minimum size of the
filesystem: 33065730
root@testpc:~# resize2fs
/dev/mapper/netshara-home
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on
/dev/mapper/netshara-home to 36433920 (4k) blocks.
The filesystem on
/dev/mapper/netshara-home is now 36433920 blocks long.
Монтируем раздел:
root@testpc:~# mount
/dev/mapper/netshara-home /home
root@testpc:~# df -h
/dev/mapper/netshara-home
Файловая система
Разм Исп Дост Исп% смонтирована на
/dev/mapper/netshara-home
137G 125G 5,7G
96% /home
Стартуем сервисы:
test@testpc:/root$ sudo service samba
start
[sudo] password for alex:
Starting Samba daemons: nmbd smbd.
test@testpc:/root$ sudo service
transmission-daemon start
Starting bittorrent daemon:
transmission-daemon.
В итоге:
test@testpc:/root$ sudo vgdisplay -C
VG #PV #LV #SN Attr VSize
VFree
netshara 2 6 0 wz--n- 151,82g
16,00m
toolsvg 2 1 0 wz--n- 6,02g
0
test@testpc:/root$ sudo lvdisplay -C
LV VG Attr LSize
Origin Snap% Move Log Copy% Convert
home netshara -wi-ao 138,98g
root netshara -wi-ao 332,00m
swap_1 netshara -wi-ao 980,00m
tmp netshara -wi-ao 380,00m
usr netshara -wi-ao 8,38g
var netshara -wi-ao 2,79g
netboot toolsvg -wi-ao 6,02g