Author: steini

  • Words of wisdom

    BG 3.25
    As the ignorant act out of attachment to action, O Bharata, so should the wise act without attachment, wishing for the welfare of the world.

    BG 18.19
    Knowledge, action, and actor are declared in the science of the Gunas (Sankhya philosophy) to be of three kinds only, according to the distinction of the Gunas. Of these, hear duly.

    BG 14.20
    The embodied one, having crossed beyond these three Gunas from which the body is evolved, is freed from birth, death, decay, and pain, and attains immortality.
  • Linux permissions in three seconds

    r w x

    4 2 1

    7=r+w+x

    6=r+w

    5=r+x

  • Modify image, command line

    Shrink partition with resize2fs
    'resize2fs' to get the desired filesystem size
    'tune2fs -l' to determine the filesystem look for 'Block size' and 'Block count'

    tune2fs -l /dev/sdb1

    'parted' to determine the partition's 'Start' sector (first set 'unit' to 's'), unit s,

    Compute the partition 'End' sector:
    'End' = 'Start' + (('Block size' * 'Block count') / 512) - 1

    'parted' to resize the partition using the computed 'End' value (first set 'unit' to 's')

    'parted /dev/sdX resizepart 2 <new_last_sector_number>s
    (See 'man resize2fs' and 'man parted' for command details)
    blkid, vim /etc/fstab, systemctl daemon-reload, lsblk
    resize2fs /dev/sdb1 250G 
    tune2fs -l /dev/sdb1 - Block count: 65536000, First block: 0, Block size: 4096

    qalc

    2048 + ((4096 × 65536000) / 512) − 1 = 524290047

    parted

    parted /dev/sdb, unit s, print, (parted) resizepart 1 524290047, e2fsck -f /dev/sdb1

    modify image

    inspection;
    fdisk -l raw_img_file.img 
    mount -o loop offset=1048576(start sector*512) raw_img_file.img /mnt/img 
    umount /mnt/img,   
    
    Add space to the image; 
    df -h /mnt/img 
    parted raw_img_file.img 
    print free 
    quit 
    dd if=/dev/zero bs=1M count=512 >> raw_img_file.img pated raw_img_file.img, unit s, resizepart 1 2444222s (last sector 's')
    print free
    kpartx -av raw_img_file.img 
    ls /dev/mapper
    e2fsck -f -y -v -C 0 /dev/mapper/loop0p1
    resize2fs -p /dev/mapper/loop0p1
    kpartx -d raw_img_file.img
    umount /mnt/img
    kpartx -d raw_img_file.img 
    kpartx -av raw_img.file.img, mount /dev/mapper/loop0p1 /mnt/img 
    chroot short version
    mount -t proc proc /mnt/img/proc
    mount -t sysfs sys /mnt/img/sys
    mount -o bind /dev /mnt/img/dev
    mount -t devpts pts /mnt/img/dev/pts
    chroot /mnt/img
    exit
    
    umount /mnt/img/dev/pts
    umount /mnt/img/dev
    umount /mnt/img/sys
    umount /mnt/img/proc
    umount /mnt/img
    kpartx -d raw_img_file.img
    

    shrinking .img

    umount /dev/sdc1 umount /mnt/sdc2dd if=/dev/sdc of=my_image.img modprobe loop
    losetup -f 
    losetup /dev/loop0 my_image.img
    prtprobe /dev/loop0
    gparted /dev/loop0
    resize, losetup -d/dev/loop0 (deattach)
    find last sector fdisk -l my_image.img 
       The last block was 9181183 and block-numbers start at 0. That means we need (9181183+1)*512 bytes. truncate --size=$[(9181183+1+33)*512] my_image.img,  


    – 33 extra sectors are needed for the backup GPT partition tablem use gdisk my_image.img and then use the w command to repair the partition table.

    – if GPT backup partition table at the end of the disk was already removed, there is fix. Add 33 sectors with dd if=/dev/zero bs=512 count=33 >> myimage.img. And fix it with gdisk myimage.img and use w command.

    or parted /dev/loop0, print, unit s,
    resizepart 2(1) 111111s (to sector), quit

    
    
    
    
    
    
    
    
    
    

  • Cryptsetup open, mount, umount, close

    Short version of cryptsteup open, mount, umount, cryptsetup close

    - blkid | grep crypto
    
    cryptsetup open /dev/nvme0n1p2 secret
    mount /dev/mapper/secret /mnt/secret
    umount /mnt/secret
    crypstsetup close secret
    Crypt partition with cryptsetup;
    
    * cryptsetup loksFormat /dev/sdd2 <-- format drive 
    * cryptsetup open /dev/sdd2 luks
    * mkfs.ext4 /dev/mapper/luks
    * crypsteup mount /dev/mapper/luks /mnt/luks
    * crypsetup open /dev/sdd2 luks
    
    * cryptsetup status luks
    * umount /mnt/luks
    * cryptsetup close luks
    
    * crypsetup luksChangeKey /dev/sdd2

  • Rsync –include-from=’include_exclude_file’

    Include and exclude with rsync -avv –include-from.

    So here is a ultra short howto. First have to be the pluses (include) of the map end then the minuses (exclude).

    rsync -avv –include-from=’rsync_home_apr25′ /home/bob/ /media/backup/experiment/

    rsync_home_apr25

    + include_file1
    + include_file2
    + include_map/
    + .config/foot
    + .config/mpv
    - .config/*
    + map/
    + map/under_map1
    + map/under_map2
    - map/*
    - /*

  • Words of wisdom

    All of humanity’s problems stem from man’s inability to sit quietly in a room alone.

    — Blaise Pascal

    Be still and know that I am god.

    — Psalm 46:10