Linux LVM - vytvoření nového oddílu
Situace: Máme stroj s GNU/Linux a pro správu diskového prostoru používáme LVM (Logical Volume Management). Na disku máme nevyužité místo a chceme ho přiřadit novému oddílu (LVM adding a new partition).
Konkrétně v našem případě chceme na disku /dev/sda vytvořit další oddíl sda3 a ten přidat do LVM (VG "centos"). V LVM to znamená přidat PV (physical volume) /dev/sda3, rozšířit VG (volume group) "centos" o /dev/sda3 a pak už jen vytvořit LV (logical volume) o velikosti 400GB s názvem "data" do VG "centos".
######################################################
[root@linux-server ~]#
[root@linux-server ~]#
######################################################
[root@linux-server ~]#
Physical volume "/dev/sda3" successfully created.
[root@linux-server ~]#
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 27,01 GiB / not usable 2,00 MiB
Allocatable yes
PE Size 4,00 MiB
Total PE 6915
Free PE 2
Allocated PE 6913
PV UUID lqPgKT-Tcu9-CYBz-hAl6-GCLS-JfXk-W80twc
"/dev/sda3" is a new physical volume of "<438,84 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size <438,84 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID D8y8K6-BiyP-6b4H-Txb6-NGny-SsEM-Eic1Zt
######################################################
[root@linux-server ~]#
Volume group "centos" successfully extended
######################################################
[root@linux-server ~]#
Logical volume "data" created.
[root@linux-server ~]#
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID InWE0p-Fymg-nI8r-F3Pt-Lkpv-ZEkY-Olfyuf
LV Write Access read/write
LV Creation host, time linux-server.localdomain, 2019-01-24 10:58:55 +0100
LV Status available
# open 2
LV Size 7,45 GiB
Current LE 1908
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID 0oKWp4-RQVH-pJhG-cMVd-O0uz-DqqS-fyJCpl
LV Write Access read/write
LV Creation host, time linux-server.localdomain, 2019-01-24 10:58:56 +0100
LV Status available
# open 1
LV Size 46,56 GiB
Current LE 11920
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/data
LV Name data
VG Name centos
LV UUID 2EbXSj-8aWs-h3Es-92uG-VjmK-YNb3-W87Jar
LV Write Access read/write
LV Creation host, time linux-server.localdomain, 2019-01-24 16:52:47 +0100
LV Status available
# open 0
LV Size 400,00 GiB
Current LE 102400
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
######################################################
[root@linux-server ~]#
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
26214400 inodes, 104857600 blocks
5242880 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2252341248
3200 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,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
######################################################
[root@linux-server ~]#
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931,5G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 27G 0 part
│ ├─centos-root 253:0 0 46,6G 0 lvm /
│ └─centos-swap 253:1 0 7,5G 0 lvm [SWAP]
└─sda3 8:3 0 438,9G 0 part
└─
######################################################
[root@linux-server ~]#
Konkrétně v našem případě chceme na disku /dev/sda vytvořit další oddíl sda3 a ten přidat do LVM (VG "centos"). V LVM to znamená přidat PV (physical volume) /dev/sda3, rozšířit VG (volume group) "centos" o /dev/sda3 a pak už jen vytvořit LV (logical volume) o velikosti 400GB s názvem "data" do VG "centos".
######################################################
Vytvořit nový oddíl - fdisk
[root@linux-server ~]#
fdisk /dev/sda
n
(nový oddíl)p
(primární)enter
t
(změna typu)8e
(typ Linux LVM)w
(uložit)[root@linux-server ~]#
reboot
######################################################
Vytvoření PV (physical volume) - pvcreate
[root@linux-server ~]#
pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@linux-server ~]#
pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 27,01 GiB / not usable 2,00 MiB
Allocatable yes
PE Size 4,00 MiB
Total PE 6915
Free PE 2
Allocated PE 6913
PV UUID lqPgKT-Tcu9-CYBz-hAl6-GCLS-JfXk-W80twc
"/dev/sda3" is a new physical volume of "<438,84 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size <438,84 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID D8y8K6-BiyP-6b4H-Txb6-NGny-SsEM-Eic1Zt
######################################################
Rozšížení VG (volume group) - vgextend
[root@linux-server ~]#
vgextend centos /dev/sda3
Volume group "centos" successfully extended
######################################################
Vytvoření LV (logical volume) - lvcreate
[root@linux-server ~]#
lvcreate -L 400GB -n data centos
Logical volume "data" created.
[root@linux-server ~]#
lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID InWE0p-Fymg-nI8r-F3Pt-Lkpv-ZEkY-Olfyuf
LV Write Access read/write
LV Creation host, time linux-server.localdomain, 2019-01-24 10:58:55 +0100
LV Status available
# open 2
LV Size 7,45 GiB
Current LE 1908
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID 0oKWp4-RQVH-pJhG-cMVd-O0uz-DqqS-fyJCpl
LV Write Access read/write
LV Creation host, time linux-server.localdomain, 2019-01-24 10:58:56 +0100
LV Status available
# open 1
LV Size 46,56 GiB
Current LE 11920
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/data
LV Name data
VG Name centos
LV UUID 2EbXSj-8aWs-h3Es-92uG-VjmK-YNb3-W87Jar
LV Write Access read/write
LV Creation host, time linux-server.localdomain, 2019-01-24 16:52:47 +0100
LV Status available
# open 0
LV Size 400,00 GiB
Current LE 102400
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
######################################################
Formát oddílu na ext4 - mkfs.ext4
[root@linux-server ~]#
mkfs.ext4 /dev/centos/data
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
26214400 inodes, 104857600 blocks
5242880 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2252341248
3200 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,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
######################################################
Kontrola finálního stavu - lsblk
[root@linux-server ~]#
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931,5G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 27G 0 part
│ ├─centos-root 253:0 0 46,6G 0 lvm /
│ └─centos-swap 253:1 0 7,5G 0 lvm [SWAP]
└─sda3 8:3 0 438,9G 0 part
└─
centos-data 253:2 0 400G 0 lvm
######################################################
Připojení oddílu - mount
[root@linux-server ~]#
mount /dev/centos/data /mnt/data