1. 创建 disk.img 文件

1
2
3
4
$ dd if=/dev/zero of=disk.img bs=4K count=$((5*1024*1024))
5242880+0 records in
5242880+0 records out
21474836480 bytes (21 GB, 20 GiB) copied, 850.981 s, 25.2 MB/s

2. 将 disk.img 挂载至 loop

1
2
$ losetup --partscan --show --find disk.img
/dev/loop0

3. 创建PV物理卷

1
2
$ pvcreate /dev/loop0
  Physical volume "/dev/loop0" successfully created.

4. 创建VG卷组

1
2
$ vgcreate loopvg /dev/loop0
  Volume group "loopvg" successfully created

5. 备份disk.img文件

随时可还原回来,或发给他人使用

1
2
$ tar zcvf disk.img.gz disk.img
disk.img

5. 创建名字为disk1的逻辑卷

1
2
$ lvcreate loopvg -L 1G -n disk1
  Logical volume "disk1" created.

7. 查看lv逻辑卷

1
2
3
$ lvs
  LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  disk1 loopvg -wi-a----- 1.00g

8. 格式化分区为xfs文件系统

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ mkfs.xfs /dev/mapper/loopvg-disk1
meta-data=/dev/mapper/loopvg-disk1 isize=512 agcount=4, agsize=65536 blks
         = sectsz=512 attr=2, projid32bit=1
         = crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, imaxpct=25
         = sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
         = sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

9. 挂载逻辑卷分区

1
2
3
4
$ mkdir /mnt/fast-disks/disk1
$ mount /dev/mapper/loopvg-disk1 /mnt/fast-disks/disk1
$ mount | grep /mnt/fast-disks/disk1
/dev/mapper/loopvg-disk1 on /mnt/fast-disks/disk1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)