Last updated: Feb 12, 2020
IMAGE GALLERY (4)
What is Filesysem?
- Hierarical data-structure Linke to linux FS notes
Various filesystems in Linux
Searching filesystem with GREP
Search for PATTERN am33xx at LOCATION ./build/, but include only ‘*.dtb’ files for searching
grep --recursive --include='*.dtb' am33xx ./build/ --files-with-matches
rsyncis a friend to move things around - incremental copying
mkdir $(ls | cut -d. -f1)
$(cat README) - Run this command and give me the output <(cat README) - Run command, hook it to a File Descriptor and then give me the path of FD # Treat any resource like a file grep google <(curl --silent http://google.com)
- Formattting a external mounted drive
- Sparse Images
If you’re familiar with disk structure, you know that disks are broken down into sectors, which are typically 512 bytes in size; all Read or Write operations occur in multiples of the sector size. When you look more closely, hard disks include extra data between sectors. The disk uses these extra bytes to detect and correct errors within each sector.
When the sector size is increased from 512 bytes to a larger value, more efficient and powerful error-correction algorithms can be used. Thus, changing to a larger sector size has two practical benefits: improved reliability and greater disk capacity — at least in theory.
Add space to wic image size, inplace
/dev/zeroAdd zeros to the wic image
cp mastercontrol-image-genericx86-64--20191212115741.wic 123.wic dd status=progress bs=1G if=/dev/zero of=./space.img count=1 bat ./space.img >> 123.wic sudo cfdisk 123.wic
dd command - copying filesystems
- Why would the disk image be so large?
- Is it going to equal the size of the partition?
- Is there a way to keep the disk image to just the size of the actual space used?
- Is there a better tool to use?
- dd makes a byte-for-byte copy, so the total size of the partition matters, not what’s in the partition.
- Yes. It will grow to 220 GB.
You can compress the resulting image using gzip or xz:
sudo dd if=/dev/sda1 | xz > /tmp/ubuntu.image
Depends on what you call a better tool. For some tasks, a byte-for-byte copy is needed (say, data recovery from a failing disk). In such cases, dd + compression is the simplest way. If not, consider something like partimage .
fdisk /dev/sdb dd if=/dev/zero of=/dev/sdb bs=512 count=1 fdisk -l /dev/sdb
- df - disk free
- display the amount of available disk space for file system
dfdoesnt show partitions, rather Filesystems
df -h -x tmpfs -x devtmpfs`
- rootfs / ramfs
rootfsis a special instance os
tempfsimage used in initram
ramfs) partitions are mounted from an internal RAM disk
- You can’t unmount rootfs
- du - disk usage
cat /sys/class/block/sda/size # determine the size of block device blockdev --getsize64 /dev/sda cat /proc/partitions
sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s rm 6 sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s rm 5 sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s rm 4 sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s print free sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s mkpart extended 4243968s 8471055s sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s mkpart logical ext4 4243969s 5471055s sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s mkpart logical ext4 5471057s 8471055s sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s print free sudo parted --script skysails-mastercontrol-image-genericx86-64.wic unit s mkpart extended 4243968s 8471055s Warning: The resulting partition is not properly aligned for best performance.
Block size versus sector size
In Linux, disk sector size can be determined with
fdisk -l | grep "Sector size
and block size can be determined with
blockdev --getbsz /dev/sda.
Everything running is a process
- In memory pseudo (virtual) Filesystem, whichi gets built at each reboot
- Explains why file size is
0for all files insode
- Explains why file size is
- regarded as a control and information centre for the kernel
- Has directories created with process names
echo $$will have a dir
- Process directory has associated
FDfile descriptors info
- All process and kernel states are stored in proc file system
/proc/PID/maps(containing the currently mapped memory regions and their access permissions)
/proc/PID/status(get the status information of a process)
/proc/PID/smaps(is an extension based on maps, showing the memory consumption for each of the process’s mappings)
- /proc/meminfo (Provides information about distribution and utilization of memory)
- /proc/vmallocinfo (Provides information about vmalloced/vmaped areas)
- /proc/net/dev (Can use this information to see which network devices are available in your system and how much traffic was routed over those devices)
- /proc/net ( tcp, udp, tcp6, udp6, igmp, ecc)
List whichi processes have current file opened?
- Process that are using a linux library
What is this user upto?
lsof --user dave
# Network sockets lsof -i TCP lsof -i UDP lsof -i :80 lsof -i -n -P | grep
FD - Files descriptors
|9w||care about writing only|
Where is a progess logging into?
lsof -p PID | grep log
- exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel’s device model to user space through virtual files
# You can upgrade kernel and keep it getting upgraded to future point Ubuntu releases by running sudo apt install linux-generic-hwe-18.04 update-initramfs -u
Mounting and unmounting filesystems
mount umount -a fuser -km /data
- Unmount all devices from filesystems
- Kill all processses using filesystem at location