Dd linux commands

From Knowledge Center
Revision as of 07:32, 3 March 2018 by Ruan (talk | contribs)
Jump to: navigation, search

lsof linux commands

Create 2GB Swap Space:

Create the space and format it to be swap:

$ dd if=/dev/zero of=/root/2g.swap bs=2M count=1024
$ chmod 600 /root/2g.swap
$ chown root:root /root/2g.swap
$ mkswap /root/2g.swap
$ swapon /root/2g.swap

Add to fstab:

$ echo '/root/2g.swap	none	swap	sw	0	0' >> /etc/fstab

Create a 1GB File for a Mountable Partition:

$ dd if=/dev/zero of=/opt/disk/1g.blob bs=1M count=1024
$ mkfs.ext4 /opt/disk/1g.blob
$ mkdir /new
$ mount /opt/disk/1g.blob /new

Verify that the disk is mounted:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G   15G  4.8G  76% /
/dev/loop2      976M  1.3M  908M   1% /new

Add to fstab:

$ echo '/dev/loop2   /new ext4  defaults  0 0' >> /etc/fstab

Another Method using dd:

$ dd if=/dev/zero of=/opt/a.img bs=1024 count=0 seek=$[1000*1000]
$ losetup /dev/loop9 /opt/a.img

List the block devices:

$ lsblk
NAME                       MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
xvda                       202:0    0    20G  0 disk
└─xvda1                    202:1    0    20G  0 part /
loop9                        7:9    0 976.6M  0 loop

Create the fs and mount:

$ mkfs.ext4 -L storage /dev/loop9
$ mkdir /mnt/data2
$ mount /dev/loop9 /mnt/data2

View block devices with mountpoint info

$ lsblk -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT
NAME                       FSTYPE LABEL   UUID                                 MOUNTPOINT
xvda
└─xvda1                    ext4   /       73947a77-ddbe-4dc7-bd8f-3fe0bc840778 /
loop9                      ext4   storage a97620b6-6f5e-4913-92d9-273ef610bb1a /mnt/data2


Related: