Для начала – определимся с терминами, которые используются при работе с LVM:
1. Физические тома (physical volumes)
– непосредственно сами физические устройства, например:
# hwinfo --short --disk disk: /dev/sda VBOX HARDDISK
2. Группы томов (volume groups)
– группа физических томов, создающий “слой” для следующего уровня;
# vgdisplay -s "vg_mainhome" 19.51 GiB [19.51 GiB used / 0 free]
3. Логические тома (logical volumes)
– это аналог разделов физического диска и то, и именно они хранят данные; пользователи и процессы работают именно с логическими томами.
# lvscan ACTIVE '/dev/vg_mainhome/lv_root' [17.54 GiB] inherit ACTIVE '/dev/vg_mainhome/lv_swap' [1.97 GiB] inherit
Соответственно – утилиты, предназначенные для разных уровней LVM имеют в своих названиях две буквы:
pv*
– для работы с физическими томами (physical volumes
);
vg*
– для работы с группами томов (volume groups
);
lv*
– для работы с логическими томами (logical volumes
).
Схематично – разделы будут выглядеть так:
Далее – подключим два новых диска к серверу, и создадим новый logical volume
, который подключим к системе.
Вот как они выглядят после добавления:
# hwinfo --short --disk disk: /dev/sda VBOX HARDDISK /dev/sdb VBOX HARDDISK /dev/sdc VBOX HARDDISK
# fdisk -l | grep Disk Disk /dev/sda: 21.5 GB, 21474836480 bytes Disk identifier: 0x0004a99b Disk /dev/sdb: 8589 MB, 8589934592 bytes Disk identifier: 0x00000000 Disk /dev/sdc: 8589 MB, 8589934592 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_mainhome-lv_root: 18.8 GB, 18832424960 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_mainhome-lv_swap: 2113 MB, 2113929216 bytes Disk identifier: 0x00000000
# pvdisplay -C --separator ' | ' -o pv_name,vg_name PV | VG /dev/sda2 | vg_mainhome
# lvdisplay --maps | grep -E "Physical volume|LV Path" LV Path /dev/vg_mainhome/lv_root Physical volume /dev/sda2 LV Path /dev/vg_mainhome/lv_swap Physical volume /dev/sda2
В выводе fdisk
видны два новых диска – sdb
и sdc
, на которых ещё нет разделов:
# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x0004a99b Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0x00000000 Disk /dev/sdc: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0x00000000
Нам требуется создать два раздела на новых дисках, и отформатировать их в fstype
Linux LVM
.
Запускаем утилиту fdisk
:
# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xe8bae10a. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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): n // n - создать новый раздел Command action e extended p primary partition (1-4) p // основной раздел Partition number (1-4): 1 // номер раздела на диске, это первый First cylinder (1-1044, default 1): // оставляем по-умолчанию, с первого цилиндра Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +8000M // диск у нас Disk /dev/sdb: 8589 MB, устанавливаем раздел 8G Command (m for help): t // далее зададим тип раздела, нам нужен Linux LVM Selected partition 1 Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Hex code (type L to list codes): 8e // код Linux LVM - 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): w // записываем изменения на диск The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Повторяем тоже самое для второго диска:
# fdisk /dev/sdc
Наши диски теперь должны выглядеть так:
# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x0004a99b Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0xe8bae10a Device Boot Start End Blocks Id System /dev/sdb1 1 1021 8201151 8e Linux LVM Disk /dev/sdc: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0x6ba2fb41 Device Boot Start End Blocks Id System /dev/sdc1 1 1021 8201151 8e Linux LVM Disk /dev/mapper/vg_mainhome-lv_root: 18.8 GB, 18832424960 bytes 255 heads, 63 sectors/track, 2289 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: 0x00000000 Disk /dev/mapper/vg_mainhome-lv_swap: 2113 MB, 2113929216 bytes 255 heads, 63 sectors/track, 257 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 byt es / 512 bytes Disk identifier: 0x00000000
Далее нам необходимо создать physical volume
(иначе говоря – проинициализировать диски, для их работы с LVM) с помощью утилиты pvcreate
:
# pvcreate /dev/sdb1 /dev/sdc1 Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created
Если потребуется откатить изменения – выполняем:
# pvremove /dev/sdb1 /dev/sdc1 Labels on physical volume "/dev/sdb1" successfully wiped Labels on physical volume "/dev/sdc1" successfully wiped
Теперь посмотрим на подключенные к LVM жесткие диски с помощью утилиты pvdisplay
:
# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name vg_mainhome PV Size 19.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4994 Free PE 0 Allocated PE 4994 PV UUID M6Rqrd-DDVf-0crg-pXCx-tmgX-SylT-T6TGxG "/dev/sdb1" is a new physical volume of "7.82 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 7.82 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID YWaJbP-Wo9k-0MKg-4M2i-t1L9-CQGY-PMp9Bp "/dev/sdc1" is a new physical volume of "7.82 GiB" --- NEW Physical volume --- PV Name /dev/sdc1 VG Name PV Size 7.82 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 7p3u9B-nE0O-FUgS-qamm-X12o-e3DU-V9mH6E
Следующий шаг – создание volume group
из этих дисков с помощью утилиты vgcreate
.
Создадим раздел с именем shared
, и подключим в него разделы /dev/sdb1
и /dev/sdc1
:
# vgcreate shared /dev/sdb1 /dev/sdc1 Volume group "shared" successfully created
Просмотрим наши volume group
:
# vgdisplay --- Volume group --- VG Name shared System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 15.63 GiB PE Size 4.00 MiB Total PE 4002 Alloc PE / Size 0 / 0 Free PE / Size 4002 / 15.63 GiB VG UUID wXhmer-iXai-yiB3-no1e-1RlE-L4a2-Bu8H0s --- Volume group --- VG Name vg_mainhome System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.51 GiB PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 0 / 0 VG UUID X5ll0X-Bin8-L6lK-1oC2-BfD3-BegZ-2p0f8y
Или по отдельности:
# vgdisplay shared --- Volume group --- VG Name shared System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 15.63 GiB PE Size 4.00 MiB Total PE 4002 Alloc PE / Size 0 / 0 Free PE / Size 4002 / 15.63 GiB VG UUID wXhmer-iXai-yiB3-no1e-1RlE-L4a2-Bu8H0s
Другая утилита для просмотра групп томов:
# vgscan Reading all physical volumes. This may take a while... Found volume group "shared" using metadata type lvm2 Found volume group "vg_mainhome" using metadata type lvm2
Что бы переименовать группу – выполняем vgrename
:
# vgrename shared sharedrenamed Volume group "shared" successfully renamed to "sharedrenamed"
# vgdisplay shared Volume group "shared" not found Skipping volume group shared
# vgdisplay sharedrenamed --- Volume group --- VG Name sharedrenamed System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 15.63 GiB PE Size 4.00 MiB Total PE 4002 Alloc PE / Size 0 / 0 Free PE / Size 4002 / 15.63 GiB VG UUID wXhmer-iXai-yiB3-no1e-1RlE-L4a2-Bu8H0s
Для удаления группы – используется утилита vgremove
:
# vgremove sharedrenamed Volume group "sharedrenamed" successfully removed
Создадим группу заново 🙂 :
# vgcreate shared /dev/sdb1 /dev/sdc1 Volume group "shared" successfully created
Теперь – создадим один logical volume
на этой volume group
:
# lvcreate --name shared --size 15G shared Logical volume "shared" created
Тут после --name
– указываем имя нового LV
, --size
– его размер, и последним – имя VG
, которая будет содержать этот LV
.
Просмотрим все текущие разделы:
# lvdisplay --- Logical volume --- LV Path /dev/shared/shared LV Name shared VG Name shared LV UUID UqSAjH-9zRe-0I41-01jd-5sUE-sugL-URRyHk LV Write Access read/write LV Creation host, time main-home, 2014-07-20 10:56:12 +0300 LV Status available # open 0 LV Size 15.00 GiB Current LE 3840 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/vg_mainhome/lv_root LV Name lv_root VG Name vg_mainhome LV UUID 7p6qIz-14Rh-6arE-Z2E2-HK0I-g6oC-c0VMqx LV Write Access read/write LV Creation host, time main-home, 2014-06-26 19:28:51 +0300 LV Status available # open 1 LV Size 17.54 GiB Current LE 4490 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_mainhome/lv_swap LV Name lv_swap VG Name vg_mainhome LV UUID pTY0hl-VBiT-K0D4-f95u-WoMG-HACN-mbpJB6 LV Write Access read/write LV Creation host, time main-home, 2014-06-26 19:29:03 +0300 LV Status available # open 1 LV Size 1.97 GiB Current LE 504 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
И только что созданный отдельно:
# lvdisplay shared --- Logical volume --- LV Path /dev/shared/shared LV Name shared VG Name shared LV UUID UqSAjH-9zRe-0I41-01jd-5sUE-sugL-URRyHk LV Write Access read/write LV Creation host, time main-home, 2014-07-20 10:56:12 +0300 LV Status available # open 0 LV Size 15.00 GiB Current LE 3840 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
# lvscan ACTIVE '/dev/shared/shared' [15.00 GiB] inherit ACTIVE '/dev/vg_mainhome/lv_root' [17.54 GiB] inherit ACTIVE '/dev/vg_mainhome/lv_swap' [1.97 GiB] inherit
Что бы переименовать logical volume
– выполняем lvrename
:
# lvrename shared shared lv_shared Renamed "shared" to "lv_shared" in volume group "shared"
Синтаксис – lvrename
– имя группы томов – имя логического тома который надо переименовать – новое имя тома.
Следующий этап – создание файловой системы на новом разделе.
Проверим наш “старый” раздел:
# blkid /dev/sda1 /dev/sda1: UUID="7cd000d8-7ad8-45a0-8b38-7232da34384d" TYPE="ext4"
И создадим файловую систему EXT4 на новом разделе:
# mkfs.ext4 /dev/mapper/shared-lv_shared 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 983040 inodes, 3932160 blocks 196608 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4026531840 120 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Проверяем:
# blkid /dev/mapper/shared-lv_shared /dev/mapper/shared-lv_shared: UUID="01939a36-712e-487d-90dc-2e8c999096c5" TYPE="ext4"
Проверяем точки монтирования:
# mount /dev/mapper/vg_mainhome-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
Последний шаг – примонтировать новый раздел.
Создадим каталог:
# mkdir /mnt/shared
И смонтируем его:
# mount /dev/mapper/shared-lv_shared /mnt/shared
# mount /dev/mapper/vg_mainhome-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/shared-lv_shared on /mnt/shared type ext4 (rw)
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_mainhome-lv_root 18G 1.9G 15G 12% / tmpfs 504M 0 504M 0% /dev/shm /dev/sda1 485M 54M 407M 12% /boot /dev/mapper/shared-lv_shared 15G 166M 14G 2% /mnt/shared
Добавим запись в fstab
, что бы раздел монтировался при загрузке:
# cp /etc/fstab /etc/fstab.bkp
# vim /etc/fstab
Добавляем строку с новым разделом:
# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Jun 26 19:30:11 2014 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_mainhome-lv_root / ext4 defaults 1 1 UUID=7cd000d8-7ad8-45a0-8b38-7232da34384d /boot ext4 defaults 1 2 /dev/mapper/vg_mainhome-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/mapper/shared-lv_shared /mnt/shared ext4 rw,noatime 0 0
Про опции fstab
можно почитать в Вики.
Перезапускаем систему:
# reboot Broadcast message from root@main-home (/dev/pts/1) at 11:12 ... The system is going down for reboot NOW!
После перезагрузки – проверяем ещё раз:
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_mainhome-lv_root 18G 1.9G 15G 12% / tmpfs 504M 0 504M 0% /dev/shm /dev/sda1 485M 54M 407M 12% /boot /dev/mapper/shared-lv_shared 15G 166M 14G 2% /mnt/shared
И файл /var/log/dmesg
:
... sd 3:0:0:0: [sdb] Attached SCSI disk dracut: Scanning devices sda2 sdb1 sdc1 for LVM logical volumes vg_mainhome/lv_root vg_mainhome/lv_swap dracut: inactive '/dev/shared/lv_shared' [15.00 GiB] inherit dracut: inactive '/dev/vg_mainhome/lv_root' [17.54 GiB] inherit dracut: inactive '/dev/vg_mainhome/lv_swap' [1.97 GiB] inherit ...
# ls -l /mnt/shared/ total 0
# mkdir /mnt/shared/muz
# ls -l /mnt/shared/ total 4 drwxr-xr-x. 2 root root 4096 Jul 20 11:18 muz
Готово.
Ссылки по теме