This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
fuss:linux [2020/05/08 21:53] – [Automatically Add all RNDIS Devices to a Bridge] office | fuss:linux [2021/04/16 19:21] – [Self-Delete Shell Script] office | ||
---|---|---|---|
Line 1142: | Line 1142: | ||
One usage case for this rule is to connect a bunch of RNDIS devices to an USB hub and have them join the network automatically as they are hotplugged; for instance, Raspberry Pis [[fuss/ | One usage case for this rule is to connect a bunch of RNDIS devices to an USB hub and have them join the network automatically as they are hotplugged; for instance, Raspberry Pis [[fuss/ | ||
+ | |||
+ | ====== Scraping a Site Automatically using SystemD ====== | ||
+ | |||
+ | FTP sites can be scraped elegantly by using systemd and tmux on Linux. By starting a '' | ||
+ | |||
+ | The following script contains a few parameters underneath the '' | ||
+ | * the download path ('' | ||
+ | * the '' | ||
+ | * a descriptive name for the '' | ||
+ | |||
+ | <code bash> | ||
+ | [Unit] | ||
+ | Description=Scrape FTP Site | ||
+ | Requires=network.target local-fs.target remote-fs.target | ||
+ | After=network.target local-fs.target remote-fs.target | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=multi-user.target | ||
+ | |||
+ | [Service] | ||
+ | # Configuration | ||
+ | Environment=DOWNLOAD_DIRECTORY="/ | ||
+ | Environment=DOWNLOAD_URL=" | ||
+ | Environment=TMUX_SESSION_NAME=" | ||
+ | # Internals | ||
+ | Type=oneshot | ||
+ | KillMode=none | ||
+ | User=root | ||
+ | ExecStartPre = -/bin/mkdir -p \"" | ||
+ | ExecStart=/ | ||
+ | ExecStop=/ | ||
+ | RemainAfterExit=yes | ||
+ | |||
+ | </ | ||
+ | |||
+ | The file should be placed under ''/ | ||
+ | |||
+ | Upon every reboot, the service file will create a detached tmux terminal and start scraping files from the URL. | ||
+ | |||
+ | ====== Access Directory Underneath Mountpoint ====== | ||
+ | |||
+ | In order to access a directory underneath a mountpoint without unmounting, create a bind mount of the root filesystem to a directory and then access the content via the bind mount. | ||
+ | |||
+ | Ie, to access the contents of the directory ''/ | ||
+ | <code bash> | ||
+ | mkdir /mnt/root | ||
+ | </ | ||
+ | |||
+ | and create a bind mount: | ||
+ | <code bash> | ||
+ | mount -o bind / /mnt/root | ||
+ | </ | ||
+ | |||
+ | Finally access the original underlying content via the path ''/ | ||
+ | |||
+ | ====== Self-Delete Shell Script ====== | ||
+ | |||
+ | < | ||
+ | rm -rf -- " | ||
+ | </ | ||
+ | |||
+ | ====== Resize Last Partition and Filesystem in Image File ====== | ||
+ | |||
+ | Assuming that an image file is available and named, for example, '' | ||
+ | |||
+ | First, extend the image file '' | ||
+ | <code bash> | ||
+ | dd if=/ | ||
+ | </ | ||
+ | where: | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | In this case, the image file '' | ||
+ | <code bash> | ||
+ | qemu-img resize raspios.img +500M | ||
+ | </ | ||
+ | |||
+ | The next step is to run '' | ||
+ | <code bash> | ||
+ | parted raspios.img | ||
+ | </ | ||
+ | |||
+ | and then resize the partition, for example: | ||
+ | <code bash> | ||
+ | (parted) resizepart 2 100% | ||
+ | </ | ||
+ | where: | ||
+ | * '' | ||
+ | |||
+ | The '' | ||
+ | |||
+ | The final step is to enlarge the filesystem within the second partition that has just been extended by $500MiB$. '' | ||
+ | <code bash> | ||
+ | kpartx -avs raspios.img | ||
+ | </ | ||
+ | |||
+ | First, the existing filesystem has to be checked: | ||
+ | <code bash> | ||
+ | e2fsck -f / | ||
+ | </ | ||
+ | where: | ||
+ | * ''/ | ||
+ | |||
+ | and then finally the filesystem is extended to its maximum size: | ||
+ | <code bash> | ||
+ | resize2fs / | ||
+ | </ | ||
+ | |||
+ | |||