File System

Mount File System

If we have an image, we can easily mount the file system:

$ sudo fdisk -l image.raw
Disk fcsc.raw: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 60DA4A85-6F6F-4043-8A38-0AB83853E6DC

Device       Start      End  Sectors  Size Type
image.raw1     2048     4095     2048    1M BIOS boot
image.raw2     4096  1861631  1857536  907M Linux filesystem
image.raw3  1861632 20969471 19107840  9.1G Linux filesystem

The second partition the /boot partition. For mounting a partition, we need to calculate the offset, in our case, it's the start value * 512: 4096 * 512 = 2097152

$ sudo mount -o loop,ro,offset=2097152 image.raw /mnt/test
$ ls /mnt/test
config-5.4.0-105-generic  grub  initrd.img  initrd.img-5.4.0-105-generic  initrd.img.old  lost+found  System.map-5.4.0-105-generic  vmlinuz  vmlinuz-5.4.0-105-generic  vmlinuz.old

The second way it's with the losetup command:

$ sudo losetup -f -P image.raw 
$ sudo losetup -l
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                          DIO LOG-SEC
/dev/loop0         0      0         0  0 image.raw   0     512
$ sudo mount /dev/loop0
loop0    loop0p1  loop0p2  loop0p3  
$ sudo mount /dev/loop0p2 /mnt/test

Mount LVM/crypt File System

We mount with losetup command:

$ sudo losetup -f -P image.raw
$ sudo losetup -l
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                          DIO LOG-SEC
/dev/loop0         0      0         0  0 image.raw   0     512

Mount LVM partition

We can now open the partition encrypted and mount it:

$ sudo cryptsetup luksOpen /dev/loop0p3 test
$ sudo vgscan
$ sudo vgscan
  Found volume group "ubuntu-vg" using metadata type lvm2
$ sudo vgs
  VG             #PV #LV #SN Attr   VSize    VFree
  ubuntu-vg        1   1   0 wz--n-    9.09g    0 
$ sudo lvs
  LV        VG             Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert                                                
  ubuntu-lv ubuntu-vg      -wi-ao----    9.09g
$ sudo mount /dev/mapper/ubuntu--vg-ubuntu--lv /mnt/test
$ stat /mnt/test/
  File: /mnt/test/
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: fe07h/65031d    Inode: 2           Links: 19
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2025-05-18 09:45:54.498499782 +0200
Modify: 2022-03-27 05:47:14.900026411 +0200
Change: 2022-03-27 05:47:14.900026411 +0200
 Birth: 2022-03-27 05:44:49.000000000 +0200

Close LVM partition

$ sudo umount /mnt/test
$ sudo lvchange -an /dev/mapper/ubuntu--vg-ubuntu--lv
$ sudo vgchange -an /dev/mapper/ubuntu--vg
$ sudo cryptsetup plainClose test
$ sudo losetup -d /dev/loop0