- Compare
- Check info
- Convert between MBR and GPT
- mkpart, format
- mount/umount
- LVM
- btrfs
- f2fs
- NTFS
- Swap
- Benchmark
- SMART
- SAMBA
Compare¶
https://en.wikipedia.org/wiki/Comparison_of_file_systems
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¶
lshw -short -C disk
lshw -class disk -class storage
lsblk -f # check file system type
tune2fs -l /dev/sda1 | grep -i count
gdisk -l /dev/sda #fdisk many give wrong GPT partiton
# file -s /dev/vda
/dev/vda: DOS/MBR boot sector
# file -s /dev/vda1
/dev/vda1: Linux rev 1.0 ext4 filesystem data, UUID=... (needs journal recovery) (extents) (large files) (huge files)
Convert between MBR and GPT¶
sudo sgdisk -g /dev/sda
sudo sgdisk -m /dev/sda
sudo partprobe -s
mkpart, format¶
https://wiki.archlinux.org/index.php/Parted
parted -s /dev/sdb mklabel gpt
parted -s /dev/sdb unit mib mkpart primary 0% 100% / 1MiB 512MiB
mkpart primary fat32 1MiB 512MiB
set 1 esp on
mkfs.ext4 /dev/sdb1
mount/umount¶
mount -o rw,remount / # recovery
umount -l /PATH/OF/BUSY-DEVICE
mount -o loop,ro $path $mount_point # ISO
mount.nfs $1:$2 $3
mount -tnfs4 -ominorversion=1 server_nfs_4.1:/dir\
echo $path $mount_point cifs username=$user,password=$passwd 0 0 >> /etc/fstab # SMB
fstab¶
Loss NAS mount may cause hang!
cat /proc/mounts # list mounted
/dev/vdb1 /root/data ext4 defaults,noatime 0 0
/dev/cdrom /media/CentOS auto user,noauto,exec,utf8 0 0
//192.168.88.10/_ISO /mnt/ISO/ cifs username=user,password=pwd 0 0
//servername/sharename /media/windowsshare cifs guest,uid=1000,iocharset=utf8 0 0
/dev/mapper/x--vg--root /home btrfs defaults,subvol=@home 0 2
/dev/sda2 /mymnt/win ntfs-3g rw,umask=0000,defaults 0 0
LVM¶
pvdisplay -v -m
Wiping internal VG cache
Wiping cache of LVM-capable devices
--- Physical volume ---
PV Name /dev/sde1
VG Name wd500-vg
PV Size <422.53 GiB / not usable 0
Allocatable yes
PE Size 4.00 MiB
Total PE 108167
Free PE 5523
Allocated PE 102644
PV UUID nPoenO-vin9-wkZF-4Dxh-5WT2-yU3f-EtAMs5
--- Physical Segments ---
Physical extent 0 to 5522:
FREE
Physical extent 5523 to 95122:
Logical volume /dev/wd500-vg/data
Logical extents 0 to 89599
Physical extent 95123 to 95366:
Logical volume /dev/wd500-vg/swap_1
Logical extents 0 to 243
Physical extent 95367 to 108166:
Logical volume /dev/wd500-vg/data
Logical extents 89600 to 102399
create vg+lv & format & mount:
vgcreate vg-name /dev/sdc3
lvcreate -L 80G wd500-vg -n data
mkfs.btrfs /dev/mapper/wd500--vg-data
mount /dev/mapper/wd500--vg-data /data2
echo $(cat /proc/mounts | tail -n 1) >> /etc/fstab ; ls /etc/fstab ;
vg operations¶
vgrename $vg_uuid new-vg-name
vgchange -ay # Activate vg
Add disk to vg
pvcreate /dev/sdb # delete all partitions first
vgextend ubuntu-vg /dev/sdb
Remove disk from vg: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/logical_volume_manager_administration/disk_remove_ex
pvmove /dev/sdb1
vgreduce myvg /dev/sdb1
lv operations¶
lvremove sandisk-u2/mint
Resize fs¶
PV thrink: gparted
lvresize -L +20G /dev/debian9-vg/root # -r, --resizefs
resize2fs /dev/dlvebian9-vg/root
yum install e4fsprogs
resize4fs /dev/debian9-vg/root # resize ext4 if resize2fs error: Filesystem has unsupported feature(s)
lvextend --resize-fs --extents +100%FREE vg/lv # not support btrfs
btrfs¶
https://btrfs.wiki.kernel.org/index.php/Getting_started#Creating_a_filesystem
btrfs filesystem show /mnt/intel160
btrfs filesystem usage /
btrfs device usage /mnt/intel160G # get {device ID}
btrfs filesystem resize 7:max /mnt/point # {device ID}
btrfs filesystem resize +60G /data # use gparted for shrink
dmesg | grep crc32c # verify if Btrfs checksum is hardware accelerated, e.g.: crc32c-intel
snapshot¶
btrfs subvolume delete snapshot1/
# mv snapshot folder will be very slow
btrfs subvolume snapshot /var/lib/docker /var/lib/docker/btrfs/snapshot_20201230
btrfs subvolume list /var/lib/docker
mount -o subvolid=298 /dev/sda5 /var/lib/docker
subvolid=298,subvol=/btrfs/snapshot_20201230
f2fs¶
https://www.kernel.org/doc/Documentation/filesystems/f2fs.txt
NTFS¶
https://wiki.archlinux.org/index.php/NTFS-3G
Swap¶
swapoff -v /dev/mapper/ubuntu--vg-swap_1
lvreduce --size -22G /dev/debian9-vg/swap
mkswap /dev/mapper/ubuntu--vg-swap_1
swapon -va
echo /dev/VG/LV swap swap defaults 0 0 >> /etc/fstab
Benchmark¶
dd¶
dd if=/dev/zero of=./test_iops bs=4k count=10000 oflag=direct
dd if=/dev/zero of=./test_bw bs=1G count=1 oflag=direct
fio¶
git clone https://github.com/axboe/fio.git && cd fio/examples/
fio --name=randwrite --ioengine=libaio --group_reporting \
--iodepth=1 --rw=randwrite \
--direct=1 --bs=4k --numjobs=8 \
--size=512M --runtime=5
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read.fio --bs=4k --iodepth=64 --size=4G --readwrite=randread
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_write.fio --bs=4k --iodepth=64 --size=4G --readwrite=randwrite
SMART¶
apt install smartmontools
https://wiki.archlinux.org/index.php/S.M.A.R.T.
smartctl --info /dev/sdf
smartctl --test=short /dev/sdf
smartctl --all /dev/sdf
smartctl -l selftest /dev/sdf
smartctl -l xerror /dev/sdf
-l TYPE, --log=TYPE
Show device log. TYPE: error, selftest, selective, directory[,g|s],
xerror[,N][,error], xselftest[,N][,selftest],
background, sasphy[,reset], sataphy[,reset],
scttemp[sts,hist], scttempint,N[,p],
scterc[,N,M], devstat[,N], ssd,
gplog,N[,RANGE], smartlog,N[,RANGE]
SAMBA¶
docker
docker run --restart=unless-stopped --net host --name samba \
-v /data:/data -d \
dperson/samba -p -s "public;/data;yes;no"
apt
apt install samba
vi /etc/samba/smb.conf
[public]
comment = public anonymous access
path = /data
browsable =yes
create mask = 0660
directory mask = 0771
writable = yes
guest ok = yes
service smbd restarttart