Tag: zfs

  • Setup ZFS file system in Ubuntu

    ZFS file system allow you to take snapshot, this is great for backing up MySQL databases. Last day i setup 2 * 2 TB Hard disk on My PC as RAID 1 (mirror) using ZFS.

    First install ZFS with

    apt install zfsutils-linux
    

    I created same size partition on both hard disks. You can use full disk if you want, but i created partition, so i can use first 100 GB of each disk for installing Operating system.

    RAID 1

    RAID 1 mirror data between 2 disks. Even if one of the disk die, your data will be safe.

    To create RAID 1, run

    zpool create tank mirror /dev/sdx3 /dev/sdy3
    

    Here sdx3 and sdy3 is partition on my HDD. Replace it with your actual partition to be used with ZFS. Be carefull not to use wrong partition or you will lose data.

    If you are using full disk, then use

    zpool create tank mirror /dev/sdx /dev/sdy
    

    RAID 0

    RAID 0 is dangerous, only use if you don’t care about data or you have a backup. If one of the disk fails, you will lose all data.

    To setup RAID 0, use

    zpool create tank /dev/sdx3 /dev/sdy3
    

    Pool

    Once you create a ZFS pool with “zpool” command, it get auto mounted as “/pool-name”. In above cause, i used name “tank”.

    Here is what i have on my PC

    root@ok-pc-01:~# df -h | grep tank
    tank/data             1.6T  371G  1.3T  23% /mnt/data
    tank                  1.3T     0  1.3T   0% /tank
    root@ok-pc-01:~# 
    

    The 2nd entry is the ZFS pool tank.

    Datasets

    Datasets are like partitions. You can create multiple partitions inside your pool, they sare disk space. You can set disk quotas if needed, by default no quota per datasets are set.

    In above example /tank/data is a datasets i use.

    To create a data set, run

    zfs create -o mountpoint=/mnt/data tank/data
    

    Here “-o mountpoint” specify where you want to mount the new dataset.

    zpool status

    To see status for your ZFS file system, run

    root@ok-pc-01:~# zpool status
      pool: tank
     state: ONLINE
      scan: none requested
    config:
    
    	NAME        STATE     READ WRITE CKSUM
    	tank        ONLINE       0     0     0
    	  mirror-0  ONLINE       0     0     0
    	    sda3    ONLINE       0     0     0
    	    sdc3    ONLINE       0     0     0
    
    errors: No known data errors
    root@ok-pc-01:~# 
    

    See zfs

  • zfs

    Install zfs file system on Ubuntu

    apt install -y zfs
    

    Listing ZFS file systems

    root@ns3048991:~# zfs list
    NAME                       USED  AVAIL  REFER  MOUNTPOINT
    rpool                     1.12T   654G   104K  /rpool
    rpool/ROOT                5.50G   654G    96K  /rpool/ROOT
    rpool/ROOT/pve-1          5.50G   654G  5.50G  /
    rpool/data                1.11T   654G    96K  /rpool/data
    rpool/data/vm-101-disk-0   103G   748G  9.29G  -
    rpool/data/vm-101-disk-1  1.01T  1.65T    56K  -
    rpool/swap                4.25G   658G   289M  -
    root@ns3048991:~# 
    

    List pools

    root@ns3048991:~# zpool list
    NAME    SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
    rpool  1.81T  15.4G  1.80T         -     0%     0%  1.00x  ONLINE  -
    root@ns3048991:~# 
    

    Show current IO usage

    root@ns3048991:~# zpool iostat
                  capacity     operations     bandwidth 
    pool        alloc   free   read  write   read  write
    ----------  -----  -----  -----  -----  -----  -----
    rpool       15.8G  1.80T     28     46   319K  2.14M
    root@ns3048991:~# 
    

    To see status

    root@ns3048991:~# zpool status
      pool: rpool
     state: ONLINE
    status: Some supported features are not enabled on the pool. The pool can
    	still be used, but some features are unavailable.
    action: Enable all features using 'zpool upgrade'. Once this is done,
    	the pool may no longer be accessible by software that does not support
    	the features. See zpool-features(5) for details.
      scan: none requested
    config:
    
    	NAME        STATE     READ WRITE CKSUM
    	rpool       ONLINE       0     0     0
    	  mirror-0  ONLINE       0     0     0
    	    sda2    ONLINE       0     0     0
    	    sdb2    ONLINE       0     0     0
    
    errors: No known data errors
    root@ns3048991:~# 
    

    Setup ZFS file system in Ubuntu