Last active
September 19, 2024 10:56
-
-
Save alex2600/3b2ebd16fa5b088358eda7597f1be196 to your computer and use it in GitHub Desktop.
Create virtual device from file and use it in LVM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fallocate -l 256M /image.img # create file to store a filesystem | |
losetup /dev/loop0 # check if loop0 is free to use, if not continue with loop1, ... | |
losetup /dev/loop0 /image.img # create device using file | |
pvcreate /dev/loop0 # create lvm physical volume | |
vgcreate lvmstorage /dev/loop0 # create volume group "lvmstorage" using device | |
lvcreate -L 128M -n lv1 lvmstorage # create logical volume "lv1" with size 128M | |
mkfs.ext4 /dev/lvmstorage/lv1 # create file system | |
e2label /dev/lvmstorage/lv1 LV1 # set label "LV1" for device | |
mkdir /mnt/stuff | |
mount /dev/lvmstorage/lv1 /mnt/stuff # mount device | |
df -hT # check result |
Do you need the "loop" module loaded ?
@Et7f3 I'm really sorry, but I completely forgot what I meant))
This was the beginning of my career in information technology, and I was stupid)
Anyway, thanks for this instruction, it was really helpful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, you can change 2 and 3 line to
losetup -fP /image.img
If you want find loop with your file, you can run some like this
losetup -a | grep image.img