File System

Compare

File system
Host OS
Online grow
Offline grow
Online shrink
Offline shrink
FAT32(X)
misc.
No
3rd-party
No
3rd-party
NTFS
Windows
Yes
Yes
Yes
Yes
ReFS
Windows
Yes
?
No
?
Btrfs[51]
Linux
Yes
No
Yes
No
ext4[52]
Linux
Yes
Yes
No
Yes
HFS+
Linux
No
No
No
No
HFS+
macOS
Yes
No
Yes
No
APFS
macOS
?
?
?
?
ZFS
misc.
Yes
No
No
No
ReiserFS[59]
Linux
Yes
Yes
No
Yes
XFS[60]
Linux
Yes
No
No
No

Check info

1
lshw -short -C disk
2
lshw -class disk -class storage
3
lsblk -f # check file system type
4
tune2fs -l /dev/sda1 | grep -i count
5
6
gdisk -l /dev/sda #fdisk many give wrong GPT partiton
7
8
# file -s /dev/vda
9
/dev/vda: DOS/MBR boot sector
10
# file -s /dev/vda1
11
/dev/vda1: Linux rev 1.0 ext4 filesystem data, UUID=... (needs journal recovery) (extents) (large files) (huge files)
Copied!

Convert between MBR and GPT

1
sudo sgdisk -g /dev/sda
2
sudo sgdisk -m /dev/sda
3
sudo partprobe -s
Copied!

mkpart, format

1
parted -s /dev/sdb mklabel gpt
2
parted -s /dev/sdb unit mib mkpart primary 0% 100% / 1MiB 512MiB
3
4
mkpart primary fat32 1MiB 512MiB
5
set 1 esp on
6
7
mkfs.ext4 /dev/sdb1
Copied!

mount/umount

1
mount -o rw,remount / # recovery
2
umount -l /PATH/OF/BUSY-DEVICE
3
4
mount -o loop,ro $path $mount_point # ISO
5
6
mount.nfs $1:$2 $3
7
mount -tnfs4 -ominorversion=1 server_nfs_4.1:/dir\
8
9
echo $path $mount_point cifs username=$user,password=$passwd 0 0 >> /etc/fstab # SMB
Copied!

fstab

Loss NAS mount may cause hang!
1
cat /proc/mounts # list mounted
2
3
/dev/vdb1 /root/data ext4 defaults,noatime 0 0
4
/dev/cdrom /media/CentOS auto user,noauto,exec,utf8 0 0
5
//192.168.88.10/_ISO /mnt/ISO/ cifs username=user,password=pwd 0 0
6
//servername/sharename /media/windowsshare cifs guest,uid=1000,iocharset=utf8 0 0
7
/dev/mapper/x--vg--root /home btrfs defaults,[email protected] 0 2
8
/dev/sda2 /mymnt/win ntfs-3g rw,umask=0000,defaults 0 0
Copied!
is checked by the dump(ext2/3 filesystem backup) utility. This field is usually set to 0, which disables the check.
/ sets the order for filesystem checks at boot time; see fsck(8). 1 for the root device, 2 for other partitions, 0 to disable checking. [Arch] If the root file system is btrfs, set to 0 instead of 1.

LVM

1
pvdisplay -v -m
2
3
Wiping internal VG cache
4
Wiping cache of LVM-capable devices
5
--- Physical volume ---
6
PV Name /dev/sde1
7
VG Name wd500-vg
8
PV Size <422.53 GiB / not usable 0
9
Allocatable yes
10
PE Size 4.00 MiB
11
Total PE 108167
12
Free PE 5523
13
Allocated PE 102644
14
PV UUID nPoenO-vin9-wkZF-4Dxh-5WT2-yU3f-EtAMs5
15
16
--- Physical Segments ---
17
Physical extent 0 to 5522:
18
FREE
19
Physical extent 5523 to 95122:
20
Logical volume /dev/wd500-vg/data
21
Logical extents 0 to 89599
22
Physical extent 95123 to 95366:
23
Logical volume /dev/wd500-vg/swap_1
24
Logical extents 0 to 243
25
Physical extent 95367 to 108166:
26
Logical volume /dev/wd500-vg/data
27
Logical extents 89600 to 102399
Copied!

Check lv filesystem

1
file -s /dev/vg1/lv1
Copied!

Rename

1
vgrename $vg_uuid new-vg-name
Copied!

Create

1
vgcreate vg-name /dev/sdc3
2
lvcreate -L 80G wd500-vg -n data
3
mkfs.btrfs /dev/mapper/wd500--vg-data
4
mount /dev/mapper/wd500--vg-data /data2
5
echo $(cat /proc/mounts | tail -n 1) >> /etc/fstab ; ls /etc/fstab ;
Copied!

Activate vg

1
vgchange -ay
Copied!

Add disk to vg

1
pvcreate /dev/sdb # delete all partitions first
2
vgextend ubuntu-vg /dev/sdb
Copied!

Remove disk from vg

1
pvmove /dev/sdb1
2
vgreduce myvg /dev/sdb1
Copied!

lv operations

1
lvremove sandisk-u2/mint
Copied!

Resize fs

PV thrink: gparted
1
lvresize -L +20G /dev/debian9-vg/root # -r, --resizefs
2
resize2fs /dev/dlvebian9-vg/root
3
4
yum install e4fsprogs
5
resize4fs /dev/debian9-vg/root # resize ext4 if resize2fs error: Filesystem has unsupported feature(s)
6
7
lvextend --resize-fs --extents +100%FREE vg/lv # not support btrfs
Copied!

btrfs

1
btrfs filesystem resize +60G /data # use gparted for shrink
2
btrfs filesystem usage /
3
btrfs device usage /data
4
5
dmesg | grep crc32c # verify if Btrfs checksum is hardware accelerated, e.g.: crc32c-intel
Copied!

snapshot

1
btrfs subvolume delete snapshot1/
2
# mv snapshot folder will be very slow
3
4
btrfs subvolume snapshot /var/lib/docker /var/lib/docker/btrfs/snapshot_20201230
5
6
btrfs subvolume list /var/lib/docker
7
8
mount -o subvolid=298 /dev/sda5 /var/lib/docker
9
subvolid=298,subvol=/btrfs/snapshot_20201230
Copied!

f2fs

NTFS

Swap

1
swapoff -v /dev/mapper/ubuntu--vg-swap_1
2
lvreduce --size -22G /dev/debian9-vg/swap
3
mkswap /dev/mapper/ubuntu--vg-swap_1
4
swapon -va
5
6
echo /dev/VG/LV swap swap defaults 0 0 >> /etc/fstab
Copied!

Benchmark

dd

1
dd if=/dev/zero of=/tmp/test_iops bs=512 count=10000 oflag=direct
2
dd if=/dev/zero of=/tmp/test_bw bs=200M count=1 oflag=direct
Copied!

fio

1
git clone https://github.com/axboe/fio.git && cd fio/examples/
2
3
fio --name=randwrite --ioengine=libaio --group_reporting \
4
--iodepth=1 --rw=randwrite \
5
--direct=1 --bs=4k --numjobs=8 \
6
--size=512M --runtime=5
Copied!

SMART

1
apt install smartmontools
Copied!
1
smartctl --info /dev/sdf
2
3
smartctl --test=short /dev/sdf
4
5
smartctl --all /dev/sdf
6
7
smartctl -l selftest /dev/sdf
8
smartctl -l xerror /dev/sdf
9
-l TYPE, --log=TYPE
10
Show device log. TYPE: error, selftest, selective, directory[,g|s],
11
xerror[,N][,error], xselftest[,N][,selftest],
12
background, sasphy[,reset], sataphy[,reset],
13
scttemp[sts,hist], scttempint,N[,p],
14
scterc[,N,M], devstat[,N], ssd,
15
gplog,N[,RANGE], smartlog,N[,RANGE]
Copied!

SAMBA

docker
1
docker run --restart=unless-stopped --net host --name samba \
2
-v /data:/data -d \
3
dperson/samba -p -s "public;/data;yes;no"
Copied!
apt
1
apt install samba
2
vi /etc/samba/smb.conf
3
4
[public]
5
comment = public anonymous access
6
path = /data
7
browsable =yes
8
create mask = 0660
9
directory mask = 0771
10
writable = yes
11
guest ok = yes
12
13
service smbd restart
Copied!
Last modified 1yr ago