Thursday 18 April 2019

Linux Hard Disk Format Command







source


Q. I’ve installed a new 250GB SATA hard disk on our office CentOS Linux server. How do I format a hard disk under Linux operating system from a shell prompt?

A.. There are total 4 steps involved for hard disk upgrade and installation procedure:
  😱
 Step #1 : Partition the new disk using fdisk command
Following command will list all detected hard disks:
# fdisk -l | grep '^Disk'
Output:
Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes
A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.
To partition the disk – /dev/sdb, enter:
# fdisk /dev/sdb
The basic fdisk commands you need are:
  • m – print help
  • p – print the partition table
  • n – create a new partition
  • d – delete a partition
  • q – quit without saving changes
  • – write the new partition table and exit
Then press n, choose default primary and  then press  w to write to disk

Step#2 : Format the new disk using mkfs.ext3 command

To format Linux partitions using ext2fs on the new disk:
# mkfs.ext4 /dev/sdb1

Step#3 : Mount the new disk using mount command

First create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H

Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab
Append as follows:
/dev/sdb1               /disk1           ext3    defaults        1 2
Save and close the file.

Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup
You can use label name insted of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

Note: for disks > 2TB the above method does not work, so  follow this:


parted with gpt label

Create a partition using GPT format. I've chosen to use just 1 large partition that uses the whole disk.
root@turtle:~# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label
(parted) mklabel gpt
(parted) mkpart
Partition name?  []?
File system type?  [ext2]? ext3
Start? 0%
End? 100%
(parted) print
Model: ATA ST3000DM001-1CH1 (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  3001GB  3001GB

(parted) quit
Information: You may need to update /etc/fstab.

Saturday 13 April 2019

How to run gunicorn script using systemd in Debian

Since upstart is deprecated, it is not available in Debian 9, so I had to use systemd which turned out to be quite easy:

nano  /etc/systemd/system/gunicorn.service

Create the file:

[Unit]
Description=Gunicorn Daemon
#After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User= appuser
Group=www-data
ExecStart=/path/to/project/gunicorn.sh
#Restart=always
#RestartSec=1
#Restart=on-failure
# Configures the time to wait before service is stopped forcefully.
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
You don't need to restart the server to enable the service:

systemctl enable gunicorn
Start it:
systemctl start gunicorn

Watch it:
systemctl status gunicorn
If you made changes to gunicorn.service you need to run:

systemctl daemon-reload

before restarting the daemon with

systemctl restart gunicorn

Sunday 6 January 2019

How to compress scanned PDF?

One problem with scanned pdfs is that the size is so bloated. One good solution to compress such files is this one script:

#!/bin/sh

gs  -q -dNOPAUSE -dBATCH -dSAFER \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.3 \
    -dPDFSETTINGS=/screen \
    -dEmbedAllFonts=true \
    -dSubsetFonts=true \
    -dColorImageDownsampleType=/Bicubic \
    -dColorImageResolution=120 \
    -dGrayImageDownsampleType=/Bicubic \
    -dGrayImageResolution=72 \
    -dMonoImageDownsampleType=/Bicubic \
    -dMonoImageResolution=120 \
    -sOutputFile=out.pdf \
     $1


Here the compression rate can be changed by tweaking resolution values. I found the above gives a good compression without sacrificing the text quality.