分类目录归档:技术笔记

Windows后台运行Minecraft服务器

官网提供的服务器启动命令是

java -Xmx1024M -Xms1024M -jar server.jar nogui

在Linux下,我们后台启动服务器非常简单,只需要在命令后加上&即可

nohup java -Xmx1024M -Xms1024M -jar server.jar nogui &

但是,在Windows下,直接在命令行中启动的话,将会关联到cmd这个父进程。也就是说,cmd窗口一关,java服务也会停止。这显然是我们不喜欢的,所以需要后台运行。于是我们用javaw完成:

@echo off 
start javaw -Xmx1024M -Xms1024M -jar server.jar nogui

将上面内容保存为bat文件执行即可。

删除Windows 10与Ubuntu 18.04双系统中的Ubuntu启动项(UEFI)

删除需要用到DiskGenius软件,请准备好。免费版本即可,无需使用高级功能。

请严格按照以下顺序执行,否则可能出现删除失败的情况。

删除UEFI启动项:

启动CMD(管理员)
bcdedit /export savebcd
bcdedit /enum firmware
找到Ubuntu的对应identifier(标识符),复制(控制台下复制用右键标记-回车)
bcdedit /store savebcd /delete {xxx} ({}里面就是上一步的identifier)
bcdedit /import savebcd /clean

删除UEFI引导文件:

使用DiskGenius删除EFI分区中与Ubuntu启动的相关文件一般为

/EFI/ubuntu
/EFI/BOOT 可能有这个文件夹,通过创建时间判断

删除Ubuntu操作系统目录:

可以直接使用Windows“磁盘管理”工具删除分区。如果遇到“删除分区”为灰色的情况,请用在CMD中使用diskpart工具删除。

备注:

1、上面提到的savebcd文件默认存储在c:\windows\system32文件夹中

2、在PowerShell中执行以上命令是会出错,请使用CMD或启动PowerShell后键入cmd并回车。

Windows 10与Ubuntu 18.04双系统安装(UEFI)

制作启动盘

首先下载Ubuntu 18.04的iso镜像文件。这里给出中科大源的下载地址:点击下载 。完成后,用软件写入到U盘中待用。这里推荐使用UltraISO(我用的就是这个),或者Rufus(选择UEFI+MBR模式)。这部分比较简单,这里不详述。

准备磁盘空间

在Windows的“磁盘管理”工具中,准备好足够的空间备用(未分区,未格式化)。

UEFI安装准备

  • 插入U盘,开机
  • 进入BIOS,关闭安全启动(Secure-Boot)、快速启动(Fast-Boot)。
  • 选择使用U盘启动或者在启动顺序中将U盘提高到第一位。

安装Ubuntu

完成准备工作后,重启。接下来是正常安装Ubuntu过程,这里只对其中需要注意的地方进行说明:

1、分区表参考

/swap 主分区。一般设置等于物理内存
/home 逻辑分区。用户目录,可以设置稍大
/ 逻辑分区。根目录,剩余所有空间

2、关于/boot分区

由于是UEFI启动,所以无需挂载这个分区

3、关于EFI分区

实际测试,以下三种方式,所得到的结果均为启动文件被放在和Windows同一个EFI分区中

  • 方式一:Ubuntu安装时选择兼容Windows分区模式
  • 方式二:分区时选择自定义方式,并创建EFI分区,并在引导文件安装位置选择创建的EFI分区
  • 方式三:分区时选择自定义方式,不创建EFI分区,引导文件安装位置选择Windows Boot Manager所在分区,即Windows的EFI分区

所以,既然所有方式结果都一样,我们应该选择方式三。因为方式二将创建一个毫无用处的EFI分区。方式一只会创建一个“/”根目录挂载点。

选择启动方式

安装完后重启系统,将默认进入Ubuntu的UEFI启动界面。如果想让Windows作为默认启动选项,只需在BIOS中将UEFI启动顺序中的Windows对应项提升到首位即可

MariaDB创建用户、数据库

目标:

用户名:sampleuser
数据库名:sampledb
密码:samplepass

命令:

# Step1: Install MariaDB

yum install mariadb
systemctl start mariadb
systemctl enable mariadb


# Step2: Initialize MariaDB

mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y


# Step3: Create user and database

mysql -u root -p
MariaDB [(none)]>CREATE DATABASE sampledb;
MariaDB [(none)]>CREATE USER 'sampleuser'@'%' IDENTIFIED BY 'samplepass';
MariaDB [(none)]>GRANT ALL on sampledb.* to 'sampleuser'@'%';
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>exit

 

编译安装python3

从官网下载源码包

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解压

tar xvzf Python-3.6.4.tgz

准备编译需要的依赖

yum install -y gcc zlib zlib-devel openssl openssl-devel

配置并编译

./configure --prefix=/usr/local/python3.6    # 设置安装位置
make
make install

添加环境变量。在/etc/profile文件末尾追加

PATH=$PATH:/usr/local/python3.6/bin
export PATH

使环境变量生效

source /etc/profile

测试,执行python3命令,查看输出

 

CentOS添加环境变量

在Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行php -v命令查看当前php版本信息时时,则会提示命令不存在的错误,下面我们详细介绍一下在linux下将php和mysql加入到环境变量中的方法(假设php和mysql分别安装在/usr/local/webserver/php//usr/local/webserver/mysql/中)。

方法一:直接运行命令

export PATH=$PATH:/usr/local/webserver/php/bin
export PATH=$PATH:/usr/local/webserver/mysql/bin

使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时生效。

方法二:执行vi ~/.bash_profile修改文件中PATH一行,将/usr/local/webserver/php/bin/usr/local/webserver/mysql/bin 加入到PATH=$PATH:$HOME/bin一行之后

这种方法只对当前登录用户生效

方法三:修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH

最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。

CentOS磁盘挂载

以下是一次完整的磁盘挂载、分区、格式化、LVM挂载等的过程

[root@centos ~]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1  4294967295  2147483647+  ee  GPT

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 1
Value out of range.
Partition number (2-4, default 2): q
Partition number (2-4, default 2): ^C
[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n   
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p^H^C
[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m        
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-250069679, default 250069679): 
Using default value 250069679
Partition 1 of type Linux and of size 119.2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos ~]# l
Display all 155 possibilities? (y or n)
l.                           locate
l2ping                       lockdev
l2test                       logger
last                         login
lastb                        loginctl
lastcomm                     logname
lastlog                      logout
lchage                       logrotate
lchfn                        logsave
lchsh                        logview
ld                           look
ldattach                     losetup
ld.bfd                       lp
ldconfig                     lpadmin
ldd                          lpasswd
ld.gold                      lpc
ldns-chaos                   lpc.cups
ldns-compare-zones           lp.cups
ldnsd                        lpinfo
ldns-dane                    lpmove
ldns-dpa                     lpoptions
ldns-gen-zone                lppasswd
ldns-key2ds                  lpq
ldns-keyfetcher              lpq.cups
ldns-keygen                  lpr
ldns-mx                      lpr.cups
ldns-notify                  lprm
ldns-nsec3-hash              lprm.cups
ldns-read-zone               lprsetup.sh
ldns-resolver                lpstat
ldns-revoke                  lpstat.cups
ldns-rrsig                   ls
ldns-signzone                lsattr
ldns-test-edns               lsblk
ldns-testns                  lscgroup
ldns-update                  lscpu
ldns-verify-zone             lsinitrd
ldns-version                 lsipc
ldns-walk                    lslocks
ldns-zcat                    lslogins
ldns-zsplit                  lsmcli
--More--^C
[root@centos ~]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos ~]# df -T
Filesystem              Type     1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root xfs       33787784 3374740  30413044  10% /
devtmpfs                devtmpfs   8030912       0   8030912   0% /dev
tmpfs                   tmpfs      8042080       0   8042080   0% /dev/shm
tmpfs                   tmpfs      8042080    9136   8032944   1% /run
tmpfs                   tmpfs      8042080       0   8042080   0% /sys/fs/cgroup
/dev/sdb1               xfs        1038336  193472    844864  19% /boot
/dev/mapper/centos-home xfs       20961280   32956  20928324   1% /home
/dev/mapper/centos-var  xfs       52403200  315164  52088036   1% /var
tmpfs                   tmpfs      1608420      56   1608364   1% /run/user/0
[root@centos ~]# mkfs.
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@centos ~]# mkfs.
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@centos ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@centos ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@centos ~]# mkfs.xfs /dev/sda1
mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (ntfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@centos ~]# mkfs.xfs /dev/sda1 -f
meta-data=/dev/sda1              isize=512    agcount=4, agsize=7814614 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31258454, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15262, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos ~]# cd /
[root@centos /]# mkdir data
[root@centos /]# ll
total 28
lrwxrwxrwx.   1 root root    7 Mar  7 22:08 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Mar  7 22:46 boot
drwxr-xr-x.   2 root root    6 Mar  8 09:43 data
drwxr-xr-x.  21 root root 3540 Mar  8 09:33 dev
drwxr-xr-x. 139 root root 8192 Mar  7 23:44 etc
drwxr-xr-x.   3 root root   19 Mar  7 22:12 home
lrwxrwxrwx.   1 root root    7 Mar  7 22:08 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Mar  7 22:08 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Nov  5  2016 media
drwxr-xr-x.   2 root root    6 Nov  5  2016 mnt
drwxr-xr-x.   3 root root   16 Mar  7 22:39 opt
dr-xr-xr-x. 308 root root    0 Mar  8 07:44 proc
dr-xr-x---.  19 root root 4096 Mar  8 09:23 root
drwxr-xr-x.  38 root root 1140 Mar  8 09:23 run
lrwxrwxrwx.   1 root root    8 Mar  7 22:08 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Nov  5  2016 srv
dr-xr-xr-x.  13 root root    0 Mar  7 23:44 sys
drwxrwxrwt.  23 root root 4096 Mar  8 09:43 tmp
drwxr-xr-x.  13 root root  155 Mar  7 22:08 usr
drwxr-xr-x.  21 root root 4096 Mar  7 22:39 var
[root@centos /]# mount /dev/sda1 /data
[root@centos /]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        33G  3.3G   30G  10% /
devtmpfs                devtmpfs  7.7G     0  7.7G   0% /dev
tmpfs                   tmpfs     7.7G     0  7.7G   0% /dev/shm
tmpfs                   tmpfs     7.7G  9.0M  7.7G   1% /run
tmpfs                   tmpfs     7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               xfs      1014M  189M  826M  19% /boot
/dev/mapper/centos-home xfs        20G   33M   20G   1% /home
/dev/mapper/centos-var  xfs        50G  308M   50G   1% /var
tmpfs                   tmpfs     1.6G   56K  1.6G   1% /run/user/0
/dev/sda1               xfs       120G   33M  120G   1% /data
[root@centos /]# cd /etc/fstab^C
[root@centos /]# vi /etc/fstab 
[root@centos /]# 
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos /]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Command (m for help): ^C
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m  
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-250069679, default 250069679): 
Using default value 250069679
Partition 1 of type Linux and of size 119.2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos /]# fdisk /dev/sda^C
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# unmount /dev/sda
bash: unmount: command not found...
[root@centos /]# yum install unmount
Loaded plugins: fastestmirror, langpacks
base                                        | 3.6 kB     00:00     
epel/x86_64/metalink                        | 7.1 kB     00:00     
extras                                      | 3.4 kB     00:00     
updates                                     | 3.4 kB     00:00     
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package unmount available.
Error: Nothing to do
[root@centos /]# umount /dev/sda
umount: /dev/sda: not mounted
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# umount /data
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@centos /]# mkfs.xfs /dev/sda -f
meta-data=/dev/sda               isize=512    agcount=4, agsize=7814678 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31258710, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15263, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# mount /dev/sda /data
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x70b67fc3.

Command (m for help): d
No partition is defined yet!

Command (m for help): ^C 
[root@centos /]# umount /data
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x181824cf.

Command (m for help): p  

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x181824cf

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): ^C 
[root@centos /]# pvcreate /dev/sda
WARNING: xfs signature detected on /dev/sda at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda.
  Physical volume "/dev/sda" successfully created.
[root@centos /]# pvs
  PV         VG     Fmt  Attr PSize    PFree  
  /dev/sda          lvm2 ---   119.24g 119.24g
  /dev/sdb2  centos lvm2 a--  <118.24g      0 
[root@centos /]# vgcreate -s 4m datavg /dev/sda
  Volume group "datavg" successfully created
[root@centos /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <118.24 GiB
  PE Size               4.00 MiB
  Total PE              30269
  Alloc PE / Size       30269 / <118.24 GiB
  Free  PE / Size       0 / 0   
  VG UUID               ykO7iD-Z2Vr-RnSN-nmdz-dDjx-AZlu-WGTO3L
   
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <119.24 GiB
  PE Size               4.00 MiB
  Total PE              30525
  Alloc PE / Size       0 / 0   
  Free  PE / Size       30525 / <119.24 GiB
  VG UUID               2Vt33P-4wry-4CHm-fzFd-ivoL-6uLe-fPk8fz
   
[root@centos /]# vgdisplay datavbg
  Volume group "datavbg" not found
  Cannot process volume group datavbg
[root@centos /]# vgdisplay datavg
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <119.24 GiB
  PE Size               4.00 MiB
  Total PE              30525
  Alloc PE / Size       0 / 0   
  Free  PE / Size       30525 / <119.24 GiB
  VG UUID               2Vt33P-4wry-4CHm-fzFd-ivoL-6uLe-fPk8fz
   
[root@centos /]# lvcreate -l 30525 -n lv_data datavg
  Logical volume "lv_data" created.
[root@centos /]# lvs
  LV      VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao----   20.00g                                                    
  root    centos -wi-ao----  <32.24g                                                    
  swap    centos -wi-ao----   16.00g                                                    
  var     centos -wi-ao----   50.00g                                                    
  lv_data datavg -wi-a----- <119.24g                                                    
[root@centos /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# mkfs.xfs /dev/mapper/datavg-lv_data
meta-data=/dev/mapper/datavg-lv_data isize=512    agcount=4, agsize=7814400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31257600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15262, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# lvs
  LV      VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao----   20.00g                                                    
  root    centos -wi-ao----  <32.24g                                                    
  swap    centos -wi-ao----   16.00g                                                    
  var     centos -wi-ao----   50.00g                                                    
  lv_data datavg -wi-a----- <119.24g                                                    
[root@centos /]# mount /dev/mapper/datavg-lv_data /data
[root@centos /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/centos-root      33G  3.3G   30G  10% /
devtmpfs                    7.7G     0  7.7G   0% /dev
tmpfs                       7.7G     0  7.7G   0% /dev/shm
tmpfs                       7.7G  9.0M  7.7G   1% /run
tmpfs                       7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1                  1014M  189M  826M  19% /boot
/dev/mapper/centos-home      20G   33M   20G   1% /home
/dev/mapper/centos-var       50G  307M   50G   1% /var
tmpfs                       1.6G   56K  1.6G   1% /run/user/0
/dev/mapper/datavg-lv_data  120G   33M  120G   1% /data
[root@centos /]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Mar  7 22:08:19 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=b118055d-ded6-4cf2-9587-31f28414e5f9 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-var  /var                    xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[root@centos /]# umount /data/
[root@centos /]# df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# lvremove /dev/mapper/
centos-home     centos-root     centos-swap     centos-var      datavg-lv_data  
[root@centos /]# lvremove /dev/mapper/
centos-home     centos-root     centos-swap     centos-var      datavg-lv_data  
[root@centos /]# lvremove /dev/mapper/datavg-lv_data 
Do you really want to remove active logical volume datavg/lv_data? [y/n]: y
  Logical volume "lv_data" successfully removed
[root@centos /]# vgremove /dev/sda
  Volume group "sda" not found
  Cannot process volume group sda
[root@centos /]# vgremove datavg
  Volume group "datavg" successfully removed
[root@centos /]# pvremove /dev/sda
  Labels on physical volume "/dev/sda" successfully wiped.

分区后,修改/etc/fstab文件保存目录挂载信息即可

TensorFlow学习笔记04

MNIST入门

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

import tensorflow as tf

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

x = tf.placeholder(tf.float32, [None, 784])

W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))

y = tf.nn.softmax(tf.matmul(x, W) + b)

y_ = tf.placeholder(tf.float32, [None, 10])

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

sess = tf.InteractiveSession()

tf.global_variables_initializer().run()

for _ in range(1000):
  batch_xs, batch_ys = mnist.train.next_batch(100)
  sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))

accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))

修改系统错误级别排除以下错误告警:Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

引入MNIST数据集

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

建立回归模型

y = tf.nn.softmax(tf.matmul(x,W) + b)